Android Question AdditionalJar with .aar file Class not found exception

EvgenyB4A

Active Member
Licensed User
Hi.
At attached project I need to use .aar file but I get the error when press Init button:

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
BroadcastReceiver has been initialized.
** Activity (main) Resume **
** Activity (main) Resume **
Error occurred on line: 122 (Main)
java.lang.ClassNotFoundException: com$nayax$cardreader$service
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:288)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:83)
at nayax.LandyBrcstexample.main._btninit_click(main.java:494)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4781)
at android.view.View$PerformClick.run(View.java:19874)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5271)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**

I renamed the file cardreader-debug.aar to cardreader-debug.jar in order to upload.
This .aar was created in at Android studio from Kotlin source.
 

Attachments

wes58

Active Member
Licensed User
Hi.
At attached project I need to use .aar file but I get the error when press Init button:

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
BroadcastReceiver has been initialized.
** Activity (main) Resume **
** Activity (main) Resume **
Error occurred on line: 122 (Main)
java.lang.ClassNotFoundException: com$nayax$cardreader$service
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:288)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:83)
at nayax.LandyBrcstexample.main._btninit_click(main.java:494)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4781)
at android.view.View$PerformClick.run(View.java:19874)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5271)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**

I renamed the file cardreader-debug.aar to cardreader-debug.jar in order to upload.
This .aar was created in at Android studio from Kotlin source.
You have this line in your code: LandiPeriph.InitializeNewInstance("com.nayax.cardreader.service", Array(jo))
Have you got a class named "service" in your aar?

I haven't used Kotlin but I think that you should rewrite your library to java.
Do a search on Google about using Kotlin aar with Java.
 

EvgenyB4A

Active Member
Licensed User
If you unzip the .aar file you can see file classes.jar and inside this file there is reference to com.nayax.cardreader.service
 

wes58

Active Member
Licensed User
You have this line in your code: LandiPeriph.InitializeNewInstance("com.nayax.cardreader.service", Array(jo))
Have you got a class named "service" in your aar?

I haven't used Kotlin but I think that you should rewrite your library to java.
Do a search on Google about using Kotlin aar with Java.
Why do you think I asked you if you have a class named service? Because I looked in the classes.jar - com.nayax.cardreader.service is the package name not a class name.
Look in the .class file names which are in this folder.
Anyway, did you search Google about mixing Kotlin and Java? If you did you would know that it is not easy if you are using different development tools.
This is from one website:
When you pack your plugin into an AAR files, the dependencies are not packed with it assuming that the consumer (which is usually another Android Studio project) will resolve these dependencies.
 

Erel

Administrator
Staff member
Licensed User
It should probably be: com.nayax.cardreader.service.CardReaderService
 

wes58

Active Member
Licensed User
It should probably be: com.nayax.cardreader.service.CardReaderService
I tried that when I was checking for him. Then it comes up with some kotlin errors -
Didn't find class "kotlin.jvm.internal.Intrinsics"
.

B4X:
LandiPeriph.InitializeNewInstance("com.nayax.card
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:90)
    at nayax.LandyBrcstexample.main._btninit_click(main.java:515)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7352)
    at android.widget.TextView.performClick(TextView.java:14177)
    at android.view.View.performClickInternal(View.java:7318)
    at android.view.View.access$3200(View.java:846)
    at android.view.View$PerformClick.run(View.java:27800)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7032)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;
    at com.nayax.cardreader.service.CardReaderService.<init>(Unknown Source:5)
    ... 21 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.jvm.internal.Intrinsics" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/nayax.LandyBrcstexample-gw3wGJmX29uOsSL-X3JQCA==/base.apk"],nativeLibraryDirectories=[/data/app/nayax.LandyBrcstexample-gw3wGJmX29uOsSL-X3JQCA==/lib/arm64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
 
Last edited:

EvgenyB4A

Active Member
Licensed User
I have added references for kotlin and got the following:

Logger connected to: 0123456789ABCDEF
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
BroadcastReceiver has been initialized.
** Activity (main) Resume **
Error occurred on line: 125 (Main)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:90)
at nayax.LandyBrcstexample.main._btninit_click(main.java:494)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4781)
at android.view.View$PerformClick.run(View.java:19874)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5271)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ltimber/log/Timber;
at com.nayax.cardreader.service.CardReaderService.<init>(CardReaderService.kt:18)
... 25 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "timber.log.Timber" on path: DexPathList[[zip file "/data/app/nayax.LandyBrcstexample-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib, /lib, /usr/lib, /home/EPT_Middleware/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 26 more
Suppressed: java.lang.ClassNotFoundException: timber.log.Timber
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 27 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
** Activity (main) Pause, UserClosed = true **
 

EvgenyB4A

Active Member
Licensed User
The reference to timber was removed but now I get:

Logger connected to: 0123456789ABCDEF

--------- beginning of system

--------- beginning of main

*** Service (starter) Create ***

** Service (starter) Start **

** Activity (main) Create, isFirst = true **

BroadcastReceiver has been initialized.

** Activity (main) Resume **

Error occurred on line: 125 (Main)

java.lang.reflect.InvocationTargetException

at java.lang.reflect.Constructor.newInstance(Native Method)

at java.lang.reflect.Constructor.newInstance(Constructor.java:288)

at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:90)

at nayax.LandyBrcstexample.main._btninit_click(main.java:494)

at java.lang.reflect.Method.invoke(Native Method)

at java.lang.reflect.Method.invoke(Method.java:372)

at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)

at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)

at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)

at java.lang.reflect.Method.invoke(Native Method)

at java.lang.reflect.Method.invoke(Method.java:372)

at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)

at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)

at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)

at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)

at android.view.View.performClick(View.java:4781)

at android.view.View$PerformClick.run(View.java:19874)

at android.os.Handler.handleCallback(Handler.java:739)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:135)

at android.app.ActivityThread.main(ActivityThread.java:5271)

at java.lang.reflect.Method.invoke(Native Method)

at java.lang.reflect.Method.invoke(Method.java:372)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)

Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/LocalBroadcastManager;

at com.nayax.cardreader.service.CardReaderService.<init>(CardReaderService.kt:23)

... 25 more

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.LocalBroadcastManager" on path: DexPathList[[zip file "/data/app/nayax.LandyBrcstexample-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib, /lib, /usr/lib, /home/EPT_Middleware/lib]]

at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)

at java.lang.ClassLoader.loadClass(ClassLoader.java:511)

at java.lang.ClassLoader.loadClass(ClassLoader.java:469)

... 26 more

Suppressed: java.lang.ClassNotFoundException: android.support.v4.content.LocalBroadcastManager

at java.lang.Class.classForName(Native Method)

at java.lang.BootClassLoader.findClass(ClassLoader.java:781)

at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)

at java.lang.ClassLoader.loadClass(ClassLoader.java:504)

... 27 more

Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

** Activity (main) Pause, UserClosed = true **

I think it already related to my application.
What is android.support.v4?
 
Top