相关疑难解决方法(0)

Gradle - 手动下载依赖项,锁定版本和更新依赖项

问题.

Gradle依赖管理如下:

  • 没有简单的方法来检查依赖项更新的可用性(仅使用某些第三方插件,如ben-manes/gradle-versions-plugin)和下载更新替换旧版本;
  • 依赖项工件从远程存储库下载,然后存储在gradle缓存中并在后续构建中重用; 但是,成功编译项目不能依赖于连接到Internet,远程存储库的可用性以及这些存储库中特定版本的依赖项的存在.

目标.

  • 在VCS中下载并存储所有依赖项工件;
  • 手动检查这些依赖项的更新并下载它们.

java android dependency-management gradle

6
推荐指数
1
解决办法
3467
查看次数

在应用程序中找不到传递库依赖项

假设我有一个库模块,其中包含一些第三方库,例如 OkHttp。当我在我的应用程序中包含这个库时,我无法使用这些第三方库。我阅读了以下文章第 1 条第 2 条 并尝试了
1. compile project(':library-name')
{将库的 .aar 文件作为模块导入到 myproject 中之后}
2. 我将 .aar 文件包含在 libs 文件夹中并添加了以下依赖项

build.gradle(项目级别)

allprojects {
repositories {
    flatDir {
        dirs 'libs'
    }
}
}
Run Code Online (Sandbox Code Playgroud)

build.gradle(应用程序级别)

compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.myapp.package:library-name:1.0.0@aar'){
transitive=true
}
Run Code Online (Sandbox Code Playgroud)

3. 与2类似,但在
build.gradle中(应用程序级别)

compile fileTree(dir: 'libs', include: ['*.jar'])
compile (name:'library-name', ext:'aar'){
transitive=true
}
Run Code Online (Sandbox Code Playgroud)

但是,我仍然无法使用我的库中存在的传递库。我收到以下异常。

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/MediaType;
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗

编辑:
以下是我的库的 build.gradle

compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'

compile 'org.apache.httpcomponents:httpcore:4.4.4' …
Run Code Online (Sandbox Code Playgroud)

android gradle android-library android-studio android-gradle-plugin

1
推荐指数
1
解决办法
2131
查看次数