Android Studio 如何从多个库项目中打包单个 AAR? [英] Android Studio how to package single AAR from multiple library projects?

查看:58
本文介绍了Android Studio 如何从多个库项目中打包单个 AAR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建 android 库项目,该项目依赖于另一个内部库项目.

I am building android library project, which has a dependency on another internal library project.

我想知道是否有一种方法可以打包单个 AAR 库,其中已经包含内部库.我只想与我的应用程序开发人员共享 1 个 AAR 库包.

I am wondering if there is a way to package a single AAR library, which already contains internal library inside it. I would like to share only 1 AAR library package to my application developers.

这是我的 build.gradle 文件目前的样子,但目前它们生成单独的 AAR 文件,并且都需要包含在应用程序的 build.gradle 中.由于应用程序是由另一家公司构建的,我们需要与他们共享最终的 AAR 文件,而不是完整的库项目.

This is how my build.gradle files look currently, but currently they produce separate AAR files and both needs to be included in Application's build.gradle. As application is being built by another company, we need to share the final AAR file with them and not the complete library projects.

-----内部库-------->>>>>>>>>>

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android-library'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion '18.1.1'
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}

----- externalLib --------

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android-library'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion '18.1.1'
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
    compile project(':internalLib')
}

推荐答案

没有组合库的机制.这有点复杂,因为您可能想要控制合并哪些依赖项(例如,您可能不想在其中包含 support-v4).您还需要合并资源和 Android 清单.

There is no mechanism to combine library. It's a bit complicated as you probably want to control which dependencies get merged (for instance you probably don't want to include support-v4 in there). Also you'd need to merge the resources and Android manifest.

此时没有办法轻松破解某些内容,除非您确定资源在两个 res 文件夹之间没有冲突(例如,您可以在一个库中使用 strings_a.xml,在另一个库中使用 strings_b.xml).通过这种方式,您可以通过将两个 res 文件夹复制到同一位置来合并"它们(而不是在 android res 级别进行合并).

At this time there's no way to easily hack something, unless you are sure the resources have no conflicts between the two res folders (for instance you could have strings_a.xml in one lib and strings_b.xml in the other lib). This way you can just "merge" the two res folders by copying them both into the same location (as opposed to do a merge at the android res level).

对于 Manifest,它会更复杂,但可以使用一些自定义代码.

For the Manifest it'd be more complicated, but doable with some custom code.

为此提供内置机制的优先级非常低,所以不要指望很快就会这样做.

Providing a built-in mechanism for this is very low on our priority so don't expect it anytime soon.

这篇关于Android Studio 如何从多个库项目中打包单个 AAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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