android 具有免安装应用程序的架构组件

android architecture components with instant app

我想让我的应用程序为免安装应用程序做好准备。 我创建了一个应用程序模块、基本模块和一个功能模块。 如果我 运行 我的项目在此配置中一切正常。

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

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

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

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

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

发生以下错误:

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

Android dependency 'android.arch.lifecycle:runtime' has different version for the compile (1.0.0) and runtime (1.0.3) classpath. You should manually set the same version via DependencyResolution

有人知道问题出在哪里吗?

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

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