Android Studio 簡單配置多渠道包案例
前言
該配置解決了多渠道包和多渠道號的打包問題,並且使用簡單的配置文件
過程
新建一個AS工程,工程截圖如下
我們新建一個channel.txt,並且增加渠道名字和渠道號
baidu:1111n360:2222n91:3333n:4444n:5555nwandoujia:6666n
為了使得我們的配置能夠生效,需要修改manifest.xml,增加如下兩行:
<!-- app pid -->n <meta-data android:name="CHANNEL_ID" android:value="${APP_PID_PLACEHOLDER}" />n <!-- app key -->n <meta-data android:name="CHANNEL_NAME" android:value="${APP_KEY_PLACEHOLDER}" />n
同樣的build.gradle也需要進行相應的修改:
buildscript {n repositories {n mavenCentral()n }n dependencies {n classpath com.android.tools.build:gradle:1.0.0n }n}nnnapply plugin: com.android.applicationnntasks.withType(JavaCompile) { options.encoding = "UTF-8" }nnnandroid {n compileSdkVersion 22n buildToolsVersion "22.0.1"nn defaultConfig {n applicationId "com.example.monkey.multichannelapk"n minSdkVersion 10n targetSdkVersion 22n versionCode 1n versionName "1.0"n }n sourceSets {nnn // Move the tests to tests/java, tests/res, etc...n instrumentTest.setRoot(tests)nn // Move the build types to build-types/<type>n // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...n // This moves them out of them default location under src/<type>/... which wouldn // conflict with src/ being used by the main source set.n // Adding new build types or product flavors should be accompaniedn // by a similar customization.n debug.setRoot(build-types/debug)n release.setRoot(build-types/release)n }nnn buildTypes {n release {n minifyEnabled falsen proguardFiles getDefaultProguardFile(proguard-android.txt), proguard-rules.pron }n }nn packagingOptions {n exclude META-INF/DEPENDENCIES.txtn exclude META-INF/LICENSE.txtn exclude META-INF/NOTICE.txtn exclude META-INF/NOTICEn exclude META-INF/LICENSEn exclude META-INF/DEPENDENCIESn exclude META-INF/notice.txtn exclude META-INF/license.txtn exclude META-INF/dependencies.txtn exclude META-INF/LGPL2.1n }n productFlavors {n def path="./channel.txt"n file(path).eachLine { line->n def words = line.split(:)n def key = words[0]n def channel = words[1]n if (key == ) {n key = channeln }n def name = s+channeln "$name" {n manifestPlaceholders=[APP_KEY_PLACEHOLDER:key, APP_PID_PLACEHOLDER:name]n }n }n }nn}nndependencies {n compile fileTree(dir: libs, include: [*.jar])n compile com.android.support:appcompat-v7:22.1.1n}n
打出的包可以在如下一次性找到:
最後附上打包gif
推薦閱讀:
※Atomic Red Team:針對安防設計的新型自動化測試框架
※如何使用MATLAB寫測試(6): 用Tag分類你的測試
※Android手工測試獲取代碼覆蓋率解決方案
※GUI自動化測試進階:頁面對象模式
※某測試模擬器性能優化-用vprof對Python程序性能調優