Android Studio Multi-Channel Packaging (1)

Keywords: Android Gradle xml

1. Multi-channel concept

  • APP s are published to different application platforms to monitor from which platform users are installed.

2. Why multi-channel packaging

  • Statistics User Installation APP Sources
  • Batch modify generated apk file name
  • Changeable package name
  • Generate different application names or icons

3. Multi-Channel Configuration

  • Add a meta-data tag to the application tag of AndroidManifest.xml to define the MTA_CHANNEL placeholder as follows
    <meta-data android:name="MTA_CHANNEL"
                android:value="${MTA_CHANNEL_VALUE}" />
  • Modify the build.gradle file under app and add the productFlavors property configuration placeholder
    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"
    
        defaultConfig {
            applicationId "com.aimerd.channel"
            minSdkVersion 11
            targetSdkVersion 21
            versionCode 1
            versionName "1.0.0"
            multiDexEnabled true
        }
    buildTypes {
            debug {
                minifyEnabled false
                debuggable true
            }
            release {
                // Do not display Log
                buildConfigField "boolean", "LOG_DEBUG", "false"
                //Enable the ability to obfuscate code
                minifyEnabled true
                //apk package generated by compression alignment
                zipAlignEnabled true
                //Specify confusion rules that require compression for optimized confusion Replace proguard-android.txt with proguard-android.txt
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                //Remove unused resource files
                shrinkResources true
                //Enable support for multidex
                multiDexEnabled true
            }
        }
    productFlavors uc { manifestPlaceholders = [MTA_CHANNEL_VALUE: "uc"] } _360 { manifestPlaceholders = [MTA_CHANNEL_VALUE: "360"] } baodu { manifestPlaceholders = [MTA_CHANNEL_VALUE: "baidu"] } xiaomi { manifestPlaceholders = [MTA_CHANNEL_VALUE: "xiaomi"] } } }
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:23.3.0'
    }

4. Generate Channel Package

  • Type gradlew assembleRelease on the command line to generate all Release packages in the buildoutputs\apk directory
  • Generate the specified package (uc|360|baidu|xiaomi), the specified version (Release|Debug), and the Gradle Project on the right can help you

 

From then on, the packaging is complete

Posted by Festy on Wed, 26 Feb 2020 08:39:44 -0800