创建具有多个 AAR/JAR 的 AAR [英] Create an AAR with multiple AARs/JARs

查看:33
本文介绍了创建具有多个 AAR/JAR 的 AAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过问题(Android Studio 将 2 .aar 合二为一 和其他人)由各种开发人员发布,但我还没有看到明确的回应,使我能够创建一个包含 1 个或多个 AAR 或 JAR 的 AAR(我可以使用 JAR,因为我不需要共享任何资源;只上课).这是我的图书馆项目的 app.gradle:

I have seen questions (Android Studio combine 2 .aar into one and others) posted by various developers but I haven't seen a definitive response that enables me to create an AAR that includes 1 or more AARs or JARs (I can do with JARs since I don't need to share any resources; only classes). Here is the app.gradle for my library project:

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 添加到我的应用程序中.

Again, this app is a library project which needs two other library projects ('core-release', 'midware-release') and while I was able to generate one AAR file that I can use in my application, the application was unable to find the dependent library projects' classes so, I had to add the two library projects' AARs into my application.

这是 app.gradle 应用程序项目(无需手动添加 JAR),它无法找到依赖项目的类:

Here is the app.gradle application project (without adding the JARs manually) which is unable to find the dependent projects' classes:

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),因此应用程序无法找到类.

I don't think the library project's AAR file is pulling in the dependent projects (AAR or JAR) and hence the application is unable to find the classes.

我阅读了有关传递依赖的信息,但我找不到可能对我的情况有所帮助的示例实现.

I read about transitive dependency, but I was unable to find an example implementation which may help with my situation.

推荐答案

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

This should fix your issue:

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 处包含传递标志.

Include the transitive flag at true.

这篇关于创建具有多个 AAR/JAR 的 AAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆