Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java.lang.ClassNotFoundException #60

Open
HomeroLara opened this issue Nov 4, 2024 · 0 comments
Open

Java.lang.ClassNotFoundException #60

HomeroLara opened this issue Nov 4, 2024 · 0 comments

Comments

@HomeroLara
Copy link

Description

Description

Re-creating this issue as it was accidentally closed.

After doing some research on the Maui.NativeLibraryInterop package it appears that you two maybe the most knowledgable on this so apologies for directly tagging you two on this Github issue ( this is also open for anyone else to comment ).

I'm hoping for guidance or feedback on an issue that I'm facing using the Maui.NativeLibraryInterop package for Android.

I cloned the Maui.NativeLibraryInterop repo and was able to get several the sample projects working on Android and was also able to get MauiCharts example working on Android as well but I'm struggling to get the process used in this repo working for a third party SDK that I'm using called Rokt.

I've created the native wrapper for this SDK using Kotlin which is being pulled into a MAUI Android Binding project in the same manner detailed in MS's getting started with native library interop and also detailed in this blog post. After compiling the MAUI Android Library, I see the generated .aar files for the native wrapper and it's dependencies in the /deps/ folder but at runtime when I try to initialize the SDK, I receive a 'Java.lang.ClassNotFoundException'. Any ideas what maybe causing this? Stack trace is below:

--- End of managed Java.Lang.ClassNotFoundException stack trace ---
java.lang.ClassNotFoundException: Didn't find class "com.rokt.roktsdk.Rokt" on path: DexPathList[[zip file "/data/app/~~9cGZ3C9Iej5_M4dtugRZmg==/com.companyname.roktmaui-dVt8QFJ3n9DOqnoxO18-dg==/base.apk"],nativeLibraryDirectories=[/data/app/~~9cGZ3C9Iej5_M4dtugRZmg==/com.companyname.roktmaui-dVt8QFJ3n9DOqnoxO18-dg==/lib/arm64, /data/app/~~9cGZ3C9Iej5_M4dtugRZmg==/com.companyname.roktmaui-dVt8QFJ3n9DOqnoxO18-dg==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
at java.lang.ClassLoader.loadClass(ClassLoader.java:637)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at com.nubisuno.roktsdkimplemenation.RoktSDkWrapper$Companion.initializeSDK(RoktSDkWrapper.kt:18)
at com.nubisuno.roktsdkimplemenation.RoktSDkWrapper.initializeSDK(Unknown Source:2)
at crc649d470b447c1776a3.MainActivity.n_onCreate(Native Method)
at crc649d470b447c1776a3.MainActivity.onCreate(MainActivity.java:39)
at android.app.Activity.performCreate(Activity.java:8290)
at android.app.Activity.performCreate(Activity.java:8269)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3657)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3813)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2308)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Questions:

  • I've pulled in the native Rokt Android SDK dependencies that are list from Android Studio's File -> Project Structure.. -> Dependencies -> roktsdk:4.6.0 into my MAUI app's csproj but I've notice the dependencies located in the /deps/ folder are far more. I also notice this similar implementation for the facebook sample project in Maui.NativeLibraryInterop repo. How did you decide which dependencies were needed to be referenced in the Facebook MAUI sample project?

  • I asked this question in a different issue raised for this repo but I'd like to ask here also: For Android, why are Android native .aar files referenced in the MAUI csproj files ( Example: see here )? Wouldn't the native project, which is being used to create the MAUI Binding library have those SDKs already?

  • I've seen the videos and posts from @rachelkang & @Redth on how to use the Maui.NativeLibraryInterop nuget package but is there is any documentation on the src projects for the Maui.NativeLibraryInterop located here ? Looks like all the magic is happening here.

I've created a repo that contains a sample project using the Maui.NativeLibraryInterop package, a native wrapper that pulls in the the Rokt SDK for Android and even an Android project using the native wrapper listed below.

Again, any comments or guidance is very much appreciated.

Thanks!

Steps to Reproduce

  1. Clone this repo
  2. Rebuild the MAUI project located in the /RoktMAUI/ folder
  3. In the solution, navigate to Platforms -> Android -> MainActivity.cs
  4. Place break points on lines 15 & 21 in the MainActivity.cs
  5. In debug mode, deploy the app to a device or simulator and you see the 'Java.Lang.ClassNotFoundException' in the catch block

Additional details about the contents in this repo:

  • The NativeLibrary folder contains the native wrapper written in Kotlin called RoktSDkWrapper.
  • The NativeLibraryAppDemo folder contains an Android app that imports the RoktSDkWrapper and calls the initialize method.
  • The RoktMAUI.Android.Binding folder contains the MAUI Android Library that creates the binding library for the RoktSDkWrapper.
  • The RoktMAUI folder contains the app that attempts to initialize the RoktSDkWrapper.

Please feel to ask any questions.

Thanks!

Link to public reproduction project repository

https://github.com/HomeroLara/RoktDroidMauiInterop

Environment

  • OS: Mac ( Apple M2 Max ), Sonoma 14.6.1
  • .NET MAUI: Net 8.0.403 / Maui Workload 8.0.82/8.0.100 SDK 8.0.400
  • Target platforms: Android and iOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant