Android Question 'JavaObject.RunMethod' - NoClassDefFoundError

BjoernB

Member
Licensed User
Longtime User
Hi everyone!

we're running B4A on 2 PCs in 2 different Versions -
the older one, 13.10 using Android SDK 34
the newer one, 13.40 using Android SDK 36

on the older one, everything works pretty fine - the new one keeps getting an Error in the following code:
Public Sub Scan:
Public Sub Scan (Formats As List) As ResumableSub
    Dim builder As JavaObject
    builder.InitializeNewInstance("com/google/mlkit/vision/codescanner/GmsBarcodeScannerOptions.Builder".Replace("/", "."), Null)
    Dim f(Formats.Size - 1) As Int
    For i = 1 To Formats.Size - 1
        f(i - 1) = Formats.Get(i)
    Next
    builder.RunMethod("setBarcodeFormats", Array(Formats.Get(0), f))
'    builder.RunMethod("enableAutoZoom", Null)
    Dim options As JavaObject = builder.RunMethod("build", Null)
    Dim scanning As JavaObject
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim CamScan1 As JavaObject = scanning.InitializeStatic("com/google/mlkit/vision/codescanner/GmsBarcodeScanning".Replace("/", ".")).RunMethod("getClient", Array(ctxt, options))
    Dim o As JavaObject = CamScan1.RunMethod("startScan", Null)
    Do While o.RunMethod("isComplete", Null).As(Boolean) = False
        Sleep(50)
    Loop
    Dim res As ScannerResult
    res.Initialize
    If o.RunMethod("isSuccessful", Null) Then
        res.Success = True
        res.Barcode = o.RunMethod("getResult", Null)
        res.Value = res.Barcode.RunMethod("getRawValue", Null)
    End If
    Return res
End Sub

this is an example code from b4a itself, it's not from us.

CamScan1.RunMethod(startScan", Null) keeps crashing with the Error java.lang.NoClassDefFoundError
Full Error Code will be posted below.

do you have any Ideas what we can do to fix this?
by now, we're compiling the apk on the other PC, the old version, but that's just a Workaround.


Full Error:
*** Receiver (httputils2service) Receive ***
** Activity (login) Pause, UserClosed = true **
** Activity (main) Resume **
Abschn All get ok
** Activity (main) Pause, UserClosed = false **
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/arch/core/executor/ArchTaskExecutor;
at androidx.lifecycle.LifecycleRegistry_androidKt.isMainThread(LifecycleRegistry.android.kt:23)
at androidx.lifecycle.LifecycleRegistry.enforceMainThreadIfNeeded(LifecycleRegistry.jvm.kt:297)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.jvm.kt:172)
at androidx.activity.ComponentActivity.<init>(ComponentActivity.kt:256)
at com.google.mlkit.vision.codescanner.internal.GmsBarcodeScanningDelegateActivity.<init>(com.google.android.gms:play-services-code-scanner@@16.1.0:1)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at android.app.Instrumentation.newActivity(Instrumentation.java:1328)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4038)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325)
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:2574)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8762)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Caused by: java.lang.ClassNotFoundException: androidx.arch.core.executor.ArchTaskExecutor
... 21 more

Thanks and greetings,
BjoernB
 
Solution
Add:
#AdditionalJar: com.google.android.gms:play-services-code-scanner
#AdditionalJar: com.google.android.gms:play-services-base

#AdditionalJar: androidx.lifecycle:lifecycle-runtime
#AdditionalJar: androidx.lifecycle:lifecycle-common
#AdditionalJar: androidx.activity:activity
#Jaraggiuntivo: androidx.arch.core:core-runtime

I had the same problem, if you add this it works for you.

teddybear

Well-Known Member
Licensed User
Try adding these lines to main module:
B4X:
#AdditionalJar: kotlin-stdlib-2.1.0
#AdditionalJar: androidx.arch.core:core-common
#AdditionalJar: androidx.arch.core:core-runtime
 
Upvote 0

valerioup

Member
Licensed User
Longtime User
Add:
#AdditionalJar: com.google.android.gms:play-services-code-scanner
#AdditionalJar: com.google.android.gms:play-services-base

#AdditionalJar: androidx.lifecycle:lifecycle-runtime
#AdditionalJar: androidx.lifecycle:lifecycle-common
#AdditionalJar: androidx.activity:activity
#Jaraggiuntivo: androidx.arch.core:core-runtime

I had the same problem, if you add this it works for you.
 
Upvote 1
Solution

BjoernB

Member
Licensed User
Longtime User
B4X:
#AdditionalJar: kotlin-stdlib-2.1.0
#AdditionalJar: androidx.arch.core:core-common
#AdditionalJar: androidx.arch.core:core-runtime
this one unfortunately didn't work


Add:
#AdditionalJar: com.google.android.gms:play-services-code-scanner
#AdditionalJar: com.google.android.gms:play-services-base

#AdditionalJar: androidx.lifecycle:lifecycle-runtime
#AdditionalJar: androidx.lifecycle:lifecycle-common
#AdditionalJar: androidx.activity:activity
#Jaraggiuntivo: androidx.arch.core:core-runtime
but after replacing "#Jaraggiuntivo" with "#AdditionalJar", this one did! Thank you!
 
Upvote 0
Top