Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将firebase添加到android studio时gradle未同步_Android_Firebase_Gradle_Android Manifest - Fatal编程技术网

将firebase添加到android studio时gradle未同步

将firebase添加到android studio时gradle未同步,android,firebase,gradle,android-manifest,Android,Firebase,Gradle,Android Manifest,因此,我正试图按照Firebase网站的说明将Firebase SDK添加到我的Android Studio应用程序中(见图) 将classpath'com.google.gms:google services:4.3.2'行添加到项目级gradle很好。我可以同步gradle文件 但是,在应用程序级别的gradle文件中添加一行apply plugin:'com.google.gms.google services',会破坏我的应用程序。 我得到以下错误: 错误:清单合并失败:属性applic

因此,我正试图按照Firebase网站的说明将Firebase SDK添加到我的Android Studio应用程序中(见图)

classpath'com.google.gms:google services:4.3.2'
行添加到项目级gradle很好。我可以同步gradle文件

但是,在应用程序级别的gradle文件中添加一行
apply plugin:'com.google.gms.google services'
,会破坏我的应用程序。 我得到以下错误:

错误:清单合并失败:属性application@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 value=(androidx.core.app.CoreComponentFactory)中也存在。 建议:在AndroidManifest.xml:5:5-21:19处的元素中添加“tools:replace=“android:appComponentFactory””以覆盖

所以我去做这个建议。我在AndroidManifest.xml文件中添加了
tools:replace=“android:appComponentFactory”
to>application<元素。这就给了我一个名称空间“tools”未绑定的错误。我按Alt+Enter来修复添加的
xmlns:tools=”http://schemas.android.com/tools“
到我的文件顶部

请重试同步。现在我得到一个类似的错误:错误:清单合并失败,出现多个错误,请参阅日志。这就是我迷路的地方。我不确定在谷歌上搜索什么。搜索这个特定错误会得到很多与我的问题无关的答案。这个领域对我来说是全新的

除此之外,在我的build.grade(应用程序级)文件中添加了前面提到的3行代码后,行
implementation'com.android.support:appcompat-v7:28.0.0'
将带红色下划线

我注意到还有其他与此相关的问题,但似乎都没有确切的答案。所以我冒着可能是回购的风险

编辑:: 这是我的梯度依赖

项目Gradle

dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath 'com.google.gms:google-services:4.3.2'
    }
dependencies {
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
应用程序渐变

dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath 'com.google.gms:google-services:4.3.2'
    }
dependencies {
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
编辑2::

好的,在迁移到androidx之后,我更新了所有导入语句以使用androidx。它仍然不断地说合并失败了,出现了多个错误。我不得不删除之前建议添加的行
tools:replace=“android:appComponentFactory”
。最后,我能够同步并运行我的应用程序!除了现在,应用程序只是立即启动和停止。我想这就是进步。有什么想法吗

编辑3:: 我终于成功了。最后一个问题是运行时错误“错误膨胀类androidx.constraintlayout.constraintlayout”。这是因为我所有的xml文件都有一行
androidx.constraintlayout.constraintlayout
。将其替换为行
androidx.constraintlayout.widget.constraintlayout
,现在一切都很好。渐变同步,应用加载,不会崩溃,一切正常

任何帮助都将不胜感激。 Thx提前

弗拉德


在应用程序标记中添加工具:replace=“android:appComponentFactory”


问题是您的应用程序正在使用android。当您添加到项目中的Firebase sdk使用AndroidX时,支持库

注意:AndroidX和android.support不兼容

因此,您必须将项目迁移到AndroidX或使用Firebase的支持版本

  • 迁移代码以使用AndroidX

    • Refactor
      选项中选择迁移到Androidx
    • 同步项目,你应该会没事的
  • 使用非Androidx firebase

    • 查找库迁移到AndroidX之前的最后一个版本
      (例如
      Firebase messaging
      19使用AndroidX,而较低版本不使用)
  • TL;DR


    迁移到
    AndroidX
    或使用Firebase的较低版本库。

    如上所述,我已经尝试过了。这仍然表示“清单合并失败,出现多个错误”显示您的Gradle依赖项。同样的错误。清单合并失败,出现多个错误。查看您迁移到androidX的日志。因此,将所有依赖项升级到AndroidX。不支持android。同时启用jetifier。我用我现在的位置更新了原始问题。gradle同步正在工作,但应用程序已关闭。有什么想法吗?没关系,我终于成功了。阅读编辑3。我接受你的解决方案作为这篇文章的答案,因为它让我走得最远。谢谢,哎呀。很抱歉反应太晚。根据EDIT3,看起来迁移没有完全完成,有些包没有更改。