我是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>
用于demoDebug的Manifest.xml
<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"
}
我做错了什么?我该如何解决?
答案 0 :(得分:2)
从package
中删除AndroidManifest.xml
参数。 Gradle插件会使用build.gradle
中的声明自动为您填充。