【问题标题】:Error when adding Firebase Analytics to Android project with appcompat-v7:28.0.0使用 appcompat-v7:28.0.0 将 Firebase Analytics 添加到 Android 项目时出错
【发布时间】:2019-12-12 16:22:51
【问题描述】:

我有一个正在运行的 Android 项目,我正在尝试添加 Firebase 分析。一旦我将 implementation 'com.google.firebase:firebase-analytics:17.2.1' 添加到我的 graddle 中,它就会在帖子末尾给我错误。我尝试了我在其他帖子中找到的几个建议,例如在 appcompat 行的末尾添加“-alpha1”,但这是一个漏洞。我也做了错误提示的事情,但另一个兔子洞也是如此。 有人有其他建议吗? 应用插件:'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.track.live"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        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'
    implementation 'com.intuit.sdp:sdp-android:1.0.4'
    implementation 'com.intuit.ssp:ssp-android:1.0.4'
    implementation 'io.realm:realm-android:0.82.1'
    implementation 'me.jahirfiquitiva:FABsMenu:1.1.4'
    implementation 'com.google.maps.android:android-maps-utils:0.5'
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    testImplementation 'junit:junit:4.12'
    annotationProcessor 'io.realm:realm-android:0.82.1'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.google.firebase:firebase-analytics:17.2.1'
}
apply plugin: 'com.google.gms.google-services'

错误:清单合并失败:属性 应用程序@appComponentFactory 值=(android.support.v4.app.CoreComponentFactory)来自 [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 也出现在 [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 值=(androidx.core.app.CoreComponentFactory)。建议:加 'tools:replace="android:appComponentFactory"' 到元素 在 AndroidManifest.xml:14:5-52:19 处覆盖。

【问题讨论】:

  • 你添加了 firebase-core 库吗?
  • 不确定,我做了 Firebase 页面所说的一切。只是这最后一步给我带来了问题。
  • 也许您只是按照分析库的步骤进行操作,但在此之前您应该检查此firebase.google.com/docs/android/setup 并建议使用 androidX 而不是 com.android.support。谷歌它

标签: android firebase firebase-analytics


【解决方案1】:

您使用的是最新版本的 firebase 分析。 Firebase 于 2019 年 6 月迁移到 androidx,来自文档:

此版本是主要版本更新,包括重大更改。

在此版本中,库从 Android 支持库迁移到 Jetpack (AndroidX) 库。

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

将 com.android.tools.build:gradle 升级到 v3.2.1 或更高版本。

将 compileSdkVersion 升级到 28 或更高版本。

更新您的应用以使用 Jetpack (AndroidX);按照迁移到 AndroidX 中的说明进行操作。

以上内容适用于 Firebase 分析的 17.0.0 版。

您可以在这里找到更多信息:

https://firebase.google.com/support/release-notes/android#2019-06-17

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

【讨论】:

  • 谢谢,我会这样做的。随时通知您
  • 迁移到 AndroidX 解决了我的问题,而且非常简单!
【解决方案2】:

您在错误消息“建议:添加 'tools:replace="android:appComponentFactory"”中有一个建议 但我的意见和建议 - 转移到 androidX

【讨论】:

  • 是的,我尝试了这个建议,但它给了我越来越多的错误。
  • 所以,只要迁移到 AndroidX
  • Google 强制我们尽可能使用最新的库。
猜你喜欢
  • 1970-01-01
  • 2015-10-22
  • 1970-01-01
  • 1970-01-01
  • 2019-10-07
  • 1970-01-01
  • 1970-01-01
  • 2019-01-19
  • 1970-01-01
相关资源
最近更新 更多