Build variants in Gradle for a Library Project in Android

前端 未结 6 1539
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 12:32

I am trying to configure with Gradle a project which contains some external libraries. With Gradle I can setup different Environmental Configuration (with a class inside a c

6条回答
  •  萌比男神i
    2020-12-02 13:00

    Not sure what's wrong with your configuration but about your need, I would do it differently.

    In the gradle build file you can use the buildConfig keyword to add a specific line to the BuildConfig.java generated class.

    So you could add do something like that in your build.gradle :

        release {
            buildConfig "public static final String USE_REPORTING = true;"
        }
        debug {
    
            buildConfig "public static final String USE_REPORTING = false;"
        }
    

    And so have only one PlayerEnvConfig with

    public static final boolean USE_REPORTING = BuildConfig.USE_REPORTING;
    

    Or even no more PlayerEnvConfig and use directly the BuildConfig class.


    EDIT Since an update, the syntax has changed :

    buildConfigField "", "", ""
    

提交回复
热议问题