1.修改项目根目录下build.gradle文件,
在buildscript下的dependencies中增加:
classpath 'com.meituan.android.walle:plugin:1.1.6'
2. 修改app工程的build.gradle文件,增加如下信息:
- 1)头部增加:
apply plugin: 'walle'
- 2)确保有签名配置,下面是样例,
signingConfigs {
release {
storeFile file("../xx.jks") // 打包的文件的地址
storePassword "123456"
keyAlias "xx"
keyPassword "123456"
}
debug {
storeFile file("../xx.jks")
storePassword "123456"
keyAlias "xx"
keyPassword "123456"
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
- 3)增加如下配置:
walle {
// 指定渠道包的输出路径
apkOutputFolder = new File("${project.buildDir}/outputs/channels");
// 定制渠道包的APK的文件名称
apkFileNameFormat = '${appName}-${packageName}-${channel}-${buildType}-v${versionName}-${versionCode}-${buildTime}.apk';
// 渠道配置文件
channelFile = new File("${project.getProjectDir()}/channel")
}
- 4)app的在dependencies中增加:
implementation 'com.meituan.android.walle:library:1.1.6'
3. 在app工程下新建文件channel,放置渠道信息(根据实际需要修改):
xiaomi
360
huawei
vivo
4. 获取渠道样例:
String channel = WalleChannelReader.getChannel(this.getApplicationContext());
5. 对于要设置到友盟里去,则需要参考友盟的设置方法。
6. 打包命令(更多命令及用法参考附录官方指导):
mac:./gradlew clean assembleReleaseChannels
windows:gradlew clean assembleReleaseChannels
7. build.gradle 总的配置文件,供参考:
apply plugin: 'com.android.application'
apply plugin: 'walle'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.administrator.dabao"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
signingConfig signingConfigs.create("release")
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
signingConfigs {
release {
v2SigningEnabled true
storeFile file("F:\\Android_studio\\keystore\\android.keystore")
storePassword "123456"
keyAlias "key0"
keyPassword "123456"
}
}
}
walle {
// 指定渠道包的输出路径
apkOutputFolder = new File("${project.buildDir}/outputs/channels");
// 定制渠道包的APK的文件名称
apkFileNameFormat = '${appName}-${packageName}-${channel}-${buildType}-v${versionName}-${versionCode}-${buildTime}.apk';
// 渠道配置文件
channelFile = new File("${project.getProjectDir()}/channel")
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
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'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.3'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
implementation 'com.meituan.android.walle:library:1.1.6'
}