rust-mobile / android-activity

Glue for building Rust applications on Android with NativeActivity or GameActivity
238 stars 46 forks source link

Is it possible to add jars/classes to the classpath? #159

Closed astonbitecode closed 4 months ago

astonbitecode commented 4 months ago

Hi,

is it possible to add to the classpath additional jars or classes, so that they are available via the JavaVM provided by vm_as_ptr?

To be more specific, I could use cargo-apk and pack several assets in my apk (jars or classes) so that they are available for the Android app. Could I somehow add them in the classpath?

MarijnS95 commented 4 months ago

Since jars/classes are not assets, they should be provided in a different way. As far as I remember, Android combines and "dexes" all Java code (classes and jars) together into classesX.dex. You could invoke the command line tool (https://developer.android.com/tools/d8) and place the output file in the root (probably needs a new feature in cargo-apk/xbuild to allow this). Or use a "standard" Android gradle project setup instead to link the jar, and use different way to compile your Rust code (cargo-ndk, rust-android-gradle).

Maybe cargo-apk/xbuild should provide builtin support for this some day.

astonbitecode commented 4 months ago

Thanks for the response. I understand android-activity cannot influence the classpath, so, I guess we can close this.