現在整理一下,怎麼使用AndroidStudio批量打包出不同圖標、不同名稱、不同包名的apk包
一、在清單文件AndroidManifest.xml裏面寫一行代碼,
${MTA_CHANNEL_VALUE}和<pre code_snippet_id="1873609" snippet_file_name="blog_20160909_1_6562287" name="code" class="html">MTA_CHANNEL
名字可以自己取(其實沒有必要修改)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aaron.viewpager3d" >
<application
android:allowBackup="true"
<span style="font-size:10px;">android:icon="@mipmap/ic_launcher"</span>
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<span style="color:#ff0000;"><meta-data
android:name="MTA_CHANNEL"
android:value="${MTA_CHANNEL_VALUE}" /></span>
</application>
</manifest>
二、切換到AndroidStudio的Project模式下面,在src/main/的同級目錄創建2個新的文件夾(有幾個不同的包就創建幾個不同的文件夾),文件夾裏面的有幾個大家都很熟悉的內容,(我們以umeng和xiaomi爲例)
src裏面包含main,umeng,xiaomi三個文件夾,其中umeng和xiaomi裏面分別是五個圖片資源文件夾(mipmap-hdpi、mipmap-xxxdpi等)和一個values資源文件夾,圖片資源文件夾裏面放一張圖標的圖片,名稱必須一樣(這個大家都懂的),記得要和第一步中
<span style="font-size:10px;">android:icon="@mipmap/ic_launcher"</span>
的部分關聯。values裏面只需要一個string.xml文件,string.xml文件裏面只需要一個字段即可,<stringname="app_name">友盟</string>,此處是設置不同的項目名稱,
三、在build.gradle裏面配置不同的打包渠道
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
...
productFlavors {
xiaomi {// 1
applicationId "com.teb.xm"
manifestPlaceholders =[MTA_CHANNEL_VALUE:"xiaomi"]<span style="white-space:pre">
}
umeng {// 2
applicationId "com.teb.um"
manifestPlaceholders =[MTA_CHANNEL_VALUE:"umeng"]<span style="white-space:pre">
}
}
//執行lint檢查,有任何的錯誤或者警告提示,都會終止構建,我們可以將其關掉。
lintOptions {// 3
checkReleaseBuilds false<span style="white-space:pre">
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
1和2所示的是對應兩個渠道的不同配置,其中其中applicationId "com.teb.xm"是配置我們的包名
3所示位置直接寫上就行,不需要做修改(可以自己查資料去了解其意義)
需要注意的地方是,manifestPlaceholders =[MTA_CHANNEL_VALUE:"umeng"]
雙引號裏面的名稱必須和第二部裏面的文件夾名稱一致。
下面我們就能夠正常打包了,打包的最後一步選上我們需要的渠道就行了,然後就等着自己運行就行了!