android studio submodule,解决迁移至 Android Build Plugin 3.x 提示找不到 submodule 依赖的问题...

解决迁移至 Android Build Plugin 3.x 提示找不到 submodule 依赖的问题

Android Studio 2.3 升级到 Android Studio 3.0 Gradle builde 报错

Unable to resolve dependency for ':app@xxPreview/compileClasspath': Could not resolve project :library.

Could not resolve project :library.

Required by: project :app

> Unable to find a matching configuration of project :library:

- Configuration 'debugApiElements':

- Required com.android.build.api.attributes.BuildTypeAttr 'preview' and found incompatible value 'debug'.

- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.

- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but was't required.

- Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.

- Required versionCode 'xiaomi' but no value provided.

- Configuration 'debugRuntimeElements':

- Required com.android.build.api.attributes.BuildTypeAttr 'preview' and found incompatible value 'debug'.

- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.

- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.

- Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.

- Required versionCode 'xiaomi' but no value provided.

- Configuration 'releaseApiElements':

- Required com.android.build.api.attributes.BuildTypeAttr 'preview' and found incompatible value 'release'.

- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.

- Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.

- Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.

- Required versionCode 'xiaomi' but no value provided.

- Configuration 'releaseRuntimeElements':

- Required com.android.build.api.attributes.BuildTypeAttr 'preview' and found incompatible value 'release'.

- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.

- Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.

- Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.

- Required versionCode 'xiaomi' but no value provided.

背景:build.gradle(module:library):

apply plugin:'com.android.library'

android{

buildTypes{

release{

...

}

debug{

...

}

}

}

build.gradle(module:app):

apply plugin:'com.android.application'

// 或

//apply plugin: 'com.android.library'

android{

buildTypes{

release{

...

}

preview{

...

}

debug{

...

}

}

}

dependencies{

compile project(':library')

}

builde.gradle(project:root):

from

dependencies{

classpath'com.android.tools.build:gradle:2.3.3'

}

to

dependencies{

classpath'com.android.tools.build:gradle:3.0.0'

}

原因: app 中 buildTypes 集合不是 library 的 buildTypes 集合子集, 即 app 中 buildType 属性 preview 在依赖的 library 中找不到.

解决:

1, 在所有 library 中添加 buildType 属性 preview. 如下:build.gradle(module:library):

apply plugin:'com.android.library'

android{

buildTypes{

release{

...

}

// 新增

preview{

...

}

debug{

...

}

}

}

2, 将 Gradle API 回滚到能够适配的版本. 如下:builde.gradle(project:root):

dependencies{

// 从 3.0.0 回滚到 2.3.3

classpath'com.android.tools.build:gradle:2.3.3'

}

方法 1 和方法 2 任选一种Bestfix:

build.gradle(module:app):

apply plugin:'com.android.application'

// 或

//apply plugin: 'com.android.library'

android{

buildTypes{

release{

...

}

preview{

...

// 关键代码, release, debug 为 library 中已有 buildType

matchingFallbacks=['release','debug']

}

debug{

...

}

}

}

dependencies{

compile project(':library')

}

来源: https://juejin.im/entry/5b17bce0e51d45067b059980

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值