android-gradle-plugin - 创建具有多个 AAR/JAR 的 AAR

标签 android-gradle-plugin dependency-management aar

我看到了各种开发人员发布的问题(Android Studio combine 2 .aar into one 和其他人),但我还没有看到明确的答复使我能够创建一个包含 1 个或多个 AAR 或 JAR 的 AAR(我可以使用 JAR,因为我没有需要共享任何资源;只有类)。这是我的图书馆项目的 app.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 21
    }

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

dependencies {
    compile 'com.google.code.gson:gson:2.1'
    compile ('libs/eventbus.jar')
    compile project(':core-release')
    compile project(':midware-release')
}

同样,这个应用程序是一个库项目,它需要另外两个库项目('core-release'、'midware-release'),虽然我能够生成一个可以在我的应用程序中使用的 AAR 文件,但该应用程序无法找到依赖库项目的类,所以我不得不将两个库项目的 AAR 添加到我的应用程序中。

这是无法找到依赖项目类的 app.gradle 应用程序项目(不手动添加 JAR):
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.app.sample"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile files('libs/eventbus.jar')
    compile project(':sdk3-debug')
}

我不认为库项目的 AAR 文件会引入依赖项目(AAR 或 JAR),因此应用程序无法找到这些类。

我阅读了传递依赖,但我无法找到可能对我的情况有所帮助的示例实现。

最佳答案

这应该可以解决您的问题:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile files('libs/eventbus.jar')
    compile project(':sdk3-debug') { transitive = true }
}

true 处包含可传递标志.

关于android-gradle-plugin - 创建具有多个 AAR/JAR 的 AAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34445399/

相关文章:

android - Proguard 与 AAR 库问题

android - 如何从库/依赖项中获取客户端应用程序的应用程序版本?

java - Apache Ivy 。未检索到传递依赖项

php - 需要其他依赖项应该使用的 Composer 的 fork

使用 jmDNS 的 Android 构建失败

android - 在 Android 库项目中包含 AAR 依赖项

Android 可以包含 .aar 和 activity extends 应用程序吗?

Android Gradle 项目升级构建工具到 21.0.1 : aapt throws Exception

安卓测试: Multiple dex files define Lorg/hamcrest/Description;

android-studio - Android Studio 3.1 卡在 "Building *** Gradle project info"