简体   繁体   English

Android Studio) 清单合并失败

[英]Android Studio) Manifest Merger Failed

firstly my module build.gradle was like this:首先我的模块 build.gradle 是这样的:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.depressionanalysis"
        minSdkVersion 27
        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'
        }
    }
    productFlavors {
    }
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.firebase:firebase-firestore:17.1.0'
    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'
    implementation 'com.google.guava:guava:27.0.1-jre'
    implementation 'com.loopj.android:android-async-http:1.4.9'
}

which resulted in this warning: " The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended. " which resulted in this warning: " The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended. "

so i tried to add it in (and updated firestore as well)所以我尝试将其添加(并更新了firestore)

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.depressionanalysis"
        minSdkVersion 27
        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'
        }
    }
    productFlavors {
    }
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.firebase:firebase-firestore:21.4.2'
    implementation 'com.google.firebase:firebase-core:17.3.0'
    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'
    implementation 'com.google.guava:guava:27.0.1-jre'
    implementation 'com.loopj.android:android-async-http:1.4.9'
}

but got this error但收到此错误

" 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.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:10:5-46:19 to override. "

How do i fix it?我如何解决它? I've tried out a few solutions found here but to no avail.. Thanks in advance!我已经尝试了一些在这里找到的解决方案,但无济于事..提前致谢! Let me know if any other codes are needed!!让我知道是否需要任何其他代码!

You are using the latest version of firestore:您正在使用最新版本的 firestore:

com.google.firebase:firebase-firestore:21.4.2

and on June 2019, firebase started supporting androidX, therefore you need to migrate to androidX to be able to use firebase.并且在 2019 年 6 月,firebase 开始支持 androidX,因此您需要迁移到 androidX 才能使用 firebase。

The updated libraries will not work unless you make the following changes in your app:除非您在应用程序中进行以下更改,否则更新的库将不起作用:

  1. Upgrade com.android.tools.build:gradle to v3.2.1 or later.将 com.android.tools.build:gradle 升级到 v3.2.1 或更高版本。
  2. Upgrade compileSdkVersion to 28 or later.将 compileSdkVersion 升级到 28 或更高版本。
  3. Update your app to use Jetpack (AndroidX);更新您的应用以使用 Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.按照迁移到 AndroidX 中的说明进行操作。

Check how to migrate:查看迁移方式:

https://developer.android.com/jetpack/androidx/migrate https://developer.android.com/jetpack/androidx/migrate

Actually, for the same library, you have different versions via different sources, You have support library as well as their AndroidX version, For Now, you can try solving it using实际上,对于同一个库,你有不同来源的不同版本,你有支持库以及他们的 AndroidX 版本,现在,你可以尝试使用解决它

tools:replace="android:appComponentFactory

attribute as given in your error itself.错误本身中给出的属性。

Go to your AndroidManifest file add this attribute like below. Go 到您的 AndroidManifest 文件中添加此属性,如下所示。

<application
        android:name=".AbcApplication"      
        tools:replace="android:appComponentFactory
        >
</application>

for me i have add two attribute in AndroidMenifest.xml对我来说,我在 AndroidMenifest.xml 中添加了两个属性

    tools:replace="android:appComponentFactory"
    android:appComponentFactory="androidx"

full tag it like:完整的标签就像:

 <application
    android:allowBackup="true"
    android:icon="@mipmap/logo"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/logo"
    android:theme="@style/AppTheme"
    tools:replace="android:appComponentFactory"
    android:appComponentFactory="androidx"
    tools:ignore="GoogleAppIndexingWarning">

and your project should be in Androidx.并且您的项目应该在 Androidx 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM