You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Auto应用Manifest合并失败:硬件管理器属性冲突求助

Android Auto Manifest合并冲突问题解决

你在开发首个Android Auto Hello World应用时,解决minSdk错误后遇到Manifest合并失败:androidx.car.app:app-projected:1.1.0和androidx.car.app:app-automotive:1.1.0两个依赖中的meta-data#androidx.car.app.CarAppMetadataHolderService.CAR_HARDWARE_MANAGER属性值冲突,即便按提示添加tools:replace="android:value",问题仍未解决。

问题根源

你同时引入了app-projected(Android Auto)和app-automotive(Android Automotive OS)两个平台依赖,它们会在Manifest合并时注入同名但值不同的meta-data,导致冲突。通常无需同时引入这两个依赖,除非你要开发跨平台应用。


方案1:仅保留单个平台依赖(推荐)

根据你的开发目标,移除其中一个平台依赖即可解决冲突:

仅支持Android Auto的依赖配置

修改build.gradle的dependencies块:

dependencies {
    implementation("androidx.car.app:app:1.1.0")
    // 仅保留Android Auto专属依赖
    implementation("androidx.car.app:app-projected:1.1.0")
    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'
}

仅支持Android Automotive OS的依赖配置

修改build.gradle的dependencies块:

dependencies {
    implementation("androidx.car.app:app:1.1.0")
    // 仅保留Android Automotive专属依赖
    implementation("androidx.car.app:app-automotive:1.1.0")
    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'
}

方案2:同时支持双平台,手动覆盖冲突meta-data

若需开发跨平台应用,需在AndroidManifest.xml中手动添加冲突的meta-data并指定覆盖规则:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.smartherd.helloworld">

    <uses-feature
        android:name="android.hardware.type.automotive"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:appCategory="audio"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.HelloWorld">

        <service
            android:name=".HelloWorldService"
            android:exported="true">
            <intent-filter>
                <action android:name="androidx.car.app.CarAppService"/>
                <category android:name="androidx.car.app.category.POI"/>
            </intent-filter>
        </service>

        <meta-data
            android:name="androidx.car.app.minCarApiLevel"
            android:value="1"/>

        <!-- 手动添加冲突meta-data并指定覆盖 -->
        <meta-data
            android:name="androidx.car.app.CarAppMetadataHolderService.CAR_HARDWARE_MANAGER"
            android:value="androidx.car.app.hardware.AutomotiveCarHardwareManager"
            tools:replace="android:value"/>

    </application>

</manifest>

value选择说明:

  • 优先支持Android Auto:使用androidx.car.app.hardware.ProjectionCarHardwareManager
  • 优先支持Android Automotive OS:使用androidx.car.app.hardware.AutomotiveCarHardwareManager

内容的提问来源于stack exchange,提问作者downmath

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 18:54:21