Gradle buildConfigField 非法前向引用

cam*_*ous 1 java android gradle android-gradle-plugin

这不起作用,因为在生成的BuildConfig,STORE最终被定义在UNLOCKED和之前PLAYSTORE。我怎样才能以不同的方式做到这一点?

构建.gradle

android {
    defaultConfig {
        buildConfigField 'int', 'UNLOCKED', '0'
        buildConfigField 'int', 'PLAYSTORE', '1'
    }

    productFlavors {
        unlocked {
            buildConfigField 'int', 'STORE', 'UNLOCKED'
        }

        playStore {
            buildConfigField 'int', 'STORE', 'PLAYSTORE'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

BuildConfig.java(生成,playStore 风格)

// Fields from product flavor: playStore
public static final int STORE = PLAYSTORE; // ERROR
// Fields from default config.
public static final int PLAYSTORE = 1;
public static final int UNLOCKED = 0;
Run Code Online (Sandbox Code Playgroud)

示例用例

if(BuildConfig.STORE == BuildConfig.PLAYSTORE)
    validatePurchaseOnPlay();
Run Code Online (Sandbox Code Playgroud)

小智 5

尝试将 STORE 构建配置字段声明更改为:

buildConfigField 'int', 'STORE', 'BuildConfig.UNLOCKED'