gpt4 book ai didi

android - 模块 : failed to resolve 中的 Gradle aar 库依赖项

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:32:38 24 4
gpt4 key购买 nike

我是 gradle 的新手,我遇到了依赖性问题。我有以下项目结构:

-MyApp
-MyAppLibrary
-MyAppPro
-MyAppFree
-ThirdPartyLibraryWrapper
--libs\ThirdPartyLibrary.aar

MyAppProMyAppFree 都依赖于MyAppLibrary,后者又依赖于ThirdPartyLibraryWrapper。顾名思义,ThirdPartyLibraryWrapper 是外部库的包装器,即 ThirdPartyLibrary.aar

这是我的配置:

build.gradle MyAppPro

apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "com.example"
minSdkVersion 8
targetSdkVersion 22
}

buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}

dependencies {
compile project(':MyAppLibrary')
}

build.gradle MyAppLibrary

apply plugin: 'com.android.library'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 8
targetSdkVersion 22
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}

dependencies {
compile project(':ThirdPartyLibraryWrapper')
compile 'com.squareup.picasso:picasso:2.5.2'
}

build.gradle ThirdPartyLibraryWrapper

apply plugin: 'com.android.library'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 8
targetSdkVersion 22
}

buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}

dependencies {
compile(name: 'ThirdPartyLibrary-0.1.0', ext: 'aar')
compile "com.android.support:support-v4:22.0.0"
compile fileTree(dir: 'libs', include: 'volley.jar')
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'

}

当 gradle sync 完成时,我得到了这个错误:

MyApp/MyAppFre/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppLibrary/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppPro/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0

谁能帮我找出问题出在哪里?

最佳答案

其他项目发现 :ThirdPartyLibraryWrapper 项目依赖于名为 ThirdPartyLibrary-0.1.0:aar 的 Artifact 。 Java(和 Android)库不会将它们自己的依赖项 bundle 在一起——相反,它们只是发布它们的依赖项列表。然后,使用项目不仅负责加载它直接依赖的库,还负责加载该库 依赖的所有库。

这样做的最终效果是 :MyAppFree 加载到 :ThirdPartyLibraryWrapper 中,然后看到 :ThirdPartyLibraryWrapper 依赖于 ThirdPartyLibrary -0.1.0:aar 因此也尝试加载它。然而,:MyAppFree 不知道 ThirdPartyLibrary-0.1.0:aar 在哪里..所以它失败了。

解决方案是在所有其他项目中放置类似的 repositories block 。试试这个:

repositories {
flatDir {
dirs project(':ThirdPartyLibraryWrapper').file('libs')
}
}

使用 project(...).file(...) 方法将使您不必对路径进行硬编码,而是使用 Gradle DSL 通过查找来解析文件系统路径项目并让它动态地进行解析。

关于android - 模块 : failed to resolve 中的 Gradle aar 库依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31558200/

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