简体   繁体   English

Gradle / Maven-加载aar依赖项时出错

[英]Gradle/Maven - Error loading aar dependency

I'm publishing an aar file to an internal maven repo, but when I try to reference it like this: 我正在将aar文件发布到内部Maven存储库中,但是当我尝试像这样引用它时:

dependencies {
    compile 'com.example.android:example-api:0.3-SNAPSHOT'
}

I get the following error: 我收到以下错误:

A problem occurred configuring project ':sdk-sample'.
> Artifact 'com.example.android:example-api:0.3-SNAPSHOT:example-api.jar' not found.

Which is confusing to me since I do not have a jar file that I've uploaded, but an aar. 这让我感到困惑,因为我没有上传的jar文件,而是aar。

The POM file that gradle generated and uploaded looks like this: gradle生成并上传的POM文件如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.android</groupId>
    <artifactId>example-api</artifactId>
    <version>0.3-SNAPSHOT</version>
    <packaging>aar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.springframework.android</groupId>
            <artifactId>spring-android-rest-template</artifactId>
            <version>1.0.1.RELEASE</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp</groupId>
            <artifactId>okhttp</artifactId>
            <version>1.3.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.android</groupId>
            <artifactId>spring-android-core</artifactId>
            <version>1.0.1.RELEASE</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</project>

If I reference it like this: 如果我这样引用它:

dependencies {
    compile 'com.example.android:example-api:0.3-SNAPSHOT@aar'
}

Then it finds it successfully, but then the dependencies are not downloaded properly and i get a NoClassDefFoundError at runtime when I call the methods that use the dependencies. 然后,它会成功找到它,但是依赖项没有正确下载,当我调用使用依赖项的方法时,在运行时出现NoClassDefFoundError。

Any idea what's going on? 知道发生了什么吗?

The transitive property needs to be set to true on your dependency: 需要根据您的依赖性将可传递属性设置为true

compile ('com.example.android:example-api:0.3-SNAPSHOT@aar') { transitive = true }

It should probably be changed in Gradle to be true by default for aar dependencies (as it seems to be for jar ). 对于aar依赖项,可能应该在Gradle中将其默认更改为true (因为似乎对于jar )。

I had the exact same problem. 我有同样的问题。 Appending "@aar" to the dependency fixed it for me. 在依赖项上附加“ @aar”对我来说已经解决了。 Compiling and running without problems now. 现在编译并运行没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM