现在整理一下,怎么使用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"]
双引号里面的名称必须和第二部里面的文件夹名称一致。
下面我们就能够正常打包了,打包的最后一步选上我们需要的渠道就行了,然后就等着自己运行就行了!