用android studio多渠道打包
2024-09-06 06:19:44
1. 官方教程
https://developer.android.com/studio/build/build-variants.html
2. 设置Build Types参数
打开 Project Sturcture --> Build Variatns --> Build Types
设置参数如:zipalign = true
3. 创建 dimension
进入第2个选项卡: Flavors 创建 dimension
4. 添加渠道,设置渠道参数
点 + 按钮 ---> 点 Add Product Flavor -- > 输入渠道名字 --> 设置渠道参数,如ProGuard Files.
5. 添加其它渠道
如上.添加完后,如下:
6. 设置生成apk的名字
module 的 build.gradle 文件
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao' // apply plugin
apply plugin: 'com.jakewharton.butterknife' def buildTime(){
return new Date().format("yyMMdd", TimeZone.getTimeZone("UTC"))
} android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "cn.com.example.app"
minSdkVersion 15
targetSdkVersion 26
versionCode 5
versionName "v3.1.2.180103"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
zipAlignEnabled = true
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = new File(
"${applicationId}_${variant.productFlavors[0].name}_${versionName}_${buildTime()}.apk".toLowerCase())
}
}
}
}
sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/values-zh'] } }
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
flavorDimensions 'channels'
productFlavors {
myapp {
dimension = 'channels'
minSdkVersion 22
proguardFiles 'proguard-rules.pro'
}
huawei {
dimension = 'channels'
minSdkVersion 22
proguardFiles 'proguard-rules.pro'
}
xiaomi {
dimension = 'channels'
minSdkVersion 22
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// add library
//... implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
- buildTime()是个自定义函数,返回时间.
- "${applicationId}_${variant.productFlavors[0].name}_${versionName}_${buildTime()}.apk".toLowerCase() 包名_渠道名_版本名_时间.apk
最新文章
- Java借助Runtime调用外部程序阻塞的代码
- SQLServer 随机生成指定范围的日期
- java设计模式(三)--抽象工厂模式
- VS-Visual Studio-IIS Express 支持局域网访问
- win8.1注册表-修改资源管理器的默认路径regedit
- SQL基础知识总结(一)
- IOS基础——alloc、init和new方法
- Android软键盘弹出时布局问题
- 你可以不知道原因,但是,我们不能停止努力。httplook抓取路由配置界面信息
- wind7系统修改host
- [INS-32052] Oracle基目录和Oracle主目录位置相同
- npm缺少css-loader,/style-compiler,stylus-loader问题,npm没有权限无法全局更新问题【已解决】
- 解决每次从cmd进入sqlplus,都得重新设置pagesize、linesize的问题
- post表单翻页保存搜索条件
- tiny4412 --Uboot移植(6) SD卡驱动,启动内核
- 9. svg学习笔记-裁剪和蒙版
- fastjson转换json字符串key的首字母小写变大写的解决办法
- SunRain
- jmeter性能测试的小小实践
- CentOS7安装mysql后无法启动服务,提示Unit not found
热门文章
- .Net Core中简单使用MongoDB
- AsyncTask被废弃了,换Coroutine吧
- 当面试官问我ArrayList和LinkedList哪个更占空间时,我这么答让他眼前一亮
- 初步理解@Transactional注解
- 003.Nginx配置解析
- 2020-05-21:es底层读写原理?倒排索引原理?
- C#LeetCode刷题之#278-第一个错误的版本(First Bad Version)
- [netty4][netty-common]netty之ResourceLeakDetector的使用与实现
- EXCEL 中数据 批量 填充进 word 中
- Javascript之其实我觉得原型链没有难的那么夸张!