博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在一台设备上安装不同版本的安卓应用
阅读量:6963 次
发布时间:2019-06-27

本文共 2668 字,大约阅读时间需要 8 分钟。

第一步:

1. Create the variant dependent strings in your build script

Edit your build.gradle file accordingly:

 

//This line allows parameterization via the terminal and the Gradle VM Optionsdef debugsuffix = System.          getProperty('debugsuffix', project.getProperties().get('debugsuffix', null))def final yourApplicationId = 'your.application.id'android {    //In the defaultConfig and all your product flavors create build dynamic variables  defaultConfig {      applicationId = yourApplicationId    //These are the values for the authorities and account types.    //Reference them in the java files with e.g. BuildConfig.ACCOUNT_TYPE.      buildConfigField "String", "ACCOUNT_TYPE", "\"${applicationId}.account\""      buildConfigField "String", "AUTHORITY", "\"${applicationId}.provider\""    //Reference them in .xml files.      resValue "string", "account_type", "${applicationId}.account"      resValue "string", "authority", "${applicationId}.provider"    }  productFlavors {      dev {      applicationId = yourApplicationId + ".dev" + debugsuffix    //Reference them again so they get overwritten by the flavor.      buildConfigField "String", "ACCOUNT_TYPE", "\"${applicationId}.account\""      buildConfigField "String", "AUTHORITY", "\"${applicationId}.provider\""      resValue "string", "account_type", "${applicationId}.account"      resValue "string", "authority", "${applicationId}.provider"    }  }}

  

第二部:

 

2. Refer to them in your Android Manifest

Replace the permissions and provider authorities in yourAndroidManifest.xml with ${applicationId}:

 

  

 

第三步:

 

3. Refactor your Java source files with the build specific strings

Update every occurrence of static strings for authorities and account types in your source files.

 

 

public static final String AUTHORITY = BuildConfig.AUTHORITY;  public static final String AUCCOUNT_TYPE = BuildConfig.ACCOUNT_TYPE;

  

 

第四步:

添加xml文件

 

4. Refactor your SyncAdapter resources

Use the resValue in the syncadapter.xml in res/xml:

 

  

 

Another nice way to use this is utilising the the Jenkins build number as a suffix.

Et voilà, you can now build and install different app versions on a single device. Just make sure to do some heavy testing, as some static strings hide themselves and can break something. During research it turned out that using the pre-build variable applicationIdSuffix does not work properly, as the application ID gets changed after the buildFlavor. Another important thing to mention is that you have to sync the project with gradle files after you changed the Gradle VM options.

 

From:

https://blog.grandcentrix.net/how-to-install-different-app-variants-on-one-android-device/

转载地址:http://nczsl.baihongyu.com/

你可能感兴趣的文章
js操作单选框
查看>>
说说内存可见性
查看>>
oracle的内存spa与pga
查看>>
百度发力智能终端 百加异军突起
查看>>
《TableStore最佳实践:轻松实现轨迹管理与地理围栏》
查看>>
网络基本功(四):细说路由(上)
查看>>
我的友情链接
查看>>
解决大数据难题 阿里云MaxCompute获科技大奖
查看>>
修复Mysql数据库
查看>>
Java基础学习第八天
查看>>
MySQL备份导致的waiting for global read lock
查看>>
javascriptEvent对象
查看>>
Linux 基础学习bash特性 (二)
查看>>
laravel 常用的第三方扩展包
查看>>
Mac入门(二)Mac os x用户必须掌握的触摸手势
查看>>
各类网址
查看>>
人生没有乞丐
查看>>
iOS 9音频应用播放音频之第一个ios9音频实例2
查看>>
win8.1不支持LOL 升级需谨慎
查看>>
oracle创建用户
查看>>