@@ -10,6 +10,7 @@ import mill.api.JsonFormatters.given
1010import mill .api .{ModuleRef , PathRef , Task }
1111import mill .javalib .*
1212import os .{Path , RelPath , zip }
13+ import os .RelPath .stringRelPathValidated
1314import upickle .default .*
1415import scala .concurrent .duration .*
1516
@@ -204,6 +205,19 @@ trait AndroidAppModule extends AndroidModule { outer =>
204205
205206 }
206207
208+ /**
209+ * Picks all jni deps from the resolved dependencies to be packaged into the APK.
210+ */
211+ def androidPackageableNativeDeps : T [Seq [AndroidPackageableExtraFile ]] = Task {
212+ androidTransformAarFiles(resolvedRunMvnDeps)().flatMap {
213+ unpackedDep =>
214+ unpackedDep.nativeLibs.toList.filter(pr => os.exists(pr.path))
215+ .flatMap(lib => os.list(lib.path))
216+ }.map(nativeLibDir =>
217+ AndroidPackageableExtraFile (PathRef (nativeLibDir), " lib" / nativeLibDir.last)
218+ )
219+ }
220+
207221 /**
208222 * Packages DEX files and Android resources into an unsigned APK.
209223 *
@@ -217,14 +231,17 @@ trait AndroidAppModule extends AndroidModule { outer =>
217231 .filter(_.ext == " dex" )
218232 .map(os.zip.ZipSource .fromPath)
219233
220- val metaInf = androidPackageMetaInfoFiles().map(extraFile =>
221- os.zip.ZipSource .fromPathTuple((extraFile.source.path, extraFile.destination.asSubPath))
222- )
234+ def asZipSource (androidPackageableExtraFile : AndroidPackageableExtraFile ): os.zip.ZipSource =
235+ os.zip.ZipSource .fromPathTuple(
236+ (androidPackageableExtraFile.source.path, androidPackageableExtraFile.destination.asSubPath)
237+ )
238+
239+ val metaInf = androidPackageMetaInfoFiles().map(asZipSource)
240+
241+ val nativeDeps = androidPackageableNativeDeps().map(asZipSource)
223242
224243 // add all the extra files to the APK
225- val extraFiles : Seq [zip.ZipSource ] = androidPackageableExtraFiles().map(extraFile =>
226- os.zip.ZipSource .fromPathTuple((extraFile.source.path, extraFile.destination.asSubPath))
227- )
244+ val extraFiles : Seq [zip.ZipSource ] = androidPackageableExtraFiles().map(asZipSource)
228245
229246 // TODO generate aar-metadata.properties (for lib distribution, not in this module) or
230247 // app-metadata.properties (for app distribution).
@@ -240,6 +257,7 @@ trait AndroidAppModule extends AndroidModule { outer =>
240257 // androidGradlePluginVersion=8.7.2
241258 os.zip(unsignedApk, dexFiles)
242259 os.zip(unsignedApk, metaInf)
260+ os.zip(unsignedApk, nativeDeps)
243261 os.zip(unsignedApk, extraFiles)
244262
245263 PathRef (unsignedApk)
0 commit comments