This article is reprinted from: http://blog.csdn.net/qq_/article/details/78922154
1. Add the statistical dependency database of the Alliance
If you cannot integrate properly, add the following configuration:
- dependencies {
- compile 'com.umeng.sdk:common:latest.integration'
- compile 'com.umeng.sdk:analytics:latest.integration'
- }
- allprojects {
- repositories {
- mavenCentral()
- }
- }
2. Configure permissions and keys in the manifest:
In the manifest file
- <uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
- <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
- <application......>
- //The value="5a446bf5f29d987bd200008a" here is generated from your account in the alliance. See the figure
- <meta-data android:value="5a446bf5f29d987bd200008a" android:name="UMENG_APPKEY"/>
- <meta-data android:value="$" android:name="UMENG_CHANNEL"/>
- </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:
- defaultConfig {
- multiDexEnabled true //Breaking the limit of 65535 methods
- manifestPlaceholders = [UMENG_CHANNEL_VAULE: "umeng"]
- flavorDimensions "versionCode"
- }
4. Configure signature file information. Note: signingConfigs should be before buildTypes
- signingConfigs {
- release {
- keyAlias 'key0'
- keyPassword '123456'
- storeFile file('release.jks')
- storePassword '123456'
- }
- }
5. Add channel information
- productFlavors {
- yingyongbao{
- }
- xiaomi{
- }
- }
- <p>For simplicity, you can replace duplicate code with scripts < / P >
- 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
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- signingConfig signingConfigs.release
- applicationVariants.all { variant ->
- variant.outputs.each{ output ->
- def outputFile = output.outputFile
- if (outputFile != null && outputFile.name.endsWith(".apk")) {
- def fileName = "$"+".apk"
- output.outputFile = new File(outputFile.parent, fileName);
- }
- }
- }
- }
- }
7. Other skills:
① Different application names can be assigned to apk of different channels
- productFlavors { xiaomi{
- // manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
- resValue "string", "app_name", "xiaomi"
- }
- wandoujia{
- // manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
- resValue "string", "app_name", "wandoujia"
- }
② Test packages that can be installed on the same mobile phone with different function points
- productFlavors {
- okhttp {
- applicationIdSuffix "okhttp"
- resValue "string", "app_name", "okhttp"
- }
- jpush {
- applicationIdSuffix "jpush"
- resValue "string", "app_name", "jpush"
- }
- }
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