我有一个包含 1 个应用程序模块(MyApplication)和 1 个库模块(核心)的项目。
当我试图查看“gradlew MyApplication:dependencies”时,
我有一个错误
* What went wrong: A problem occurred evaluating project ':core'.
> Cannot change dependencies of configuration ':core:classpath' after it has been resolved.
在顶级目录中,我有 build.gradle :
...
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
maven {
url 'https://maven.fabric.io/public'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'io.fabric.tools:gradle:1.26.1'
}
}
...
我也设置了
org.gradle.configureondemand=true
在 MyApplication 目录中,我有 build.gradle 和典型的应用程序配置
apply plugin: "com.android.application"
...
在核心目录中,我有 build.gradle :
...
buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
...
请询问是否需要 gradle 文件中的其他信息。
很抱歉,它的项目对源代码和整个 gradle 文件正文的披露有限制。
最佳答案
终于我明白出了什么问题。
在顶级文件夹 build.gradle 中,我们已经定义了与 android 构建工具相关的内容:
buildscript {
repositories {
google()
maven {
url 'https://maven.fabric.io/public'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'io.fabric.tools:gradle:1.26.1'
}
}
所以我们需要从应用程序或库模块中删除这个定义:
apply plugin: "com.android.library"
apply plugin: "maven"
apply plugin: "maven-publish"
ext.getArtifactId = {
return "core"
}
if(project.hasProperty("PATH_SET_VERSION") == true){
apply from: project.property("PATH_SET_VERSION").toString()
}
repositories {
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
mavenLocal()
maven {
url "our local repositiry"
}
maven {
url "https://google.bintray.com/flexbox-layout"
}
}
buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1' // it's not needed here, so better to delete this dependencies {...} section
}
}
关于android - 解决后无法更改配置 ':core:classpath' 的依赖关系。 Gradle按需配置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57185950/