android 多包名apk,一个项目如何编译多个不同签名、包名、资源等,的apk?
4
其他需要注意的事项
如果您在清单文件AndroidManifest.xml中,有那种以包名开头命名的那种。因为如果包名都改了,有些也需要动态的改变。可以用${applicationId}代替。在打包的时候,会自动替换成当前包名。
比如,类似下配置:
android:name="com.xxx.xx.permission.JPUSH_MESSAGE"
android:protectionLevel="signature"/>
android:name=".push.MyJPushMessageReceiver"
android:enabled="true"
android:exported="false">
android:name="android.support.v4.content.FileProvider"
android:authorities="com.xxx.xx.provider"
android:exported="false"
tools:replace="android:authorities"
android:grantUriPermissions="true">
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
可改为:
android:name="${applicationId}.permission.JPUSH_MESSAGE"
android:protectionLevel="signature"/>
android:name=".push.MyJPushMessageReceiver"
android:enabled="true"
android:exported="false">
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
tools:replace="android:authorities"
android:grantUriPermissions="true">
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
当然值得注意的是,在代码中我们也不能把包名写死了,可通过BuildConfig得到当前包名
5
我的完整配置,供参考
有关隐私信息的都用xxx替换了
1. 项目根目录的build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
build {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "io.github.prototypez:save-state:0.1.7"
// NOTE:Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io"}
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/'}
flatDir {
dirs 'libs'
}
}
}
task clean( type: Delete) {
deleterootProject.buildDir
}
ext{
minSdkVersion = 16
targetSdkVersion = 27
compileSdkVersion = 27
buildToolsVersion = '27.1.1'
supportLibraryVersion = '27.1.1'
xmvpVersion = '1.2.2'
retrofit2Version = '2.3.0'
okhttp3Version = '3.8.1'
butterknifeVersion = '8.6.0'
rx2Version = '2.0.2'
CircleProgressDialogVersion = '1.0.2'
smarttabVersion = '1.6.1@aar'
adapterHelperVersion = '2.9.41'
glideVersion = '4.7.1'
roundedimageviewVersion = '2.3.0'
eventbusVersion = '3.0.0'
dispatcherVersion = '2.4.0'
picture_libraryVersion = 'v2.2.3'
statusbarutilVersion = '1.5.1'
okhttpUtilsVersion = '3.8.0'
constraintVersion = '1.1.3'
flexboxVersion = '1.0.0'
}
2. app目录下的build.gradle
apply plugin: 'com.android.application'
apply plugin: 'save.state'
staticdef releaseTime() {
returnnewDate().format( "yyyy-MM-dd-HH.mm", TimeZone.getTimeZone( "GMT+8"))
}
android {
compileSdkVersion rootProject.compileSdkVersion
// buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
// config the JSON processing library
javaCompileOptions {
annotationProcessorOptions {
arguments = [ serializer : "gson"]
}
}
ndk {
abiFilters "armeabi-v7a"
}
renderTargetApi 25
renderSupportModeEnabled true
}
signingConfigs {
userquhuaRelease {
storeFile file( "../key/xxx.keystore")
storePassword "xxxxxx"
keyAlias "xxx"
keyPassword "xxxxxx"
}
quhuaRelease {
storeFile file( "../key/xxx.keystore")
storePassword "xxxxxxx"
keyAlias "xxx"
keyPassword "xxxxxxx"
}
cuntubaRelease {
storeFile file( "../key/xxx.keystore")
storePassword "xxxxxxx"
keyAlias "xxx"
keyPassword "xxxxxxx"
}
xemhRelease {
storeFile file( "../key/xxx.keystore")
storePassword "xxxxxxx"
keyAlias "xxx"
keyPassword "xxxxxxx"
}
}
flavorDimensions "default"
productFlavors {
userquhua {
applicationId "com.xxx.xx"
versionCode 22
versionName "1.7.5"
signingConfig = signingConfigs.userquhuaRelease
Stringqq_id = '"xxxxxx"'
buildConfigField "String", "QQ_ID", qq_id // qq appId
buildConfigField "String", "SINA_ID", '"xxxxxx"'// 新浪appId
buildConfigField "String", "WX_ID", '"xxxxxx"'// 微信 appId
buildConfigField "String", "UM_ID", '"xxxxxx"'// 友盟
buildConfigField "String", "WX_SECRET", '"xxxxxx"'// 微信 secret
buildConfigField "String", "SINA_REDIRECT", '"http://open.weibo.com/apps/xxxxxx/privilege/oauth"'// 新浪
buildConfigField "String", "ADHUB_INIT_ID", '"xxxxxx"'// 广告sdk初始化id
buildConfigField "String", "ADHUB_SPLASH_ID", '"xxxxxx"'// 开屏广告id
buildConfigField "String", "ADHUB_BANNER_ID", '"xxxxxx"'// banner广告id
buildConfigField "String", "SERVER_URL", '"http://xxx.xxx.com/"'
buildConfigField "String", "LOGO_URL", '"http://file.xxx.com/img/xxx.png"'
manifestPlaceholders = [
qq_id: qq_id,
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "xxxxxx", //JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
}
quhua {
applicationId "com.xxx.xx"
versionCode 1
versionName "1.0.0"
signingConfig = signingConfigs.quhuaRelease
Stringqq_id = '"xxxxxx"'
buildConfigField "String", "QQ_ID", qq_id
buildConfigField "String", "SINA_ID", '"xxxxxx"'
buildConfigField "String", "WX_ID", '"xxxxxx"'
buildConfigField "String", "UM_ID", '"xxxxxx"'
buildConfigField "String", "WX_SECRET", '"xxxxxx"'
buildConfigField "String", "SINA_REDIRECT", '"http://open.weibo.com/apps/xxxxxx/privilege/oauth"'
buildConfigField "String", "ADHUB_INIT_ID", '"xxxxxx"'// 广告sdk初始化id
buildConfigField "String", "ADHUB_SPLASH_ID", '"xxxxxx"'// 开屏广告id
buildConfigField "String", "ADHUB_BANNER_ID", '"xxxxxx"'// banner广告id
buildConfigField "String", "SERVER_URL", '"http://xx.xxx.com/"'
buildConfigField "String", "LOGO_URL", '"http://file.xxx.com/img/xxx.png"'
manifestPlaceholders = [
qq_id: qq_id,
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "xxxxxx", //JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
}
cuntuba {
applicationId "com.xxx.xx"
versionCode 1
versionName "1.0.0"
signingConfig = signingConfigs.cuntubaRelease
Stringqq_id = '"xxxxxx"'
buildConfigField "String", "QQ_ID", qq_id
buildConfigField "String", "SINA_ID", '"xxxxxx"'
buildConfigField "String", "WX_ID", '"xxxxxx"'
buildConfigField "String", "UM_ID", '"xxxxxx"'
buildConfigField "String", "WX_SECRET", '"xxxxxx"'
buildConfigField "String", "SINA_REDIRECT", '"http://open.weibo.com/apps/xxxxxx/privilege/oauth"'
buildConfigField "String", "ADHUB_INIT_ID", '"xxxxxx"'// 广告sdk初始化id
buildConfigField "String", "ADHUB_SPLASH_ID", '"xxxxxx"'// 开屏广告id
buildConfigField "String", "ADHUB_BANNER_ID", '"xxxxxx"'// banner广告id
buildConfigField "String", "SERVER_URL", '"http://xxx.xxxx.com/"'
buildConfigField "String", "LOGO_URL", '"http://file.xxx.com/img/xxx.png"'
manifestPlaceholders = [
qq_id: qq_id,
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "xxxxxx", //JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
}
xemh {
applicationId "com.xxx.xx"
versionCode 1
versionName "1.0.0"
signingConfig = signingConfigs.xemhRelease
Stringqq_id = '"xxxxxx"'
buildConfigField "String", "QQ_ID", qq_id
buildConfigField "String", "SINA_ID", '"xxxxxx"'
buildConfigField "String", "WX_ID", '"xxxxxx"'
buildConfigField "String", "UM_ID", '"xxxxxx"'
buildConfigField "String", "WX_SECRET", '"xxxxxx"'
buildConfigField "String", "SINA_REDIRECT", '"xxxxxx"'
buildConfigField "String", "ADHUB_INIT_ID", '"xxxxxx"'// 广告sdk初始化id
buildConfigField "String", "ADHUB_SPLASH_ID", '"xxxxxx"'// 开屏广告id
buildConfigField "String", "ADHUB_BANNER_ID", '"xxxxxx"'// banner广告id
buildConfigField "String", "SERVER_URL", '"http://xx.xxx.com/"'
buildConfigField "String", "LOGO_URL", '"http://file.xxxxxx.com/img/xxxxxx.png"'
manifestPlaceholders = [
qq_id: qq_id,
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "xxxxxx", //JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
}
}
applicationVariants.all {
variant ->
variant.outputs.all {
outputFileName = "${variant.productFlavors[0].name}-v${variant.productFlavors[0].versionName}-${releaseTime()}.apk"
}
}
buildTypes {
release {
// 不显示Log
buildConfigField "boolean", "LOG_DEBUG", "false"
signingConfig null
minifyEnabled true
zipAlignEnabled true
// 移除无用的resource文件
shrinkResources true
proguardFiles getDefaultProguardFile( 'proguard-android.txt'), 'proguard-rules.pro'
}
debug {
// 显示Log
buildConfigField "boolean", "LOG_DEBUG", "true"
signingConfig null
minifyEnabled false
zipAlignEnabled false
shrinkResources false
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
dexOptions {
javaMaxHeapSize "4g"//此处可根据电脑本身配置 数值越大 当然越快
preDexLibraries = false
}
}
repositories {
flatDir {
dirs 'libs', '../adpoymer/libs'
}
}
dependencies {
// 省略
}
结束
就这样就可以解放大量劳动力啦!每次项目打包各种软件,选一下就ojbk,哈哈哈~
如果有些配置在其他渠道没有的,也可通过BuildConfig在java中判断如果是某某渠道那么屏蔽。返回搜狐,查看更多
android 多包名apk,一个项目如何编译多个不同签名、包名、资源等,的apk?相关推荐
- 一个项目如何编译多个不同签名、包名、资源等,的apk?
简介 如题所示!本篇文章就是为了解决这种问题.方便打包和运行的时候能做到无需手动替换配置,即可打包想要的apk.打包的时候,只需选一下想打哪种配置的apk就OK啦. (^o^)/~ 先来看,有需求如下 ...
- 一个项目如何编译多个不同签名,包名,资源等
简介 如题所示!本篇文章就是为了解决这种问题.方便打包和运行的时候能做到无需手动替换配置,即可打包想要的apk.打包的时候,只需选一下想打哪种配置的apk就OK啦. (^o^)/~ 先来看,有需求如下 ...
- 在idea项目中的android包不能识别_项目调试编译和部署运行
项目调试 Logcat日志 顾名思义,logcat是android系统的日志包,提供给开发者供调试程序时使用.logcat一共有Verbose.Debug.Info.Warn.Error等不同级别的日 ...
- android添加工程依赖工程,将项目依赖项添加到Android studio中的另一个项目
我有一个现有的项目说A,它依赖于几个项目.现在我想将这个项目A作为Project B的库项目.到目前为止,我所做的是在Project A的build.gradle中,我已将插件从"andro ...
- Android Studio开发环境及第一个项目
1. 在你的电脑上搭建Android平台开发环境. 2. 新建项目,实现以下基本内容: (1) 修改默认的APP的名称和图标(任意的,非默认的). (2) 显示个人信息,包括:照片.专业.姓名.学号等 ...
- Android Studio快速的接受一个项目
1.关键词搜索法,搜索这个词,然后仔细的去找找.肯定可以找到的,虽然可能会有一些奔波. 2.Android device moniter ,可以抓屏幕,看布局,而且可以看到资源id.看到资源id,你说 ...
- Eric6最简单的应用(创建一个项目-窗体-编译-运行)
1.创建项目 2.创建一个窗体 自动弹出Qt designer 工具,可视化窗体界面: 创建一个关闭按钮,关闭这个窗体: 保存后,选择ui文件,进行编译ui文件: 然后执行该脚本,即可: 以上是eri ...
- android引用另一个项目作为library错误
android有时会引用另一个项目作为library, 但是老是引用不进来,后来发现原来 所引用的项目lirary跟你所在的项目不是同一个工作目录下面, 只要把library项目放到跟你的项目一个工作 ...
- Android V1、V2签名包和快速集成美团多渠道打包
今日科技快讯 三天的Google I/O大会2018终于落下帷幕,虽说现在的I/O大会重点已经变成了人工智能,但是Android P的推出还是让很多小伙伴激动不已的.这次Android P被喻为近几年 ...
最新文章
- Learning to Rank 中Listwise关于ListNet算法讲授及实现
- SAP 货物移动 BAPI 的简单使用 BAPI_GOODSMVT_CREATE
- DCMTK:I2DBmpSource类的测试程序
- Mybatis Interceptor 拦截器原理 源码分析
- mysql实体监听器_GitHub - langjiangit/spring-boot-starter-mysql-binlog: mysql的binlog监听器
- python什么是数据结构_python算法与数据结构-数据结构介绍(38)
- 关于 Intellij IDEA Ultimate Edition 14.1控制台中文乱码 解决
- 以links方式安装eclipse插件
- NameError: name ‘os‘ is not defined - 解决
- 设计模式学习总结7 - 行为型2 - Command命令模式
- kubectl源码分析之rollout restart
- android 11.0禁用电源键(屏蔽关机短按长按事件)
- Java - 什么是ORM?
- 校园网同时连手机和电脑、用数据线给电脑连网
- 使用python画简单的图
- 机电信息杂志机电信息杂志社机电信息编辑部2022年第24期目录
- sysvol 域控制器 文件_[转载]重建域控制器上的SYSVOL和NETLOGON共享
- 为什么C语言要有头文件(补充)
- 微信小程序-仿朋友圈点赞评论操作面板
- Chapter 30 Web Technology and DBMSs
热门文章
- 浙大程序员甘愿放弃三万月薪跑滴滴,自称开心比什么都好
- 201671010434王雯涵--实验二 软件工程个人项目
- newmultipartentity php,使用MultipartEntity图片上传
- 手工编程是指利用计算机完成,CAD CAM考试复习题答案(1)
- evo_traj 错误:[ERROR] Unhandled error in evo.main_traj
- integrationobjects点com all OPC Crack
- 第五天:了解越疆dobot机械臂,使用python,编写通过ros服务控制机械臂运动程序
- 11-Air-合宙820-车牌识别2-百度智能云
- 迅雷ios版下载beta
- 凸优化第三章凸函数 3.1基本性质和例子