在 android 工作室中创建构建变体源集时出错
Getting error while creating build variant source set in android studio
我是 Android Studio 构建变体的新手。我创建了一个新应用程序,在 gradle 中编辑了构建风格并成功同步了它。但是当我为其中一个构建变体(demoDebug)添加源集时,它显示错误。
模块级别build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.shaon.myappbuildtest"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
flavorDimensions "version"
productFlavors {
demo {
dimension "version"
applicationIdSuffix ".demo"
versionNameSuffix "-demo"
}
full {
dimension "version"
applicationIdSuffix ".full"
versionNameSuffix "-full"
}
}
sourceSets { debug { java.srcDirs = ['src/debug/java', 'src/debug/java/'] } }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
项目结构屏幕截图:
Manifest.xml 主
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shaon.myappbuildtest">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
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>
Manifest.xml 用于 demoDebug
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shaon.myappbuildtest.demo.debug">
<application>
<activity android:name="com.example.shaon.myappbuildtest.demo.debug.MainActivityDemoDebug"></activity>
</application>
</manifest>
为 demoDebug 创建源集文件夹时出现错误:
Manifest merger failed : Overlay manifest:package attribute declared at AndroidManifest.xml:2:5-58 value=(com.example.shaon.myappbuildtest.demo.debug)
has a different value=(com.example.shaon.myappbuildtest.demo.debug) declared in main manifest at AndroidManifest.xml:3:5-47
Suggestion: remove the overlay declaration at AndroidManifest.xml and place it in the build.gradle:
flavorName {
applicationId = "com.example.shaon.myappbuildtest.demo.debug"
}
我做错了什么?我该如何解决?
从 AndroidManifest.xml
中删除 package
参数。 Gradle 插件将使用来自 build.gradle
的声明自动为您填充它。
我是 Android Studio 构建变体的新手。我创建了一个新应用程序,在 gradle 中编辑了构建风格并成功同步了它。但是当我为其中一个构建变体(demoDebug)添加源集时,它显示错误。
模块级别build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.shaon.myappbuildtest"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
flavorDimensions "version"
productFlavors {
demo {
dimension "version"
applicationIdSuffix ".demo"
versionNameSuffix "-demo"
}
full {
dimension "version"
applicationIdSuffix ".full"
versionNameSuffix "-full"
}
}
sourceSets { debug { java.srcDirs = ['src/debug/java', 'src/debug/java/'] } }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
项目结构屏幕截图:
Manifest.xml 主
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shaon.myappbuildtest">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
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>
Manifest.xml 用于 demoDebug
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shaon.myappbuildtest.demo.debug">
<application>
<activity android:name="com.example.shaon.myappbuildtest.demo.debug.MainActivityDemoDebug"></activity>
</application>
</manifest>
为 demoDebug 创建源集文件夹时出现错误:
Manifest merger failed : Overlay manifest:package attribute declared at AndroidManifest.xml:2:5-58 value=(com.example.shaon.myappbuildtest.demo.debug)
has a different value=(com.example.shaon.myappbuildtest.demo.debug) declared in main manifest at AndroidManifest.xml:3:5-47
Suggestion: remove the overlay declaration at AndroidManifest.xml and place it in the build.gradle:
flavorName {
applicationId = "com.example.shaon.myappbuildtest.demo.debug"
}
我做错了什么?我该如何解决?
从 AndroidManifest.xml
中删除 package
参数。 Gradle 插件将使用来自 build.gradle
的声明自动为您填充它。