如何在一台设备上安装不同版本的安卓应用

第一步:

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 Options
def 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}:

 

<permission android:name="${applicationId}.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.MAPS_RECEIVE" />

<provider   android:name=".your.provider"
            android:authorities="${applicationId}.your.provider"
            … />

  

 

第三步:

 

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:

 

<sync-adapter android:contentAuthority="@string/authority"
              android:accountType="@string/account_type"
           … />

  

 

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/

时间: 2024-08-01 00:27:12

如何在一台设备上安装不同版本的安卓应用的相关文章

一套金山毒霸能在多台电脑上安装吗

  金山毒霸是单机授权的软件,仅允许在一台电脑上使用.对于毒霸2005以后的版本,如果在多台电脑上安装使用则可能会被服务器提示超过授权人数而锁定.该锁定一周后自动解除,无法人工解锁.

ios app 如何实现在一台设备上登陆的时候另一台设备就注销的功能

问题描述 ios app 如何实现在一台设备上登陆的时候另一台设备就注销的功能 ios app 如何实现在一台设备上登陆的时候另一台设备就注销的功能,就如同QQ的多设备登陆时候的另一台设备上的账号自动退出. 解决方案 这个需服务端有消息通讯机制,或者客户端有定时检索机制,APP登录服务端分配一个SESSIONID给对应客户端,每次登录后SESSIONID都会有变化,客户端监测到本地id与服务端不一致,就强制退出: 解决方案二: 每一台设备连接服务端时,服务端都会收到消息,只要让服务端在检测到重复

iOS 怎么判断用户在另一台设备上登陆过

问题描述 iOS 怎么判断用户在另一台设备上登陆过,去退出另一台设备 解决方案 /*! @method @brief 当前登录账号在其它设备登录时的通知回调 @discussion @result */- (void)didLoginFromOtherDevice;如果另一台设备的登录了,当前设备会执行这个回调的.解决方案二:我这个代理怎么不走?应该写在什么地方解决方案三:遵守EMChatManagerLoginDelegate这个协议,注册代理//注册为SDK的ChatManager的dele

“SandJacking”攻击:在未越狱的 iOS 设备上安装恶意应用

在HITB 2016 会议中,Mi3 Security公司的安全研究员Chilik Tamir发表了一个关于"SandJacking"攻击的演讲,利用一个未打补丁的iOS漏洞在未越狱的iOS设备上使用恶意版本替换合法的应用程序,获取设备的敏感信息. 开发一个以Apple iOS系统为目标的恶意软件并不简单,首先,iOS中的应用程序都运行在沙箱中以防止其他进程访问.沙箱中包含文档.数据库.cookies--其中的任何一项都会导致严重的信息泄露,因此保护沙箱十分重要. 苹果也尝试要求所有通

在一台服务器上安装两个或多个mysql的实现步骤_Mysql

如何在一台服务器上安装两个或者更多个的mysql呢?下面是详细的操作步骤,一起来学习学习吧. 一.环境 mysql软件包:      mysql-5.6.31.tar      mysql-5.5.32.tar 操作系统环境:      CentOS release 6.8 (Final) 二.系统规模 /mysqlsoft 用来存放mysql的各个程序 /mysqlsoft/mysql1 用来存放mysql-5.5.32.tar的安装程序 /mysqlsoft/mysql2 用来存放mysql

Windows KB3119142补丁反复在用户设备上安装

最近不少用户反映,微软推出的Windows KB3119142补丁在用户设备上成功安装一次之后,居然反复在用户设备上继续安装,受此问题影响的都是Windows 10设备.微软社区论坛的帖子确认Windows KB3119142补丁会反复安装在用户电脑上,每次都是成功安装.查看Windows日志也可以发现,同样的更新每周都要成功安装好几次. 有用户就表示:"我检查了更新日志,发现在过去5天当中,它一天要成功安装4-5次,如果它已经成功安装,为什么要反复继续安装呢?" 另外一些用户声称,在

在Ubuntu上安装最新版本的Node.js_node.js

Node.js包含了Google V8 JavaScript引擎,libuv库和核心库几乎都是使用JavaScript编写的.libuv库提供了异步事件I/O的抽象和Node.js跨平台的机制. Node.js最初是由Ryan Dahl创建的,目前由Isaac Schlueter在演进和维护. 在互联网上有很多从源码编译安装Node.js的文章,在此我强烈建议不要采用这种方法.大多数情况下,包维护者对软件结构了解的非常清楚,开发者无需从头编译最新版本的源码. 下面的方法适用于最新版本的Ubunt

windows下在一台机器上安装两个MYSQL数据库的方法_Mysql

环境: OS:Windows 2003 DB:MYSQL5.5 1.正常安装第一个mysql(安装步骤省略) 2.在控制面板里停止第一个mysql服务 3.将C:\Program Files\MySQL目录下的所有目录和文件copy到另外一个路径,我这里是copy到E盘 4.创建第二个mysql的my.ini文件 第一个mysql的my.ini文件默认是在如下路径 C:\Documents and Settings\All Users\Application Data\MySQL\MySQL S

如何在Debian Linux上安装配置ISC DHCP服务器

动态主机控制协议(DHCP)给网络管理员提供了一种便捷的方式,为不断变化的网络主机或是动态网络提供网络层地址,其中最常用的 DHCP 服务工具是 ISC DHCP Server.DHCP 服务的目的是给主机提供必要的网络信息以便能够和其他连接在网络中的主机互相通信.DHCP 服务提供的信息包括:DNS 服务器信息,网络地址(IP),子网掩码,默认网关信息,主机名等等. 本教程介绍运行在 Debian 7.7 上 4.2.4 版的 ISC-DHCP-Server 如何管理多个虚拟局域网(VLAN)