使用多个AAR/JAR创建AAR

Ani*_*thy 7 dependency-management android-gradle-plugin aar

我已经看到各种开发者发布的问题(Android Studio将两个.aar合并为一个和其他),但我没有看到一个明确的响应,使我能够创建一个包含一个或多个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')
}
Run Code Online (Sandbox Code Playgroud)

同样,这个应用程序是一个库项目,需要两个其他库项目('核心发布','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')
}
Run Code Online (Sandbox Code Playgroud)

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

我读到了传递依赖,但我无法找到可能有助于我的情况的示例实现.

San*_*ado 1

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

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 }
}
Run Code Online (Sandbox Code Playgroud)

包括在 处的传递标志true

  • 我尝试过,但无法克服“没有这样的属性:类的传递:org.gradle.api.internal.project.DefaultProject_Decolated”错误。即使从本地 gradle 分发中切换到“构建工具”->“Gradle 设置”中的默认 gradle 包装器也没有帮助 (2认同)
  • 你可以尝试一下:compile(project(':sdk3-debug')){transitive = true} (2认同)