我的 build.gradle 中有两种产品风格,如下所示:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.2"
aaptOptions.setProperty("cruncherEnabled", false)
defaultConfig {
minSdkVersion 15
targetSdkVersion 16
applicationId "com.example.app"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
def final myApplicationId = 'com.example.app'
def final appName = 'app'
productFlavors {
dev {
resValue "string", "app_name", appName
resValue "string", "APIURL", "http://prod.example.com/"
}
production {
resValue "string", "app_name", appName
resValue "string", "APIURL", "http://test.example.com/"
}
}
buildTypes{
dtest {
applicationIdSuffix ".dev"
}
dprod{
}
}
}
dependencies {
compile()
few libraries
}
我的dev/AndroidManifest.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app.dev"
android:installLocation="auto"
android:versionCode="3"
android:versionName="3.1">
</manifest>
而我的production/AndroidManifest.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:installLocation="auto"
android:versionCode="3"
android:versionName="3.1">
</manifest>
我的main/AndroidManifest.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:installLocation="auto"
android:versionCode="3"
android:versionName="3.1">
<application>
<activity list.. </activity>
</application>
</manifest>
我想在同一台设备上安装 dev 和 production flavor,但即使我设置了不同的 applicationId,我也无法更改包名称。我怀疑我在主 list 中提到的包名称以某种方式覆盖了 build.gradle 中的 applicationId。如果有人指出我正确的方向,我将不胜感激。谢谢。
最佳答案
与其在 productFlavors
中设置,不如在 buildTypes
中添加它
使用
buildTypes {
debug {
applicationIdSuffix ".dev"
// Rest of the code block
}
release {
// your code block
}
}
更新
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.2"
aaptOptions.setProperty("cruncherEnabled", false)
defaultConfig {
minSdkVersion 15
targetSdkVersion 16
applicationId "com.example.app"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
buildTypes {
debug{
applicationIdSuffix ".dev"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
dev {
resValue "string", "app_name", appName
resValue "string", "APIURL", "http://prod.example.com/"
}
production {
resValue "string", "app_name", appName
resValue "string", "APIURL", "http://test.example.com/"
}
}
}
dependencies {
compile()
few libraries
}
关于android - 处理产品口味时,main/AndroidManifest.xml 中的包名称应该是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35481113/