【问题标题】:Android studio firebase integration is giving an errorAndroid Studio Firebase 集成出错
【发布时间】:2020-06-28 05:48:36
【问题描述】:

我是 android studio 的新手,我正在尝试学习 firebase 并在我的虚拟应用程序中实现 google 登录。

我继续按照谷歌的文档在 build.gradle 文件中包含某些行

在我添加的项目/gradle classpath 'com.google.gms:google-services:4.3.3'

在 app/gradle 我检查了apply plugin: 'com.android.application'apply plugin: 'com.google.gms.google-services'

因为它已经存在,我补充说: implementation 'com.google.firebase:firebase-analytics:17.2.2'

我同步了我的项目,当我尝试运行应用程序时,我收到以下错误:

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:5:5-19:19 to override.

请告诉我我做错了什么? 我在 Windows 10 上使用 android studio

编辑:这是用户建议的我的清单 xml 文件

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

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

我的应用程序 gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.MyName.TestApp"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.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'
    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.firebase:firebase-analytics:17.2.3'
}

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

打包 gradle 文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath 'com.google.gms:google-services:4.3.3'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

【问题讨论】:

  • 您的问题出在您的 AndroidManifest.xml 中,错误提示在您的 Manifest 的应用程序标签中添加 tools:replace="android:appComponentFactory",这是因为重复尝试添加您的 Manifest,以便有人可以提供更好的帮助跨度>

标签: java android firebase android-studio firebase-authentication


【解决方案1】:

如果您想使用 Analytics 版本 17.2.2,那么您需要升级 androidx。来自文档:

除非您在应用中进行以下更改,否则更新后的库将不起作用:

  1. 将 com.android.tools.build:gradle 升级到 v3.2.1 或更高版本。
  2. 将 compileSdkVersion 升级到 28 或更高版本。
  3. 更新您的应用以使用 Jetpack (AndroidX);按照Migrating to AndroidX. 中的说明进行操作

https://firebase.google.com/support/release-notes/android

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多