github地址:https://github.com/Meituan-Dianping/walle
美團博客地址:http://tech.meituan.com/android-apk-v2-signature-scheme.html
前言
上面的2篇文章分別介紹了Walle的原理和使用。一般情況下,我們都能自己去搞定了。但是我在使用的過程中確實是遇到了幾個問題,在這里和大家分享下,希望可以幫助需要的人。
正文
添加walle插件,添加gradle依賴,我就不說了,上面文章已經講的很詳細了,直接上gradle代碼。
apply plugin: 'com.android.application'
apply plugin: 'walle'
android {
compileSdkVersion 24
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.javalong.myapplication"
minSdkVersion 14
targetSdkVersion 8
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test2.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
walleTest{}
}
}
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 {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.meituan.android.walle:library:1.1.3'
}
問題一
然后運行下gradle,報錯
Error:Plugin requires 'APK Signature Scheme v2 Enabled' for release.
圖片如下:
解決方法
signingConfigs {
sankuai {
storeFile file("sign/xd.jks")
storePassword 'xdshzxd'
keyPassword 'xdshzxd'
keyAlias 'xd'
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.sankuai
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.sankuai
}
}
看上面的代碼可以發現,在buildTypes中添加了signingConfig。
再運行,就不會有剛才的錯誤了。
問題二
開始執行生成多渠道命令。(記得在主模塊下添加channel 渠道文件,在上面的github的文章中已有詳細介紹,這里就不贅述了)
在AndroidStudio中的Terminal中執行
./gradlew clean assembleReleaseChannels
報錯:
Task 'assembleReleaseChannels' not found in root project 'MyApplication'.
圖片如下:
解決方法
原來在沒有使用walle時,會使用productFlavors
進行多渠道打包。
所以在gradle文件中會有這樣的設置
productFlavors {
walleTest{}
...
...
}
在這里設置了很多的渠道。
使用walle后,需要把productFlavors
注釋掉。
當然,我也沒看到github的文章中有這樣的說明,只是不注釋掉,執行明顯會報錯。這也只是我自己的猜測。
執行結果
具體生成的渠道可以在channel
文件中配置
生成的apk的文件名和生成路徑可以在gradle
中配置