Android Question AndroidX and Chrome Custom Tabs

martin24

Member
Licensed User
I updated to B4A 9.30 and converted to AndroidX. In my app, everything runs fine except ChromCustomTabs. I use this lib: https://www.b4x.com/android/forum/threads/chrome-custom-tabs.70312/#content

The app crashes as soon as I try to open a page in a ChromeCustomTab. Everything worked fine before converting to AndroidX.

This is the error I get:
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/customtabs/CustomTabsServiceConnection;

Any idea how to fix this problem?
 

Erel

Administrator
Staff member
Licensed User
Works fine here. Make sure to run the jetifier tool and then clean the project (Ctrl + P).

Tested with this code:
B4X:
#AdditionalJar: com.android.support:support-v4
Sub Process_Globals

End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim c As ChromCustomTabs
   c.Initialize("c")
   c.chromeCustomTab("https://www.google.com")
End Sub
 

martin24

Member
Licensed User
I created a new project and used exactly the same code as Erel in his example, and got this error:

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 339)
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/customtabs/CustomTabsServiceConnection;
    at b4a.example.main._activity_create(main.java:339)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at b4a.example.main.afterFirstLayout(main.java:104)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:874)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:198)
    at android.app.ActivityThread.main(ActivityThread.java:6729)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.customtabs.CustomTabsServiceConnection" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/b4a.example-kyccUr2gcZz9MGd7RwHKQw==/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example-kyccUr2gcZz9MGd7RwHKQw==/lib/arm64, /system/lib64, /system/vendor/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)
    ... 13 more

Make sure to run the jetifier tool and then clean the project (Ctrl + P).
The crash still happens after performing these steps.

When I try to run jetifier, a window seems to popup and is automatically closed within a second, I cannot see any content in that window. Is this the correct behavior?


Thanks for this link, the example project also crashes here with this error:

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 346)
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/customtabs/CustomTabsIntent$Builder;
    at de.donmanfred.CCTwrapper.Initialize(CCTwrapper.java:57)
    at b4a.example.cct.main._activity_create(main.java:346)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at b4a.example.cct.main.afterFirstLayout(main.java:104)
    at b4a.example.cct.main.access$000(main.java:17)
    at b4a.example.cct.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:874)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:198)
    at android.app.ActivityThread.main(ActivityThread.java:6729)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/b4a.example.cct-Ug8wW8pX1XmDIlrY9xmz1A==/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example.cct-Ug8wW8pX1XmDIlrY9xmz1A==/lib/arm64, /system/lib64, /system/vendor/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)
    ... 14 more
 

martin24

Member
Licensed User
Is Java 8 installed?
yes.

Change the path to your additional folder.

What do you see?
I see the correct window with installed libs and could also click the Jetify button.
The execution was successful and some androidx.jar files were created. ChromCustomTabs work fine now.

Problem solved, thank you very much.
 

martin24

Member
Licensed User
It seems that B4A has a problem with my lib folder what also caused my problems with the Jetifier window.

My lib folder is: G:\proj\apps\_libs\B4A\

Running this command opens the correct window:
java -jar "c:\Program Files (x86)\Anywhere Software\Basic4android\Jetifier.jar" G:\proj\apps\_libs\B4A\
Please try if you can reproduce these steps:

1) In "Configure paths", I have entered (with trailing backslash): G:\proj\apps\_libs\B4A\
2) Running Jetifier will not open the window correctly
3) In "Configure paths", I remove the trailing backslash, entered path now is: G:\proj\apps\_libs\B4A
4) Close this window (Jetifier works fine now)
5) Re-Open "Configure paths" and I just see: G:\proj\apps\_libs
---> B4A was removed! (closing and re-opening the "Configure paths" window is enough to automatically remove "\B4A")

When I use for example "G:\proj\apps\_libB4A", then everything works fine. Nothing is removed and Jetifier works correctly.
 

Erel

Administrator
Staff member
Licensed User
Top