这不起作用,因为在生成的BuildConfig中,STORE最终要在UNLOCKEDPLAYSTORE之前定义。我该怎么做呢?

build.gradle

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

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

        playStore {
            buildConfigField 'int', 'STORE', 'PLAYSTORE'
        }
    }
}

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;

样例用例
if(BuildConfig.STORE == BuildConfig.PLAYSTORE)
    validatePurchaseOnPlay();

最佳答案

尝试将您的STORE构建配置字段声明更改为:
buildConfigField 'int', 'STORE', 'BuildConfig.UNLOCKED'

07-25 22:42