Skip to content

Commit 564f9b3

Browse files
vaslabslefou
andauthored
Android: Package jnis provided by dependencies (#5760)
This PR resolves an issue found [during integration](#5758) where we were missing the functionality to include in the apk, native deps provided by dependencies <img width="1448" height="637" alt="image" src="https://github.com/user-attachments/assets/8101b58f-5006-4cac-9fc8-8b277b3007ab" /> I have also renamed the kspDeps as suggested from #5727 --------- Co-authored-by: Tobias Roeser <[email protected]>
1 parent e30be9c commit 564f9b3

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

libs/androidlib/src/mill/androidlib/AndroidAppModule.scala

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import mill.api.JsonFormatters.given
1010
import mill.api.{ModuleRef, PathRef, Task}
1111
import mill.javalib.*
1212
import os.{Path, RelPath, zip}
13+
import os.RelPath.stringRelPathValidated
1314
import upickle.default.*
1415
import 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)

libs/kotlinlib/src/mill/kotlinlib/ksp/Ksp2Module.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ trait Ksp2Module extends KspBaseModule { outer =>
4444
* For finding the right versions, also see [[https://github.com/google/ksp/releases]]
4545
* For more info go to [[https://github.com/google/ksp/blob/main/docs/ksp2cmdline.md]]
4646
*/
47-
def kspDeps: T[Seq[Dep]] = Task {
47+
def kspToolsDeps: T[Seq[Dep]] = Task {
4848
Seq(
4949
mvn"com.google.devtools.ksp:symbol-processing-aa-embeddable:${kotlinVersion()}-${kspVersion()}",
5050
mvn"com.google.devtools.ksp:symbol-processing-api:${kotlinVersion()}-${kspVersion()}",
@@ -53,8 +53,11 @@ trait Ksp2Module extends KspBaseModule { outer =>
5353
)
5454
}
5555

56-
def kspDepsResolved: T[Seq[PathRef]] = Task {
57-
defaultResolver().classpath(kspDeps(), resolutionParamsMapOpt = Some(addJvmVariantAttributes))
56+
def kspToolsDepsClasspath: T[Seq[PathRef]] = Task {
57+
defaultResolver().classpath(
58+
kspToolsDeps(),
59+
resolutionParamsMapOpt = Some(addJvmVariantAttributes)
60+
)
5861
}
5962

6063
/**
@@ -113,7 +116,7 @@ trait Ksp2Module extends KspBaseModule { outer =>
113116
s"-map-annotation-arguments-in-java=false"
114117
) ++ kspArgs() :+ processorClasspath
115118

116-
val kspJvmMainClasspath = kspDepsResolved().map(_.path)
119+
val kspJvmMainClasspath = kspToolsDepsClasspath().map(_.path)
117120
val mainClass = "com.google.devtools.ksp.cmdline.KSPJvmMain"
118121
Task.log.debug(
119122
s"Running Kotlin Symbol Processing with java -cp ${kspJvmMainClasspath.mkString(File.pathSeparator)} ${mainClass} ${args.mkString(" ")}"

libs/kotlinlib/src/mill/kotlinlib/ksp/KspModule.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ trait KspModule extends KspBaseModule { outer =>
3939
/**
4040
* Mandatory plugins that are needed for KSP to work.
4141
* For more info go to [[https://kotlinlang.org/docs/ksp-command-line.html]]
42-
*
43-
* @deprecated Use `kspDeps` instead
44-
*
45-
* @return
4642
*/
4743
def kspPlugins: T[Seq[Dep]] = Task {
4844
Seq(

0 commit comments

Comments
 (0)