3

我是 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

    <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"
    }

我做错什么了?我如何解决它?

4

1 回答 1

6

从 中删除package参数AndroidManifest.xml。Gradle 插件将使用来自的声明自动为您填充它build.gradle

于 2018-11-26T12:10:34.427 回答