有没有办法在 Unity 中更改 gradle.properties 文件 [英] Is there a way to change the gradle.properties file in Unity

查看:187
本文介绍了有没有办法在 Unity 中更改 gradle.properties 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unity 有一个在构建过程中添加的默认 gradle.properties 文件.虽然可以更改 build.gradle 和 settings.gradle 文件这里

Unity has a default gradle.properties file that gets added during the build process. While its possible to change the build.gradle and the settings.gradle files as mentioned here https://docs.unity3d.com/Manual/android-gradle-overview.html there is no mention of being able to change gradle.properties within the unity docs. The file also gets recreated every build attempt so editing it within the temp/gradleOut after a build and building again doesn't work. I know exporting the project is possible as well, but I'm looking for a solution where the project can be run directly from unity.

Btw this question is NOT a duplicate of this question How to use Gradle in Unity The answer here has nothing to do with modifying the gradle.properties file.

This is a duplicate of this question that got incorrectly marked as a duplicate how to change default gradle.properties of Unity?

解决方案

Maybe my answer is a bit outdated but in Unity 2020 you can do it in:

Player Settings -> Tab Android (with robot obviously) -> Publishing Settings -> Custom Gradle Properties Template (checkbox).

After enabling the checkbox you will see the path to gradleTemplate.properties (usually it appears in Assets/Plugins/Android directory) file which will be merged with final gradle.properties.

Everything you need you can write to the end of file after **ADDITIONAL_PROPERTIES** string.

Example:

org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
android.enableR8=**MINIFY_WITH_R_EIGHT**
**ADDITIONAL_PROPERTIES**

android.useAndroidX = true // I added this property to fix error:  This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.

Also on screenshot:

这篇关于有没有办法在 Unity 中更改 gradle.properties 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆