即时应用程序的Firebase支持库依赖项冲突 [英] Firebase support library dependency conflict for instant apps

本文介绍了即时应用程序的Firebase支持库依赖项冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将即时应用程序实施到使用Firebase数据库的项目中.我的目标是 SDK版本27 ,因此支持库位于版本 27.0.2 .

I'm trying to implement instant apps into a project that uses Firebase database. I'm targeting SDK version 27, so the support libraries are on version 27.0.2.

Firebase数据库版本为 11.8.0 ,gms版本为 3.1.0 .尝试同步时,出现以下错误:

Firebase database version is 11.8.0 and gms version is 3.1.0. When I try to sync, I get the following error:

Android dependency 'com.android.support:support-v4' has different 
version for the compile (25.2.0) and runtime (27.0.2) classpath. You 
should manually set the same version via DependencyResolution

我可以通过在即时应用程序之前显式添加以下依赖项来解决此问题

I was able to get around the issue by adding the following dependencies explicitly before the instant apps

implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:support-media-compat:27.0.2'

但是对于即时应用程序,即使我将它们放在功能模块(基于应用程序)中,当我尝试构建实际应用程序(com.android.application)时,我也会再次遇到相同的错误.

But with the instant apps, even if I have them in the feature module (app-base), when I try to build the actual app (com.android.application), I again get the same error.

我可以通过将那些冲突的依赖项移至应用程序模块gradle文件中来再次解决该问题,在这种情况下,同步成功,但是接下来我遇到了另一个问题,即清单合并,这阻止了应用程序查找启动器活动:

I can again move around the issue by moving those conflicting dependencies into application module gradle file, in which case the sync succeeds, but then I'm facing another problem, this time with manifest merging, which prevents the app from finding the launcher activity:

来自AndroidManifest.xml:10:13-72的

Attribute provider#com.google.firebase.provider.FirebaseInitProvider@authorities value =(com.iamkaan.packagename.firebaseinitprovider)也出现在AndroidManifest.xml:33:350- 423 value =(com.iamkaan.packagename.base.firebaseinitprovider).建议:在AndroidManifest.xml:8:9-12:39的元素上添加'tools:replace ="android:authorities"'以进行覆盖.应用程序主清单(此文件),第9行

Attribute provider#com.google.firebase.provider.FirebaseInitProvider@authorities value=(com.iamkaan.packagename.firebaseinitprovider) from AndroidManifest.xml:10:13-72 is also present at AndroidManifest.xml:33:350-423 value=(com.iamkaan.packagename.base.firebaseinitprovider). Suggestion: add 'tools:replace="android:authorities"' to element at AndroidManifest.xml:8:9-12:39 to override. app main manifest (this file), line 9

最后一个问题与firebase-core依赖性相关,因为当我从以下位置更改我的应用程序gradle依赖性

This last issue is somehow related to firebase-core dependency because when I changed my app gradle dependencies from

implementation project(':app-base')

implementation (project(':app-base')) {
    exclude group: 'com.google.firebase', module:'firebase-core'
}

我能够运行该应用程序.但是这次,我开始在运行时收到以下错误(我第一次调用FirebaseDatabase.getInstance())

I was able to run the app. But this time, I started getting the following error on runtime (the first time I call FirebaseDatabase.getInstance())

Default FirebaseApp is not initialized in this process com.iamkaan.packagename. Make sure to call FirebaseApp.initializeApp(Context) first

它确实没有被调用,但是直到即时应用程序实现后,它还是无法正常工作.无论如何,我在第一个FirebaseDatabase调用之前将调用添加到了各个位置,没有任何帮助.

It was indeed not called but was working without anyway until instant app implementation. Anyway, I added the call to various places before the first FirebaseDatabase call, nothing helped.

包裹名称

  • 应用清单:com.iamkaan.packagename
  • 应用程序gradle applicationId:com.iamkaan.packagename
  • 基于应用的清单:com.iamkaan.packagename.base
  • 基于应用程序的gradle文件没有applicationId
  • app manifest: com.iamkaan.packagename
  • app gradle applicationId: com.iamkaan.packagename
  • app-base manifest: com.iamkaan.packagename.base
  • app-base gradle file doesn't have an applicationId

推荐答案

我遇到了类似的情况,这是由依赖项包含的支持库引起的.请务必注意,几乎所有的Google/Android支持库(CardView,RecyclerView等)都包含最新的v4和v7支持库.因此,这通常会引起冲突.

I ran into something similar and it is caused by support libraries being included by dependencies. It's important to note that almost all of Google/Android support libraries (CardView, RecyclerView etc) includes the latest v4 and v7 support libraries. So that usually causes conflicts.

您需要做的是:

  1. 在主应用程序中添加基本模块时不要排除任何内容,即仅使用implementation project(':app-base')
  2. 使用api代替implementation以获得基本模块build.gradle中包含的支持库,即api 'com.android.support:support-v4:27.0.2'
  3. 确保您在基本模块中添加的任何库都不得再次添加到主应用程序的build.gradle文件中
  4. 最重要的是:对于主应用程序和基本模块的build.gradle文件,请排除支持库FOR EACH项(请参见下面的示例)
  1. Don't exclude anything while adding Base Module in main application, i.e. keep using implementation project(':app-base') only
  2. Use api instead of implementation for support libs included inside Base Module's build.gradle i.e. api 'com.android.support:support-v4:27.0.2'
  3. Make sure whichever library you've added in Base Module must NOT be added again in main app's build.gradle file
  4. MOST IMPORTANT: For both main app and base module's build.gradle file, exclude support libs FOR EACH item (see example below)

 

api('com.android.support:support-media-compat:27.0.2') {
    exclude group: 'com.android.support'
}
api('com.android.support:support-v7:27.0.2') {
    exclude group: 'com.android.support'
}

我也建议您不要使用com.android.support:support-v7:27.0.2,而只使用您需要的支持库中的特定项目.有关如何仅添加特定项目的信息,请参见支持库软件包.来自支持库.

I will also recommend not using com.android.support:support-v7:27.0.2 instead use only the specific items from support libs that you need. See Support Library Packages on how can you add only specific items from support libs.

这篇关于即时应用程序的Firebase支持库依赖项冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆