Android Library - 为什么我的依赖项没有被下载?(格拉德尔/梅文)



我正试图找出如何分发Android库项目的一些beta用户,但我遇到了一些问题,当我分发它,并在一个样本项目中使用它。我正在尝试分发一个AAR文件。

我的示例项目中的所有内容都编译得很好,除了我得到一个错误:java.lang.NoClassDefFoundError: com.google.gson.Gson当我调用使用GSON的代码片段时。

我的构建。我的库的Gradle文件看起来像这样:

apply plugin: 'android-library'
apply plugin: 'maven'
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: exampleMavenUrl ) {
                authentication(userName: exampleMavenUser, password: exampleMavenPassword)
            }
            pom.groupId = 'com.example.android'
            pom.artifactId = 'example-api'
            pom.version = '0.1-SNAPSHOT'
            pom.packaging = 'aar'
        }
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"
    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 1
        versionName "0.1"
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.squareup.okhttp:okhttp:1.3.0'
    compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
    compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
}

当我运行:gradlew clean uploadArchives时,它成功地上传到我的快照nexus存储库。

在我的示例项目的build.gradle中引用它:

apply plugin: 'android'
repositories {
    mavenCentral()
    maven(){
        url "http://repos.example.com/nexus/content/repositories/android-snapshot"
    }
}
android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"
    defaultConfig {
        packageName "com.example.sample.app"
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:19.+'
    compile('com.example.android:example-api:0.1-SNAPSHOT')
}

下面是gradle生成和上传的pom文件,它位于如下位置:

http://repos.example.com/nexus/content/repositories/android snapshot/com/example/android/example - api/0.1 snapshot/example - api - 0.1 - 20140602.145158 - 1. - pom

位于aar文件旁边。

<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.1-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>

当我运行gradlew androidDependencies时,它只列出我在本地库文件夹中包含的那些。

:app:androidDependencies
debug
--- com.example.android:example-api:0.1-SNAPSHOT
     +--- LOCAL: android-logging.jar
     +--- LOCAL: Context-Core.jar
     --- LOCAL: Context-Location.jar
debugTest
No dependencies
release
--- com.example.android:example-api:0.1-SNAPSHOT
     +--- LOCAL: android-logging.jar
     +--- LOCAL: Context-Core.jar
     --- LOCAL: Context-Location.jar

我对出版库非常非常陌生,所以很有可能我在这里做了一些完全错误的事情。任何提示都会有帮助的。

编辑:这是gradle依赖项的输出(部分)——它显示了远程依赖项被列出,但我仍然得到运行时错误!

compile - Classpath for compiling the main sources.
+--- com.android.support:support-v4:19.+ -> 19.1.0
--- com.example.android:example-api:0.1-SNAPSHOT
     +--- org.springframework.android:spring-android-rest-template:1.0.1.RELEASE
     |    --- org.springframework.android:spring-android-core:1.0.1.RELEASE
     +--- com.google.code.gson:gson:2.2.4
     +--- com.squareup.okhttp:okhttp:1.3.0
     |    --- com.squareup.okhttp:okhttp-protocols:1.3.0
     --- org.springframework.android:spring-android-core:1.0.1.RELEASE

谢谢!

我不确定确切的原因,但是创建的新项目像这样工作没有问题:

compile('com.example.android:example-api:0.1-SNAPSHOT')

但是当使用它一个较老的项目时,我不得不像这样引用它,以便AAR被下载和引用。

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

最新更新