且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android白色标签

更新时间:2023-12-03 16:39:58

您可以根据自己的怀疑使用构建变体来做到这一点,但是您可能还需要风味.

You can do this with build variants as you suspected but also you would likely need Flavors.

这是示例gradle文件,具有多种构建类型和风格.您可以在风味设置中设置ApplicationId(在Play商店中使用的程序包名称).

Here is an example gradle file that has multiple build types and flavors. You set the ApplicationId (packagename used in Play Store) in the flavor settings.

在每种类型/风格中设置签名.您可以添加特定于每种口味的资源,图标,清单等.您甚至可以替换整个类文件,因此,针对特定客户的apk中仅包含针对客户的代码.

Set up the signing in each type/flavor. You can add resources, icons, manifests etc that are specific to each flavor. You can even replace whole class files so customer specific code is only included in the apk for the customer you are building for.

  defaultConfig {
    applicationId "uk.co.foo.default"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode = 113
    versionName = "3.2.3"
}

signingConfigs {
    release {
        storeFile file("X:\\Android Projects\\Keystore\\MyKeys.jks")
        storePassword "MyPassword"
        keyAlias "KeyAlias"
        keyPassword "itsasecret"
    }
}

productFlavors {
    Customer1 {
        applicationId "uk.co.foo.customer1"
    }

    Customer2 {
        applicationId "uk.co.foo.customer2"
    }
}

buildTypes {

    debug {
        applicationIdSuffix ".debug"
        versionNameSuffix " Debug"
    }

    beta {
        applicationIdSuffix ".beta"
        versionNameSuffix " Beta"
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }

    signed {
        minifyEnabled false
        debuggable true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }

    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}

这里是用于为每种类型\ flavor添加资源的文件夹结构.在此示例中,第二种风味称为粉丝".默认情况下使用主"文件夹.每种类型和口味的资源都将合并到apk中(替换主文件夹中的任何同名名称),具体取决于您在Android Studio的构建版本"部分中选择的是哪种版本.

Here is the folder structure for adding resources for each type\flavor. In this example, the second flavor is called "fan". The "main" folder is used by default. Each type and flavors resources are merged into the apk (replacing any of the same name in the main folder) depending on which build you choose in the "Build Variants" section of Android Studio.

Android Studio将显示当前构建中有效的文件夹,如该图突出显示.

Android Studio will display which folders are in effect for the current build as shown highlighted in this image.

编辑-此处提供完整的官方文档: https://developer. android.com/tools/building/configuring-gradle.html

Edit - full official documentation is available here: https://developer.android.com/tools/building/configuring-gradle.html