Android Question [SOLVED] OCR - MobileVisionText

saunwin

Active Member
Licensed User
Longtime User
I'm having trouble getting this to work.
AppCompat not used message appearring
B4A 9.8
AppCompat 4.00 ticked in the library manager list and present n additional library folder.
I've followed this thread - https://www.b4x.com/android/forum/threads/ocr-mobilevisiontext.82910/
Any clues anyone ?

TIA


** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/truiton/mobile/vision/ocr/MainActivity;
at mobilevisiontextwrapper.mobilevisiontextWrapper.Initialize(mobilevisiontextWrapper.java:76)
at JHS.MobileVisionText.main._activity_create(main.java:387)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at JHS.MobileVisionText.main.afterFirstLayout(main.java:104)
at JHS.MobileVisionText.main.access$000(main.java:17)
at JHS.MobileVisionText.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
Caused by: java.lang.ClassNotFoundException: com.truiton.mobile.vision.ocr.MainActivity
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 18 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
... 18 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AppCompatActivity" on path: DexPathList[[zip file "/data/app/JHS.MobileVisionText-JZ1zA1QibLNO7HHwH0qzGQ==/base.apk"],nativeLibraryDirectories=[/data/app/JHS.MobileVisionText-JZ1zA1QibLNO7HHwH0qzGQ==/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 18 more
** Activity (main) Resume **
 

Johan Schoeman

Expert
Licensed User
Longtime User
I have revisited the library yesterday to make it work with B4A v9.80 and it is working. Have not had time to post it. Will do so sometime this week when I have time to do so. Old laptop and takes "hours" to start up. I did run in a compile error at first but it was not related to AppCompat. Had to add MultiDex: True to get it compiled. Don't know why but adding it solved the compile error.
 
Last edited:
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Try with the attached - please note that I have not made the B4A project "RunTimePermission" compliant. You can add the required B4A code to the project to do so and then change the B4A Manifest accordingly.

Working on Android 9 (Samsung SM-G973F) with B4A V9.80 🇿🇦

B4A Manifest as it is at present:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="22"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

SetApplicationAttribute(android:theme, "@style/MyAppTheme")
AddApplicationText(<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.gms.vision.DEPENDENCIES"
            android:value="ocr" />

<activity android:name="com.truiton.mobile.vision.ocr.MainActivity">

        </activity>)

B4A sample code (see attached B4A project):
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aMobileVisionText
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
    #MultiDex: True
#End Region

#AdditionalRes: ..\DemoRes
#AdditionalRes: ..\resource


#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    
    Dim mvt As MobileVisionText

    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    
    mvt.Initialize("mvt")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
    
    mvt.startMobileVisionText
    
End Sub

Sub mvt_blocks_result(blocks As String)
    
    Log("B4A Blocks = " & blocks)
    
End Sub

Sub mvt_lines_result(lines As String)
    
    Log("B4A Lines = " & lines)
    
End Sub

Sub mvt_words_result(words As String)
    
    Log("B4A Words = " & words)
    
End Sub

Sub mvt_error_result(error As String)
    
    Log("B4A ERROR = " & error)
    
End Sub

Extract the B4A lib files from the attached zip file and copy them to your additional libs folder. It includes constraint-layout-1.0.1.aar that needs to be in your additional libs folder.

Libraries enabled in B4A libs tab
1584376598735.png



Make sure you add folder DemoRes and resource with their contents to the B4A app (have attached them to this post). They must be on the same folder level as that of the /Objects and /Files folders of the B4A project.

Enjoy!
 

Attachments

  • B4ALibFiles20200316.zip
    44.2 KB · Views: 168
  • b4aMobileVisionText20200316.zip
    8.3 KB · Views: 175
  • DemoRes.zip
    57.4 KB · Views: 157
  • resource.zip
    423 bytes · Views: 168
Upvote 0
Top