Android's multi-channel packaging

This article is reprinted from: http://blog.csdn.net/qq_/article/details/78922154 ...

This article is reprinted from: http://blog.csdn.net/qq_/article/details/78922154

1. Add the statistical dependency database of the Alliance

  1. dependencies {
  2. compile 'com.umeng.sdk:common:latest.integration'
  3. compile 'com.umeng.sdk:analytics:latest.integration'
  4. }
If you cannot integrate properly, add the following configuration:


  1. allprojects {
  2. repositories {
  3. mavenCentral()
  4. }
  5. }

2. Configure permissions and keys in the manifest:

In the manifest file

  1. <uses-permission android:name="android.permission.INTERNET"/>
  2. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  3. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
  4. <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
  5. <application......>
  6. //The value="5a446bf5f29d987bd200008a" here is generated from your account in the alliance. See the figure
  7. <meta-data android:value="5a446bf5f29d987bd200008a" android:name="UMENG_APPKEY"/>
  8. <meta-data android:value="$" android:name="UMENG_CHANNEL"/>
  9. </application>




3.app build.gradle dynamically configure the placeholder and default value of Manifest

In other words, configure in build.gradle (Module:app) of the project:

  1. defaultConfig {
  2. multiDexEnabled true //Breaking the limit of 65535 methods
  3. manifestPlaceholders = [UMENG_CHANNEL_VAULE: "umeng"]
  4. flavorDimensions "versionCode"
  5. }

4. Configure signature file information. Note: signingConfigs should be before buildTypes

  1. signingConfigs {
  2. release {
  3. keyAlias 'key0'
  4. keyPassword '123456'
  5. storeFile file('release.jks')
  6. storePassword '123456'
  7. }
  8. }

5. Add channel information


  1. productFlavors {
  2. yingyongbao{
  3. }
  4. xiaomi{
  5. }
  6. }
  1. <p>For simplicity, you can replace duplicate code with scripts < / P >
  1. productFlavors.all


Finally, click Generate Signed APK under Build to pack. Select the required packages in the flags and click Finish. Look at the picture:





6. The name of multi-channel packaging output can be configured, for example, the name of packaging is the channel name

  1. buildTypes {
  2. release {
  3. minifyEnabled false
  4. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  5. signingConfig signingConfigs.release
  6. applicationVariants.all { variant ->
  7. variant.outputs.each{ output ->
  8. def outputFile = output.outputFile
  9. if (outputFile != null && outputFile.name.endsWith(".apk")) {
  10. def fileName = "$"+".apk"
  11. output.outputFile = new File(outputFile.parent, fileName);
  12. }
  13. }
  14. }
  15. }
  16. }

7. Other skills:


① Different application names can be assigned to apk of different channels


  1. productFlavors { xiaomi{
  2. // manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
  3. resValue "string", "app_name", "xiaomi"
  4. }
  5. wandoujia{
  6. // manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
  7. resValue "string", "app_name", "wandoujia"
  8. }

② Test packages that can be installed on the same mobile phone with different function points

  1. productFlavors {
  2. okhttp {
  3. applicationIdSuffix "okhttp"
  4. resValue "string", "app_name", "okhttp"
  5. }
  6. jpush {
  7. applicationIdSuffix "jpush"
  8. resValue "string", "app_name", "jpush"
  9. }
  10. }




Multichannel packaging is because there are too many app stores in the current market, so there is multichannel packaging for this situation, which allows users to download apps in different app stores

3 May 2020, 14:07 | Views: 7910

Add new comment

For adding a comment, please log in
or create account

0 comments