Skip to content

Commit 382295f

Browse files
committed
build: Bundle jni-utils into droidplug.aar in build script
It's the way we've worked before, don't want to change it.
1 parent a4b07c6 commit 382295f

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

scripts/build-java.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ run_gradle_build() {
206206
chmod +x ./gradlew
207207
fi
208208

209-
./gradlew assembleDebug "$@"
209+
./gradlew assembleDebug assembleRelease "$@"
210210

211211
info "Java build completed successfully."
212212
}

src/droidplug/java/build.gradle

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,49 @@ dependencies {
2828
implementation 'io.github.gedgygedgy.rust:jni-utils:0.1.1-SNAPSHOT'
2929
//implementation files('c:/Users/qdot/code/jni-utils-rs/java/build/libs/jni-utils-0.1.1-SNAPSHOT.jar')
3030
}
31+
32+
// Embed jni-utils classes into the AAR's classes.jar so consumers that include
33+
// this AAR as a flat file (without Maven dependency resolution) get the
34+
// transitive dependency bundled automatically.
35+
android.libraryVariants.configureEach { variant ->
36+
def name = variant.name.capitalize()
37+
tasks.named("bundle${name}Aar").configure { bundleTask ->
38+
bundleTask.doLast {
39+
def aarFile = bundleTask.archiveFile.get().asFile
40+
def tmpDir = new File(project.layout.buildDirectory.asFile.get(), "tmp/fataar-${variant.name}")
41+
if (tmpDir.exists()) tmpDir.deleteDir()
42+
tmpDir.mkdirs()
43+
44+
// Extract the AAR
45+
ant.unzip(src: aarFile, dest: tmpDir)
46+
47+
// Collect runtime dependency JARs and merge into classes.jar
48+
def classesJar = new File(tmpDir, "classes.jar")
49+
def mergeDir = new File(tmpDir, "_merge")
50+
mergeDir.mkdirs()
51+
52+
// Extract existing classes.jar
53+
ant.unzip(src: classesJar, dest: mergeDir)
54+
55+
// Extract each runtime dependency JAR
56+
configurations.getByName("${variant.name}RuntimeClasspath").files.each { jar ->
57+
if (jar.name.endsWith(".jar")) {
58+
ant.unzip(src: jar, dest: mergeDir) {
59+
patternset { exclude(name: "META-INF/**") }
60+
}
61+
}
62+
}
63+
64+
// Re-jar
65+
classesJar.delete()
66+
ant.jar(destfile: classesJar, basedir: mergeDir)
67+
68+
// Cleanup merge dir before re-packaging
69+
mergeDir.deleteDir()
70+
71+
// Re-package the AAR
72+
aarFile.delete()
73+
ant.zip(destfile: aarFile, basedir: tmpDir)
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)