Android 自动清单合并失败:属性也存在于

dow*_*ath 2 android manifest android-auto

我目前正在尝试构建一个 hello world 应用程序作为我的第一个 Android 汽车应用程序。早些时候,当我尝试运行该应用程序时,它给了我一些 minSdk 错误,我设法修复了该错误。现在,当我尝试运行它时,它给了我这个错误:

Manifest merger failed : Attribute meta-data#androidx.car.app.CarAppMetadataHolderService.CAR_HARDWARE_MANAGER@value value=(androidx.car.app.hardware.ProjectedCarHardwareManager) from [androidx.car.app:app-projected:1.1.0] AndroidManifest.xml:34:17-86
    is also present at [androidx.car.app:app-automotive:1.1.0] AndroidManifest.xml:44:17-87 value=(androidx.car.app.hardware.AutomotiveCarHardwareManager).
    Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml to override.
Run Code Online (Sandbox Code Playgroud)

我一直在尝试按照此处有关如何编辑清单文件的说明进行操作,并且根据说明一切看起来都很好。

这是 AndroidManifest.xml:

Manifest merger failed : Attribute meta-data#androidx.car.app.CarAppMetadataHolderService.CAR_HARDWARE_MANAGER@value value=(androidx.car.app.hardware.ProjectedCarHardwareManager) from [androidx.car.app:app-projected:1.1.0] AndroidManifest.xml:34:17-86
    is also present at [androidx.car.app:app-automotive:1.1.0] AndroidManifest.xml:44:17-87 value=(androidx.car.app.hardware.AutomotiveCarHardwareManager).
    Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml to override.
Run Code Online (Sandbox Code Playgroud)

构建.gradle:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.smartherd.helloworld"
        minSdk 29
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation("androidx.car.app:app:1.1.0")
    // For Android Auto specific functionality
    implementation("androidx.car.app:app-projected:1.1.0")
    // For Android Automotive specific functionality
    implementation("androidx.car.app:app-automotive:1.1.0")
    // For testing
    testImplementation("androidx.car.app:app-testing:1.2.0-rc01")
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.2'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Run Code Online (Sandbox Code Playgroud)

nar*_*rko 6

由于您的清单中的目标是 Android Automotive,因此您可以在 gradle 文件中删除以下依赖项:

    implementation("androidx.car.app:app-projected:1.1.0")
Run Code Online (Sandbox Code Playgroud)

这应该可以解决您遇到的冲突。