gpt4 book ai didi

java - 更新到 Android Studio 3.2.1 后无法解决模块依赖关系

转载 作者:行者123 更新时间:2023-12-02 04:19:08 24 4
gpt4 key购买 nike

升级到 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')

该库终于在左侧列出了!

但是,新的问题出现了。无法解析模块中定义的类/方法/字段等。甚至不在模块本身的类中,尽管它们甚至位于同一目录(包)中......清理和重建没有帮助。奇怪的是,构建成功了,我显然甚至可以在我的设备上安装该应用程序并让它毫无异常(exception)地运行......!?那么这可能只是一个 IDE 错误吗?

更新3

我删除了.gradle和.idea目录并重新启动了AS。现在一切都很好 B-)

最佳答案

尝试构建一次 androidlib_abc。你能在侧面菜单中看到这个库吗?可能是这个特定的库没有正确导入

关于java - 更新到 Android Studio 3.2.1 后无法解决模块依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53208434/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com