【发布时间】:2018-11-08 13:08:31
【问题描述】:
升级到 AS 3.2.1 后,我收到此 gradle 同步错误:
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :androidlib_abc.
我的应用程序 gradle.build:
apply plugin: 'com.android.application'
allprojects {
repositories {
// The order in which you list these repositories matter.
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "de.gpx.android.rtk"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile project(path: ':androidlib_abc')
}
我的 androidlib_abc gradle.build 文件:
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
错误消息中的“打开文件”链接指向应用程序 gradle.build 文件。当我删除线时
compile project(path: ':androidlib_abc')
然后我可以同步成绩项目,但我无法编译和使用该库中的任何包(无法解析类等)
我希望我没有进行更新...(“永远不要更改正在运行的系统”-_-)
任何想法如何解决?
更新:
我从项目中删除了模块,然后重新导入了它。然后一切正常!但是:模块目录被复制到我的项目目录中(通常的行为)。但是,我需要将模块目录提高一级,与项目目录位于同一目录中。这样,我可以与不同的项目共享模块,而无需重复和同步工作,这为我节省了大量时间(实际上我不能同时处理多个项目)。
我曾经使用过这个settings.gradle文件:
include ':app', ':androidlib_abc'
project(':androidlib_abc').projectDir = new File(rootProject.projectDir, '../androidlib_abc ')
在 AS 3.2.1 之前完美运行
现在,在我再次成功导入模块并将模块目录上移一级并再次将 settings.gradle 文件更改为此后,我再次收到无法解决依赖关系的错误:'-(
更新 2:
使用不带参数 rootProject.projectDir 的另一个构造函数允许我进行 gradle 同步。
include ':app', ':androidlib_abc'
project(':androidlib_abc').projectDir = new File('../androidlib_abc')
图书馆终于在左侧列出来了!
但是,出现了一个新问题。无法解析模块中定义的任何类/方法/字段等。甚至在模块本身的类中也没有,尽管它们甚至在同一个目录(包)中......清理和重建没有帮助。奇怪的是,构建成功了,显然我什至可以在我的设备上安装应用程序并让它毫无例外地运行......!?那么这可能只是一个 IDE 错误吗?
UPDATE3
我删除了 .gradle 和 .idea 目录并重新启动了 AS。现在一切都很好 B-)
【问题讨论】:
-
这听起来很愚蠢,删除 .gradle 和 .idea 文件夹就可以了。我不敢相信他们 (intellij) 没有照顾好兼容性。
标签: java api android-studio gradle intellij-idea