添加CameraX gradle依赖项时清单合并失败

时间:2019-05-27 12:34:17

标签: android gradle camera android-gradle android-camerax

我正尝试在基于官方CameraX演示应用程序https://github.com/android/camera/tree/master/CameraXBasic

的全新Android Studio项目中使用CameraX库。

我已经在我的(模块)build.gradle中添加了以下依赖项:

    implementation "androidx.camera:camera-core:1.0.0-alpha01"
    implementation "androidx.camera:camera-camera2:1.0.0-alpha01"

和我的AndroidManifest.xml看起来像:

    <?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="simplediary.raouf.camerapoc">

        <uses-permission android:name="android.permission.CAMERA" />
        <uses-feature android:name="android.hardware.camera" />

        <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 merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.1.0-beta01] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:9:3-23:17 to override.

现在将“ tools:replace =“ android:appComponentFactory”添加到清单中的application元素会导致此错误:

Manifest merger failed with multiple errors, see logs

因此,在AndroidManifest.xml的“ Merged Manifest”下,这些是我现在看到的错误:

Error: tools:replace specified at line:9 for attribute android:appComponentFactory, but no new value specified app main manifest (this file), line 8 Error: Validation failed, exiting app main manifest (this file)

如何解决此问题?完整的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "simplediary.raouf.camerapoc"
        minSdkVersion 21
        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'
        }
    }
}

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'
    implementation "androidx.camera:camera-core:1.0.0-alpha01"
    implementation "androidx.camera:camera-camera2:1.0.0-alpha01"
    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'
}

感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

您必须迁移到AndroidX库:

步骤如下:

  

1 /进入“重构”

     

2 /在下拉菜单中选择“迁移到AndroidX”

     

3 /确保保留备份(通过版本控制或选中“保留备份”复选框)

     

4 /按照设置向导

     

5 /完成清洁项目并重建时