代码之家  ›  专栏  ›  技术社区  ›  dbotha

Gradle sync无法使用@aar注释自动解析Android库项目依赖关系

  •  0
  • dbotha  · 技术社区  · 10 年前

    我在这里创建了一个Android库项目: https://github.com/dbotha/Android-Photo-Picker

    照片选取器库项目本身有几个依赖项:

    // library build.gradle
    dependencies {
        compile 'com.android.support:appcompat-v7:22.2.1'
        compile 'com.squareup.picasso:picasso:2.5.2'
    }
    

    我已经在Maven Central上提供了这个库项目,以便可以将其作为依赖项轻松添加到应用程序中:

    // application build.gradle
    dependencies {
        compile 'ly.kite:photo-picker:1.1.2@aar'
    }
    

    但问题是,当我将其作为依赖项添加到新的Android应用程序项目时,它会崩溃,因为它无法从库项目中找到Picasso依赖项:

    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.picasso.Picasso" on path

    只有当我明确地将此依赖项添加到应用程序构建中时,才会出现这种情况。gradle做事很有效。

    我的库POM文件 dependencies 看起来正确: https://repo1.maven.org/maven2/ly/kite/photo-picker/1.1.2/photo-picker-1.1.2.pom

    所以我很好奇,如果应用程序将我的照片选取器库作为依赖项,是否总是需要显式地添加所有的照片选取库依赖项?

    1 回复  |  直到 10 年前
        1
  •  1
  •   Gabriele Mariotti    10 年前

    您正在使用 @aar 符号
    这意味着您只需要下载aar工件,而不需要依赖项。
    您可以检查 documentation :
    检查 1.4.1.2. Artifact only notation 部分:

    仅工件表示法创建了一个模块依赖关系,它只下载具有指定扩展名的工件文件。 忽略现有模块描述符 .

    使用 @aar公司 如果要下载依赖项,应添加 transitive=true .

    我希望省略“aar”应该会奏效。