当前位置: 移动技术网 > IT编程>移动开发>Android > androidstudio3.0之后多渠道打包

androidstudio3.0之后多渠道打包

2018年10月27日  | 移动技术网IT编程  | 我要评论

玏怎么读,棉城之窗,包钢无缝管

androidstudio3.0之后多渠道打包。

1.androidmanifest.xml里面设置动态渠道变量:

2.app下完整的build.gradleapply plugin: 'com.android.application'android {

compilesdkversion 27

defaultconfig {

applicationid "app.clm.com.demoapp"

minsdkversion 15

targetsdkversion 27

versioncode 1

versionname "1.0"

flavordimensions "1"

testinstrumentationrunner "android.support.test.runner.androidjunitrunner"

}

buildtypes {

release {

//启用混淆代码的功能

minifyenabled true

//压缩对齐生成的apk包

zipalignenabled true

proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'

//移除无用的资源文件

shrinkresources true

//启用multidex的支持

multidexenabled true

}

}

productflavors{

xiaomi{ }

google{}

wandoujia{}

baidu{}

anzhi{}

qq{}

}

//输出渠道包的名字,例如 xx.apk(个人还木有完全理解这块为什么这么写)

android.applicationvariants.all{ variant ->

variant.outputs.all{ output ->

def outfile = output.outputfile

if (outfile != null && outfile.name.endswith(".apk")){

//自定义想要生成的apk格式

def filename = "${variant.productflavors[0].name}_${publishtime()}" + ".apk"

outputfilename = filename

} } }

//批量处理

productflavors.all {

flavor -> flavor.manifestplaceholders = [clm_channel: name]

}

}

//渠道def publishtime() {

return new date().format("yyyy-mm-dd", timezone.gettimezone("utc"))

}dependencies {

implementation filetree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:27.1.1'

implementation 'com.android.support.constraint:constraint-layout:1.1.0'

testimplementation 'junit:junit:4.12'

androidtestimplementation 'com.android.support.test:runner:1.0.2'

androidtestimplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

3.如果同一个apk不同渠道要添加不同的包名可以在productflavors里面实现,forexample:

xiaomi{

applicationid "com.clm.cn"

}

4.如果同一个apk不同渠道要添加不同的icon,资源可以这么实现:在main的同级目录创建相同项目结构的不同渠道,然后把不同渠道的资源或icon替换掉。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网