【问题标题】:How can I include a library project in only the Premium build of my app and not the Free build?如何仅在我的应用程序的高级版本而不是免费版本中包含库项目?
【发布时间】:2017-09-13 01:30:32
【问题描述】:

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

下面的缩减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 库不包含在免费版的 APK 中(但包含在高级版中?

【问题讨论】:

    标签: android android-library


    【解决方案1】:

    试试

    dependencies {
       premiumCompile project(':LVL')
    }
    

    ref 类似问题

    【讨论】:

    • 谢谢。这确实回答了我的具体问题。但是,我已经决定,要么实现一个虚拟的“LVL”类,要么将 MainActivity 重新排列为“免费”和“高级”风格,以便从“免费”版本中删除对 LVL 的调用,这需要做很多工作。不值得麻烦。所以我只会在两个构建中都包含 LVL,因为开销相对较小。
    猜你喜欢
    • 1970-01-01
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多