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

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

问题描述

Unity有一个默认的gradle.properties文件,该文件在构建过程中添加.虽然可以更改提到的build.gradle和settings.gradle文件 此处 https://docs.unity3d.com/Manual/android-gradle-overview. html 没有提及能够在统一文档中更改gradle.properties.该文件还会在每次构建尝试时都重新创建,因此在构建后再在temp/gradleOut中对其进行编辑并无法正常工作.我知道也可以导出该项目,但是我正在寻找一种解决方案,使该项目可以直接从整体上运行.

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.

这个问题不是这个问题的重复如何在Unity中使用Gradle 答案与修改gradle.properties文件无关.

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?

推荐答案

这很难发现.我打算像在iOS版本中那样使用常规的后版本处理器,但是在寻找一种加载方式并确定属性文件在哪里的过程中,我遇到了文档IPostGenerateGradleAndroidProject中的以下界面.

This was something that was slightly hard to discover. I was going to do a regular post build processor like I had for my iOS build, but as I was searching for a manner to load and determine where the properties file was, I ran across the following interface in the documentation : IPostGenerateGradleAndroidProject.

根据文档:

在Android之后实现此接口以接收回调 Gradle项目已生成.

Implement this interface to receive a callback after the Android Gradle project is generated.

因此,以下是我最初用于启用androidX和jetifier的蛮力实施.

So below is my initial brute force implementation for turning on androidX and jetifier.

public class AndroidPostBuildProcessor : IPostGenerateGradleAndroidProject
{
    public int callbackOrder
    {
        get
        {
            return 999;
        }
    }


    void IPostGenerateGradleAndroidProject.OnPostGenerateGradleAndroidProject(string path)
    {
        Debug.Log("Bulid path : " + path);
        string gradlePropertiesFile = path + "/gradle.properties";
        if (File.Exists(gradlePropertiesFile))
        {
            File.Delete(gradlePropertiesFile);
        }
        StreamWriter writer = File.CreateText(gradlePropertiesFile);
        writer.WriteLine("org.gradle.jvmargs=-Xmx4096M");
        writer.WriteLine("android.useAndroidX=true");
        writer.WriteLine("android.enableJetifier=true");
        writer.Flush();
        writer.Close();

    }
}

从理论上讲,您应该能够在后期构建处理器中以选择的任何方式来操纵生成的gradle项目.某些其他工具可能会有所帮助,例如iOS上的PBXProject支持,但是直到那时,这样做仍然可以.

Theoretically you should be able to manipulate the generated gradle project in any manner to your choosing during the post build processor. Some additional tools might be helpful, like the PBXProject support on iOS, but until then, this will do.

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

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