Gradle配置不再适用于Android Studio 3(测试版)

问题描述 投票:2回答:1

我的Android Studio项目有一个像这样的目录结构:

project
|-- build.gradle
|-- settings.gradle
|
|-- app
|    |-- src
|    |-- build.gradle
|    +-- settings.gradle
|
+-- submodule
     |-- build.gradle
     |-- settings.gradle
     +-- library
          |-- src
          |-- build.gradle
          +-- settings.gradle

project/submodule是一个git子模块,直接引用另一个Android Studio项目的git存储库。它的settings.gradle只是include ':library'

以前工作的配置

project/settings.gradleinclude ':submodule/library'project/app/build.gradlecompile project(':submodule/library')线。

这一切在Android Studio 3之前都运行良好,但现在Android Studio抱怨它无法通过该名称找到模块:

Error:Unable to find module with Gradle path ':submodule/library' (needed by module 'Accession'.)

(使用gradle在命令行中运行构建似乎工作正常,因此它似乎只是Android Studio不喜欢的东西。)

在线查看似乎指的是:submodule/library可能只是巧合,因为gradle配置中指定的项目名称被逐字地假定为与其根的相对路径相同。

我有两种可能的解决方案:

可能的解决方案1

:submodule/library:submodule:library中用build.gradle替换settings.gradle。这似乎有效,但我最好的猜测是它包括gradle项目:submodule及其子项目。更重要的是,我不确定这个:x:y符号实际上代表什么。

可能的解决方案2

include ':submodule/library'替换

include ':library'
project(':library').projectDir = file('submodule/library')

settings.gradle并用compile project(':submodule/library')中的compile project(':library')取代build.gradle

我怀疑这可能是“正确的事情”。

有人可以告诉我这三个gradle(原始配置和两个可能的修复)中的每一个究竟发生了什么,哪些(如果有的话)应该工作,哪个是“最佳实践”?

更新(澄清)

我所描述的内容包括我的旧Gradle和Android Gradle插件版本配置(Gradle 3.3,Android Gradle Plugin 2.3.3)以及更新后(Gradle 4.1,Android Gradle Plugin 3.0.0 beta)。

android gradle android-studio-3.0
1个回答
0
投票

他们在新的gardle版本中改变了很多东西,我的构建脚本也不再适用了。但是这里有一个关于如何迁移构建脚本以使用较新版本的良好文档。

例如,这部分文档应该适合您:

您应该按如下方式配置依赖项:

dependencies {
// This is the old method and no longer works for local
// library modules:
// debugCompile project(path: ':foo', configuration: 'debug')
// releaseCompile project(path: ':foo', configuration: 'release')

// Instead, simply use the following to take advantage of
// variant-aware dependency resolution. You can learn more about
// the 'implementation' configuration in the section about
// new dependency configurations.
implementation project(':foo')

// You can, however, keep using variant-specific configurations when
// targeting external dependencies. The following line adds 'app-magic'
// as a dependency to only the 'debug' version of your module.

debugImplementation 'com.example.android:app-magic:12.3'

}

这里是完整文档的链接,希望它能帮助你喜欢它。

https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

© www.soinside.com 2019 - 2024. All rights reserved.