如何修改code产品之间的重口味口味、产品、code

2023-09-06 08:47:15 作者:我愿意赌上所有时光只爱你

我创建一个免费和付费版本,一个非常简单的应用程序,对于这个我使用的伟大productFlavors在Android摇篮插件功能。我理解的build.gradle文件应该如何进行配置,写它,所以我的构建选项;

I'm creating a very simple app with a free and paid version, for this I'm using the great productFlavors feature in the Android Gradle plugin. I understand how the build.gradle file should be configured and have written it so my build options are;

freeRelease freeDebug paidRelease PaidDebug

(如下所示)

buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        signingConfig signingConfigs.someconfig
    }
}
productFlavors {
    free {
        packageName "com.somepackagename.appfree"
    }
    paid {
        packageName "com.somepackagename.appPaid"
    }
}

基本上,所有我想要做的就是限制了一些功能,并添加AdMod的免费版本,我将如何做呢?难道我添加if-else语句在检查,看它是否是免费或付费的我主要的java类?或者我可以覆盖在免费的目录中的java类?我应该如何去这样做呢?

Basically, all I'm trying to do is restrict a few features and add AdMod to the free version, how would I do that? Do I add if-else statements in my main java classes that check to see if it's free or paid? or can I overwrite java classes in the free directory? How should I go about doing this?

推荐答案

可以连接在目录结构code的东西,例如:

You can encode things in the directory structure, e.g.:

src/
  main/                    # Common source and assets
    java/
    res/
    AndroidManifest.xml
  free/                    # Source and assets for the free flavour
    java/
    res/
    AndroidManifest.xml
  paid/                    # Source and assets for the paid flavour
    java/
    res/
    AndroidManifest.xml

的code和特定于一个版本或其他资产进入特定的目录。该清单被合并。您可以使用字段生成到 BuildConfig.java 风味基地的if-else语句。

The code and assets that are specific to one version or the other go into the specific directories. The manifests are merged. You can use the FLAVOR field generated into BuildConfig.java to base if-else statements on.

的 SourceSets和依赖部分解释了这个更详细。

The SourceSets and Dependencies section of the Android-Gradle-Plugin user guide explains this in greater detail.

 
精彩推荐
图片推荐