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

简介: 第一步: 1. Create the variant dependent strings in your build script Edit your build.gradle file accordingly:   //This line allows parameterizatio...

第一步:

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/

目录
相关文章
|
10月前
|
开发框架 前端开发 Android开发
Flutter 与原生模块(Android 和 iOS)之间的通信机制,包括方法调用、事件传递等,分析了通信的必要性、主要方式、数据传递、性能优化及错误处理,并通过实际案例展示了其应用效果,展望了未来的发展趋势
本文深入探讨了 Flutter 与原生模块(Android 和 iOS)之间的通信机制,包括方法调用、事件传递等,分析了通信的必要性、主要方式、数据传递、性能优化及错误处理,并通过实际案例展示了其应用效果,展望了未来的发展趋势。这对于实现高效的跨平台移动应用开发具有重要指导意义。
968 4
|
5月前
|
存储 Android开发
如何查看Flutter应用在Android设备上已被撤销的权限?
如何查看Flutter应用在Android设备上已被撤销的权限?
255 64
|
2月前
|
存储 机器学习/深度学习 API
Android API Level 到底是什么?和安卓什么关系?应用发布如何知道自己的版本?优雅草卓伊凡
Android API Level 到底是什么?和安卓什么关系?应用发布如何知道自己的版本?优雅草卓伊凡
415 31
Android API Level 到底是什么?和安卓什么关系?应用发布如何知道自己的版本?优雅草卓伊凡
|
5月前
|
存储 Android开发 数据安全/隐私保护
如何在Android设备上撤销Flutter应用程序的所有权限?
如何在Android设备上撤销Flutter应用程序的所有权限?
331 64
|
5月前
|
缓存 Android开发 开发者
Flutter环境配置完成后,如何在Android设备上运行Flutter应用程序?
Flutter环境配置完成后,如何在Android设备上运行Flutter应用程序?
949 62
|
5月前
|
开发工具 Android开发 开发者
在Android设备上运行Flutter应用程序时,如果遇到设备未授权的问题该如何解决?
在Android设备上运行Flutter应用程序时,如果遇到设备未授权的问题该如何解决?
297 61
|
7月前
|
移动开发 安全 Java
Android历史版本与APK文件结构
通过以上内容,您可以全面了解Android的历史版本及其主要特性,同时掌握APK文件的结构和各部分的作用。这些知识对于理解Android应用的开发和发布过程非常重要,也有助于在实际开发中进行高效的应用管理和优化。希望这些内容对您的学习和工作有所帮助。
676 83
|
5月前
|
Java API 开发工具
Android cmdline-tools版本与最小JDK的关系
总的来说,Android的命令行工具和JDK之间的关系就像是一场舞会,两者需要彼此配合,才能共同创造出美妙的舞蹈。如果选择了不合适的舞伴(即不兼容的版本),可能会导致舞蹈中的步伐混乱,甚至无法完成舞蹈。而即使选择了合适的舞伴,也需要考虑舞伴的舞蹈技巧(即性能和稳定性),才能确保舞蹈的完美表现。因此,选择合适的Android命令行工具和JDK版本,是每一个Android开发者都需要面对的重要决定。
179 13
|
10月前
|
人工智能 搜索推荐 物联网
Android系统版本演进与未来展望####
本文深入探讨了Android操作系统从诞生至今的发展历程,详细阐述了其关键版本迭代带来的创新特性、用户体验提升及对全球移动生态系统的影响。通过对Android历史版本的回顾与分析,本文旨在揭示其成功背后的驱动力,并展望未来Android可能的发展趋势与面临的挑战,为读者呈现一个既全面又具深度的技术视角。 ####
|
6月前
|
安全 开发工具 Android开发
【Android Git】Git版本回退方式
在实际操作中,选择合适的版本回退方式,可以有效地管理代码版本,提高开发效率和代码质量。
325 26