开发者社区> 问答> 正文

Android Studio Firebase集成出现错误

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

我继续并遵循了google的文档,在build.gradle文件中包含了某些行

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

在应用程序/ 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
}

问题来源:Stack Overflow

展开
收起
montos 2020-03-21 20:32:11 1435 0
1 条回答
写回答
取消 提交回答
  • 如果要使用Google Analytics(分析)17.2.2版,则需要升级androidx。从文档:

    除非您在应用中进行以下更改,否则更新的库将无法工作:

    将com.android.tools.build:gradle升级到v3.2.1或更高版本。 将compileSdkVersion升级到28或更高版本。 更新您的应用程序以使用Jetpack(AndroidX);按照迁移到AndroidX中的说明进行操作。 https://firebase.google.com/support/release-notes/android

    回答来源:Stack Overflow

    2020-03-21 20:33:21
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
阿里邮箱—安全高效集成 立即下载
集成智能接入网关APP:优化企业级移动办公网络 立即下载
云效助力企业集成安全到DevOps中 立即下载

相关实验场景

更多