0

我有一个 gradle 项目,其中包含我的app,然后是我的lib. 我在尝试构建我的app模块时看到错误,因为它找不到lib模块所需的依赖项。

* What went wrong:
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find com.google.android.gms:play-services-location:11.4.2.
Searched in the following locations:
  file:/Users/me/Library/Android/sdk/extras/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.pom
  file:/Users/me/Library/Android/sdk/extras/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.jar
  file:/Users/me/Library/Android/sdk/extras/google/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.pom
  file:/Users/me/Library/Android/sdk/extras/google/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.jar
  file:/Users/me/Library/Android/sdk/extras/android/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.pom
  file:/Users/me/Library/Android/sdk/extras/android/m2repository/com/google/android/gms/play-services-location/11.4.2/play-services-location-11.4.2.jar

Required by:
  project :app > project :lib

lib此错误对于所有模块的依赖项都是重复的。我目前lib/build.gradle在存储库下定义了这些依赖项。

repositories {
    jcenter()
    google()
    maven { url "https://jitpack.io" }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.android.gms:play-services-location:11.4.2'
    implementation 'com.google.android.gms:play-services-gcm:11.4.2'
    // ...
}
// ...

当我运行时,./gradlew lib:assembleDebug我收到了 lib 已构建的成功消息。所以我知道存储库/依赖项定义对于该模块是正确的。不幸的是,构建应用程序并没有得到预期的结果:

./gradlew assembleDebug --rerun-tasks --console plain
:buildSrc:compileJava NO-SOURCE
:buildSrc:compileGroovy
:buildSrc:processResources NO-SOURCE
:buildSrc:classes
:buildSrc:jar
:buildSrc:assemble
:buildSrc:compileTestJava NO-SOURCE
:buildSrc:compileTestGroovy NO-SOURCE
:buildSrc:processTestResources NO-SOURCE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test NO-SOURCE
:buildSrc:check UP-TO-DATE
:buildSrc:build
The CompileOptions.bootClasspath property has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the CompileOptions.bootstrapClasspath property instead.
:app:customTask
:app:preBuild
:lib:preBuild UP-TO-DATE
:lib:preDebugBuild UP-TO-DATE
:lib:checkDebugManifest
:lib:processDebugManifest
:app:preDebugBuild FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find com.google.android.gms:play-services-location:11.4.2.
// ... 

我在 preBuild 任务之前注入的应用程序模块中确实有一些任务。我不认为这会导致事情被抛弃,但我会提到它以防万一。

如果有人对实现一个子项目定义自己的存储库的多项目 gradle 应用程序有任何建议,我将非常感激。

4

0 回答 0