安卓多渠道打包

一.gradle多渠道打包

1. 在AndroidManifest.xml中定义占位符     在application里面 与activity同级

//添加这一句即可
        
        

2.项目build.gradle里的android添加签名文件的配置  如果签名文件已经配置好了可以忽略

 signingConfigs {
        release {
            storeFile file("C:/Users/Administrator/Desktop/MyApplication2/app/src/myapp.jks")   //签名文件全路径
            storePassword "123456"
            keyAlias "myapp"
            keyPassword "123456"
            //7.0使用的APK Signature Scheme v2签名方案使外部打入渠道信息会修改签名导致没办法安装 所以目前这里我们需要先禁用掉
            v2SigningEnabled false
        }
        debug {
            storeFile file("C:/Users/Administrator/Desktop/MyApplication2/app/src/myapp.jks")
            storePassword "123456"
            keyAlias "myapp"
            keyPassword "123456"
            //没办法安装 所以目前这里我们需要先禁用掉
            v2SigningEnabled false
        }
    }

在加上替换占位符的UMENG_CHANNEL_VALUE     

 productFlavors {
        wangdoujia {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wangdoujia"]
        }
        xiaomi {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
        }
        anzhi {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "anzhi"]
        }
    }

添加完以后build一下,如果报错如下

Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

请添加defaultConfig里面添加flavorDimensions "default"     整体代码如下

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.administrator.myapplication"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        flavorDimensions "default"//就是这句
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    signingConfigs {
        release {
            storeFile file("C:/Users/Administrator/Desktop/MyApplication2/app/src/myapp.jks")   //签名文件全路径
            storePassword "123456"
            keyAlias "myapp"
            keyPassword "123456"
            //7.0使用的APK Signature Scheme v2签名方案使外部打入渠道信息会修改签名导致没办法安装 所以目前这里我们需要先禁用掉
            v2SigningEnabled false
        }
        debug {
            storeFile file("C:/Users/Administrator/Desktop/MyApplication2/app/src/myapp.jks")
            storePassword "123456"
            keyAlias "myapp"
            keyPassword "123456"
            //没办法安装 所以目前这里我们需要先禁用掉
            v2SigningEnabled false
        }
    }

    productFlavors {
        wangdoujia {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wangdoujia"]
        }
        xiaomi {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
        }
        anzhi {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "anzhi"]
        }
    }

}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

然后点击build----->generate signed apk  就可看到了刚才添加的三个渠道包点击finish就可以打包了

安卓多渠道打包_第1张图片

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(安卓多渠道打包)