【问题标题】:android architecture components with instant app带有即时应用程序的 android 架构组件
【发布时间】:2017-11-09 09:51:53
【问题描述】:

我想让我的应用为免安装应用做好准备。 我创建了一个应用程序模块、基本模块和一个功能模块。 如果我以这种配置运行我的项目,一切都会很好。

当我在基本模块 Gradle 文件中实现以下行时。

annotationProcessor "android.arch.lifecycle:compiler:1.0.0"
api "android.arch.lifecycle:extensions:1.0.0"

Gradle 构建成功,但我失去了默认活动并且无法运行该项目。默认活动在我的基本模块清单中。

如果我通过实现更改扩展行。

implementation "android.arch.lifecycle:extensions:1.0.0"

出现以下错误:

错误:任务 ':app:preDebugBuild' 执行失败。

Android 依赖 'android.arch.lifecycle:runtime' 对于编译 (1.0.0) 和运行时 (1.0.3) 类路径有不同的版本。您应该通过 DependencyResolution 手动设置相同的版本

有谁知道问题出在哪里?

【问题讨论】:

  • 您使用的是 v26.1.0 或更高版本的支持库吗?如果是这样,那现在包括 Lifecycles (developer.android.com/topic/libraries/support-library/…) ....因此,您可能会遇到传递依赖与您所包含的版本之间的不匹配,
  • 愚蠢的问题,但是失去 DefaultActivity 意味着什么? api 是基本模块中将由功能模块使用的库的更好选择。您也可以尝试运行gradle -q :<base module name>:dependencies --configuration implementation 来查看重复库发生在哪里
  • 我遇到了同样的问题,我最终删除了生命周期依赖项。
  • 问题在于对库有两个依赖项。我使用了 26.1.0 支持库并包含了生命周期,也包括了造成错误的原因。 @John O'Reilly 对于“DefaultActivity”,我的意思是您使用主要意图过滤器的活动。通过使用 api 而不是实现,我可能包含了比需要更多的库,并且运行配置无法再找到主要意图过滤器

标签: android module android-gradle-plugin android-instant-apps android-architecture-components


【解决方案1】:

使用支持库 26.1.0 或更高版本时,生命周期功能包含在其中。通过删除以下库行

annotationProcessor "android.arch.lifecycle:compiler:1.0.0"
api "android.arch.lifecycle:extensions:1.0.0"

并且只使用 :

 implementation 'com.android.support:appcompat-v7:26.1.0'

一切都恢复正常了。

Official document reference

【讨论】:

  • 另一个救星。我很高兴你被标记为这个问题的正确答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-14
  • 2012-05-01
  • 1970-01-01
  • 2012-02-18
  • 1970-01-01
相关资源
最近更新 更多