如何仅在我的应用程序的Premium版本中包含库项目而不包含免费版本?

时间:2017-04-17 12:16:38

标签: android android-library

我有一个应用程序,它使用与付费和免费版本相同的代码库..

下面的缩减build.gradle给出了结构的概念

android {
....
defaultConfig {
    applicationId "com.myco.myapp"
    ....
}

buildTypes {
....
    release {
    ....
    }
}

productFlavors {
    free {
        applicationIdSuffix ".free"
        buildConfigField "boolean", "PREMIUM", "false"
        buildConfigField "boolean", "FREE", "true"
    }
    premium {
        applicationIdSuffix ".premium"
        buildConfigField "boolean", "PREMIUM", "true"
        buildConfigField "boolean", "FREE", "false"
    }
}

dependencies {
    ....
    compile project(path: ':LVL')
}

我在onCreate中调用LVL许可证如下: -

        if (BuildConfig.PREMIUM) {
        String deviceId = Settings.Secure.ANDROID_ID;
        Log.i(TAG, "Device Id: " + deviceId);
        mHandler = new Handler();
        mLicenseCheckerCallback = new MyLicenseCheckerCallback();
        // Construct the LicenseChecker with a Policy.
        mChecker = new LicenseChecker(
                getApplicationContext(), new ServerManagedPolicy(this,
                new AESObfuscator(SALT, getPackageName(), deviceId)),
                BASE64_PUBLIC_KEY  // Your public licensing key.
        );
        doCheck();
    }

myapp的“免费”版本未调用或要求LVL库。我的问题是: - 我应该如何构建我的项目/ build.gradle,以便LVL库不包含在Free版本的APK中(但是包含在Premium版本中?

1 个答案:

答案 0 :(得分:1)

dependencies {
   premiumCompile project(':LVL')
}

ref类似问题