Android Studio如何从多个库项目打包单个AAR ?

时间:2022-11-12 20:53:16

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

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

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.

我想知道是否有一种方法来打包一个AAR库,它已经包含了内部库。我想向我的应用程序开发人员共享一个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.

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

----- internalLib -------->>>>>>>>>>

- - - - - - internalLib - - - - - - - - > > > > > > > > > >

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 --------

- - - - - - 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')
}

1 个解决方案

#1


29  

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.

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

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).

此时,没有办法轻松破解某些东西,除非您确定两个res文件夹之间的资源没有冲突(例如,您可以使用strings_a)。xml在一个lib和strings_b中。另一个库中的xml)。通过这种方式,您可以将两个res文件夹“合并”到同一个位置(而不是在android的res级别进行合并)。

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.

为此提供一个内置机制对我们的优先级来说非常低,所以不要期望它很快就会实现。

#1


29  

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.

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

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).

此时,没有办法轻松破解某些东西,除非您确定两个res文件夹之间的资源没有冲突(例如,您可以使用strings_a)。xml在一个lib和strings_b中。另一个库中的xml)。通过这种方式,您可以将两个res文件夹“合并”到同一个位置(而不是在android的res级别进行合并)。

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.

为此提供一个内置机制对我们的优先级来说非常低,所以不要期望它很快就会实现。