版权声明:博主原创欢迎分享学习 https://blog.csdn.net/qXing123456789/article/details/84565087
Android 手机同时安装debug release版(四部曲)
文章目录
引入
同一部手机上安装app的debug版和release版, 不会相互覆盖,这在开发中会用的一个小功能点,也可能在你面试的考官,考察你是否有真实开发经验,可能以这个点来问你,博主以前在一次面试中也遇到过,一般配置型,都是跟build.gradle有关,那么问题就很好处理了
步骤一 build.gradle
你可以在buildTypes—debug 中 只加这一句代码:
resValue “string”, “app_name”, “@string/app_name_debug” //配置debug包名称
buildTypes {
release {
resValue "string", "app_name", "@string/app_name_release" //配置release包名称
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
resValue "string", "app_name", "@string/app_name_debug" //配置debug包名称
applicationIdSuffix '.debug' //增加包名后缀
}
}
步骤二 strings.xml
<resources>
<string name="app_name_release">Release</string>
<string name="app_name_debug">Debug</string>
</resources>
步骤三 AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kx.test">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
步骤四 可能的坑
你按上述步骤,出现这个问题:
Error:Execution failed for task ‘:app:mergeDebugResources’. [string/app_name] D:\DevWorkSpace\KxJiaoBen\app\build\generated\res\resValues\debug\values\generated.xml [string/app_name] D:\DevWorkSpace\KxJiaoBen\app\src\main\res\values\strings.xml: Error: Duplicate resources
解决办法
删除strings.xml 文件中, 这一行原始代码即可< string name=“app_name”>Test< /string>
<string name="app_name">Test</string>
尾言
本文如有错误或不当之处,欢迎读者留言斧正,互相交流学习,博主不胜感激.联系邮箱[email protected]