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'
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
As you can see android-sdk:networkstate:unspecified
and android-sdk:okvolley:unspecified
show up in the list of external dependencies.
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.
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...
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.
I tried this on my local modules
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'
}
to reference the aar directly...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…