使用美團(tuán)Walle多渠道打包

github地址:https://github.com/Meituan-Dianping/walle
美團(tuán)博客地址:http://tech.meituan.com/android-apk-v2-signature-scheme.html

前言

上面的2篇文章分別介紹了Walle的原理和使用。一般情況下,我們都能自己去搞定了。但是我在使用的過程中確實(shí)是遇到了幾個(gè)問題,在這里和大家分享下,希望可以幫助需要的人。

正文

添加walle插件,添加gradle依賴,我就不說了,上面文章已經(jīng)講的很詳細(xì)了,直接上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'
}

問題一

然后運(yùn)行下gradle,報(bào)錯(cuò)
Error:Plugin requires 'APK Signature Scheme v2 Enabled' for release.

圖片如下:

image.png

解決方法

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
        }
    }

看上面的代碼可以發(fā)現(xiàn),在buildTypes中添加了signingConfig。

再運(yùn)行,就不會(huì)有剛才的錯(cuò)誤了。

問題二

開始執(zhí)行生成多渠道命令。(記得在主模塊下添加channel 渠道文件,在上面的github的文章中已有詳細(xì)介紹,這里就不贅述了)

在AndroidStudio中的Terminal中執(zhí)行
./gradlew clean assembleReleaseChannels

報(bào)錯(cuò):
Task 'assembleReleaseChannels' not found in root project 'MyApplication'.
圖片如下:

image.png

解決方法

原來在沒有使用walle時(shí),會(huì)使用productFlavors進(jìn)行多渠道打包。
所以在gradle文件中會(huì)有這樣的設(shè)置

productFlavors {
       walleTest{}
       ...
       ...
   }

在這里設(shè)置了很多的渠道。
使用walle后,需要把productFlavors注釋掉。
當(dāng)然,我也沒看到github的文章中有這樣的說明,只是不注釋掉,執(zhí)行明顯會(huì)報(bào)錯(cuò)。這也只是我自己的猜測。

執(zhí)行結(jié)果

image.png

具體生成的渠道可以在channel文件中配置
生成的apk的文件名和生成路徑可以在gradle中配置

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容