与捆绑的依赖库(脂肪AAR)脂肪、AAR

2023-09-04 11:16:09 作者:不就行

我们建立,我们分配给我们的客户库。散发他们使用的原始AAR文件。此外,我们使用GitHub上的原始访问API提供了Maven仓库。

We build a library that we distribute to our customers. We distribute the raw aar files for them to use. Also we use the raw access API of GitHub to provide a Maven repository.

现在要保持整洁,我们分手库分为几个模块:

Now to keep things tidy, we split up the library into several modules:

include ':library'
include ':geohash'
include ':networkstate'
include ':okvolley'
include ':volley'

是一款Android库,所以是抽射 okvolley networkstate

library is an Android library, so are volley and okvolley and networkstate.

现在,当我发布的依赖关系树看起来是这样的:

Now when I publish library, the dependency tree looks like this:

\--- com.sensorberg.sdk:sensorberg-sdk:0.10.0-SNAPSHOT
 +--- com.squareup.okhttp:okhttp-urlconnection:2.2.0
 |    \--- com.squareup.okhttp:okhttp:2.2.0
 |         \--- com.squareup.okio:okio:1.2.0
 +--- com.google.code.gson:gson:2.3.1 
 +--- android-sdk:okvolley:unspecified
 |    +--- com.squareup.okhttp:okhttp-urlconnection:2.2.0 (*)
 |    +--- com.google.code.gson:gson:2.3.1
 |    +--- android-near-gradle:volley:unspecified
 |    \--- com.squareup.okhttp:okhttp:2.2.0 (*)
 +--- android-sdk:networkstate:unspecified
 +--- com.squareup.okhttp:okhttp:2.2.0 (*)
 +--- android-sdk:volley:unspecified
 \--- com.loopj.android:android-async-http:1.4.5

正如你可以看到 Android的SDK:networkstate:未指定 Android的SDK:okvolley:未指定现身在外部依赖的列表。

As you can see android-sdk:networkstate:unspecified and android-sdk:okvolley:unspecified show up in the list of external dependencies.

我想创建我的 AAR与捆绑的本地模块。它应该做一个本地清单合并,远罐子......和合并所有模块的dependcies。只有外部模块应该显示。

I would like to create my library aar with the local modules bundled. It should do a local manifest merge and far jar... and merge the dependcies of all modules. Only external modules should show.

我也尝试从建立/输出/ AAR引用本地AAR文件中的各个模块文件夹,但似乎也行不通。它似乎仍然按名称引用本地模块,而不是合并罐子的体现...

I did try to reference the local aar file from the build/output/aar folder of the respective modules, but that also seems to not work. It still seems to reference the local modules by their names and not merge the jar's manifests...

有人曾经做过这样的事情?安卓之外,这将被称为fatjar和有像 musketyr /摇篮 - fatjar-插件产生一个插件fatjar与摇篮。

Anybody ever done something like this? Outside of Android this would be called a fatjar and there are plugins like musketyr/gradle-fatjar-plugin that produce a fatjar with Gradle.

我想这对我的本地模块

if (project.ext.libraryBuild == true) {
    def moduleName = getName()
    File artifactFile = file("/build/outputs/aar/${moduleName}-release.aar")
    if (!artifactFile.exists()) {
        throw new GradleException("Dependency ${moduleName} is not build")
    }
    configurations.create("default")
    artifacts.add("default", artifactFile)
    return;
}


apply plugin: 'com.android.library'

android {
    compileSdkVersion 19
    buildToolsVersion = '21.1.2'
}

直接引用AAR ...

to reference the aar directly...

推荐答案

我也有类似的要求,所以搜索了很多之后,我结束了通过Android插件黑客自己的路。我不知道Groovy的不多,但我可以想办法做饭了,做构建它是由应用程序接受了脂肪AAR文件摇篮文件。

I had a similar requirement, so after searching a lot I ending up hacking my way through the android plugin. I do not know groovy much, but I could manage to cook up a gradle file that does build a fat aar file which is accepted by the app.

由此产生的code可在 github.com/adwiv/android-fat-aar 。详细说明在GitHub的网站。由此产生的 build.gradle 是这样的:

The resulting code is available at github.com/adwiv/android-fat-aar. The detailed instructions are at the GitHub site. The resulting build.gradle would look like this:

apply from: 'fat-aar.gradle'

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])

  embedded project(':libraryone')
  embedded project('com.example.internal:lib-three:1.2.3')

  compile 'com.android.support:appcompat-v7:22.2.0'
}

目前的code不试图合并AIDL文件,因为我不使用它们。下面的功能是present和工作对我来说(虽然我的库是不是太复杂)

The current code does not attempt to merge AIDL files, since I don't use them. The following features are present and work for me (although my libraries are not too complex)

类(所以ProGuard的作品上再加clases)合并 资产和JNI库的合并 舱单的合并 资源合并 从同一个项目库嵌入 从Maven仓库嵌入库

只有Android的库(AAR)可以嵌入,而不是JAR文件,虽然嵌入式库的库文件夹中的jar文件解压缩和合并。

Only android libraries (aar) can be embedded, not jar files, although jar files within the libs folders of embedded libraries are unpacked and merged.

试试吧,让我知道的任何问题。你可以通过在code和修改您的需求。

Try it out and let me know any issues. You can go through the code and modify it to your needs.

 
精彩推荐