我有一个带有这个gradle构建脚本的android库项目:

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group 'com.test'
version '0.0.1'

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.test.sdk"
        minSdkVersion 14
        targetSdkVersion 19
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    lintOptions {
        abortOnError false
    }
}


dependencies {
    compile 'com.android.support:support-v4:21.0.2'
    compile 'com.google.code.gson:gson:2.3'
}

然后我有一个使用此构建脚本的应用程序:

apply plugin:'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:19'
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.test.app"
        minSdkVersion 14
        targetSdkVersion 19
        multiDexEnabled true
    }


    signingConfigs {
        release {
            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.release
        }
        debug {
            minifyEnabled false
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    compile ('com.test:sdk:0.0.1@aar') {
        transitive = true
    }
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:support-v4:21.0.2'
    compile 'com.google.android.gms:play-services:6.1.71'
}

我正在使用maven插件将我的库sdk发布到我当地的maven存储库:https://github.com/dcendents/android-maven-plugin

我在我的库项目上运行安装任务,它成功发布库.aar和pom文件 . pom文件将gson列为编译依赖项 .

生成的POM文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>sdk</artifactId>
  <version>0.0.1</version>
  <packaging>aar</packaging>
  <dependencies>
   <dependency>
     <groupId>com.google.code.gson</groupId>
     <artifactId>gson</artifactId>
     <version>2.3</version>
     <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

当我运行我的应用程序时,我得到了gson类的java.lang.NoClassDefFoundError . 通过apk浏览我没有看到gson dep完全拉入 .

我已经读过将扩展名“@aar”放在依赖集上传递给false并且不会传递传递依赖性 . 所以我添加了transitive = true . 我也试过没有'@aar'扩展,我遇到了同样的问题 .

我正在使用Android Studio RC1 w / gradle插件版本0.14.4 .