Ошибка слияния манифеста при добавлении зависимости CameraX gradle

Я пытаюсь использовать библиотеку CameraX в совершенно новом проекте 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" к элементу приложения в манифесте теперь приводит к этой ошибке:

Manifest merger failed with multiple errors, see logs

Итак, в разделе «Объединенный манифест» в AndroidManifest.xml я вижу следующие ошибки:

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)

Как я могу обойти эту проблему? Полная сборка.градле:

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

Ценим любую помощь!

Вам потребуется перейти на артефакт AndroidX. проверьте здесь: developer.android.com/jetpack/androidx/мигрировать

Jeel Vankhede 27.05.2019 14:37
1
1
831
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Вам нужно будет перейти в библиотеку AndroidX:

вот шаги:

1/ go under "refactor"

2/in the drop down menu select "Migrate to AndroidX"

3/make sure to keep a Backup (by version control or check the keep backup checkbox)

4/follow the setup wizard

5/when finished clean project & rebuild

В app -> refactor я вижу только Migrate to AppCompat и Migrate. Ни у кого из них нет ссылок на AndroidX, и у меня такая же проблема.

eyes enberg 27.05.2019 14:46

@eyesenberg иди под Refactor

Thorvald 27.05.2019 14:49

@eyesenberg Если у вас есть какие-либо зависимости Maven, которые не были перенесены в пространство имен AndroidX, или какие-либо другие проблемы во время миграции, попробуйте переопределить их вручную, перейдя в свой файл gradle.properties, а затем добавив их в строки: android.useAndroidX=true и android.enableJetifier=true

Thorvald 27.05.2019 14:50

Все та же проблема. Я не вижу AndroidX в Refactor (но добавил эти свойства gradle). Однако моя Android Studio не обновлялась, вероятно, год, поэтому обновите ее сейчас

eyes enberg 27.05.2019 15:15

@eyesenberg да, обновление AS определенно решит проблему

Thorvald 27.05.2019 15:16

Другие вопросы по теме