Error inflating SlidingPaneLayout class in AndroidX - android

Problem :
Hey everyone, I have a straightforward issue.
I have used androidx.slidingpanelayout.widget.SlidingPaneLayout in AndroidX before, and it worked perfectly fine.
But now, in my another application, Android-Studio is giving me an error which basically says it is having problems inflating SlidingPaneLayout class.
What I did :
I have checked every dependency and also compared it with my previous app that uses this.
I rebuilt my project many many times and also cleaned it (Build > Clean Project).
I used previous versions of material-design dependency and compiled my project with them, but nothing changed.
The dependencies I've used :
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Note that I've also tried to switch back to alpha09 which I used in my other app, but here it did nothing.
Error :
I have simply copied and pasted the whole error below.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: afm.scheduler, PID: 5241
java.lang.RuntimeException: Unable to start activity ComponentInfo{afm.scheduler/afm.scheduler.ChatActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.slidingpanelayout.widget.SlidingPaneLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.slidingpanelayout.widget.SlidingPaneLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.slidingpanelayout.widget.SlidingPaneLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.slidingpanelayout.widget.SlidingPaneLayout" on path: DexPathList[[zip file "/data/app/afm.scheduler-pdmC1V-CHlc9Wtgy6E_N0A==/base.apk"],nativeLibraryDirectories=[/data/app/afm.scheduler-pdmC1V-CHlc9Wtgy6E_N0A==/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:171)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:610)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.inflate(LayoutInflater.java:496)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at afm.scheduler.ChatActivity.onCreate(ChatActivity.java:36)
at android.app.Activity.performCreate(Activity.java:7224)
at android.app.Activity.performCreate(Activity.java:7213)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
I/afm.scheduler: ProcessProfilingInfo new_methods=0 is saved saved_to_disk=0 resolve_classes_delay=8000
Process 5241 terminated.
Goal :
I just want be able to use SlidingPaneLayout in my existing AndroidX application.

Just adding "implementation 'androidx.slidingpanelayout:slidingpanelayout:1.1.0'" in your build.gradle file.

Related

How to use a bottom sheet dialog from navigation ui component

I'm using nav graph for internal navigations. Now I want to open a bottom sheet dialog fragment using nav_graph.
I tried adding
<dialog
android:id="#+id/ItemBottomSheetFragment"
android:name="xxxxxxx.fragments.InvoiceItemBottomSheetFragment"
tools:layout="#layout/fragment_invoice_item_bottom_sheet"
android:label="ItemBottomSheetFragment" />
But my app crashes when I launch it.
Crash report
2019-11-23 18:42:13.393 16111-16111/xxxxxxxxxxxxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxxxxxxxxxxxx, PID: 16111
java.lang.RuntimeException: Unable to start activity ComponentInfo{xxxxxxxxxxxxx/xxxxxxxxxxxxx.MainActivity}: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
Caused by: java.lang.RuntimeException: Exception inflating xxxxxxxxxxxxx:navigation/nav_graph line 266
at androidx.navigation.NavInflater.inflate(NavInflater.java:90)
at androidx.navigation.NavController.setGraph(NavController.java:447)
at androidx.navigation.NavController.setGraph(NavController.java:429)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:226)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2528)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:843)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1135)
at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManagerImpl.java:1391)
at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3123)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:134)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:360)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:339)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:537)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
at xxxxxxxxxxxxx.MainActivity.onCreate(MainActivity.kt:19)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
2019-11-23 18:42:13.395 16111-16111/xxxxxxxxxxxxx E/AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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.IllegalStateException: Could not find Navigator with name "dialog". You must call NavController.addNavigator() for each navigation type.
at androidx.navigation.NavigatorProvider.getNavigator(NavigatorProvider.java:98)
at androidx.navigation.NavInflater.inflate(NavInflater.java:100)
at androidx.navigation.NavInflater.inflate(NavInflater.java:132)
at androidx.navigation.NavInflater.inflate(NavInflater.java:81)
Previously I was using navigation UI version 2.0.0
After upgrading to 2.1.0, it's working fine

My app keep closing in the emulator after migrate to androidx. Does anyone have solution for this?

I just migrated to androidx. For some reason, my app keeps crashing whenever I use it in the emulator. I need help
I have been searching on the Internet for hours but have not seen any solution for that. I also examine my logcat but I do not get the error
2019-10-16 18:33:11.287 7763-7763/com.example.recyclerview E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.recyclerview, PID: 7763
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.recyclerview/com.example.recyclerview.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.core.widget.DrawerLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.core.widget.DrawerLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.core.widget.DrawerLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.widget.DrawerLayout" on path: DexPathList[[zip file "/data/app/com.example.recyclerview-gS5TXhudi0GJX8tyIujcvA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.recyclerview-gS5TXhudi0GJX8tyIujcvA==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.recyclerview.MainActivity.onCreate(MainActivity.java:40)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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)
In the activity java and xml file with drawer layout replace androidx.core.widget.DrawerLayou with androidx.drawerlayout.widget.DrawerLayout. If you can't see it directly, use find option and search the string directly.
try to change androidx.core.widget.DrawerLayout with androidx.drawerlayout.widget.DrawerLayout
Your error message says your layout used in com.example.recyclerview.MainActivity.onCreate contains the class androidx.core.widget.DrawerLayout, but the package name for DrawerLayout is androidx.drawerlayout.widget.DrawerLayout. Correct your layout to use the right class name.

New app which Use AndroidX artifacts crash

When creating new app and checking the Use Android X artifacts without modifying anything the app crash bout on my phone and the emulator.
I have asked my friend to repeat method of creating the app and every thing work in his phone.
It is my first time using Android X, Am I doing something wrong? I am running Android Studio 3.3.0.20 in snap (Linux).
2019-02-08 17:54:44.477 5487-5487/worshifter.com.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: worshifter.com.myapplication, PID: 5487
java.lang.RuntimeException: Unable to start activity ComponentInfo{worshifter.com.myapplication/worshifter.com.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at worshifter.com.myapplication.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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.NoClassDefFoundError: Failed resolution of: Landroidx/constraintlayout/widget/R$styleable;
at androidx.constraintlayout.widget.ConstraintLayout.init(ConstraintLayout.java:590)
at androidx.constraintlayout.widget.ConstraintLayout.<init>(ConstraintLayout.java:567)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
at android.view.LayoutInflater.createView(LayoutInflater.java:647) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at worshifter.com.myapplication.MainActivity.onCreate(MainActivity.java:12) 
at android.app.Activity.performCreate(Activity.java:7136) 
at android.app.Activity.performCreate(Activity.java:7127) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
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) 
2019-02-08 17:54:44.478 5487-5487/worshifter.com.myapplication E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.constraintlayout.widget.R$styleable" on path: DexPathList[[zip file "/data/app/worshifter.com.myapplication-gnuqp7fLCQHjhJ5ZKGKRAQ==/base.apk"],nativeLibraryDirectories=[/data/app/worshifter.com.myapplication-gnuqp7fLCQHjhJ5ZKGKRAQ==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 28 more
Edit found out that when removing android.enableJetifier=true the app works.
I have the same issue.
As you see it show in logs: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
You should go to project level build.gradle and update ConstraintLayout to the latest version (and also the good idea update all other dependencies from beta versions):
Default dependencies:
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.core:core-ktx:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
Actual version:
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
Also I created bugreport about this issue:
https://issuetracker.google.com/issues/122892917
The solution is as simple as upgrading the libraries to their latest version in the build.gradle file.
Hint: Use the Android Studio's linting feature to update the libraries to their latest version (Left Alt+Enter on Windows)
I got same error,
My release apk can install to Emulator, Device,
But it crashed.
I check build.gradle file, updated to library to latest version.
Also remove deprecated library, error library, as image in below.
Then, my release apk never got crash when start application as before.

Android Studio: Error inflating class android.support.design.widget.FloatingActionButton

Today I tried to initialize "ChatSDK" and had a few problems. Now, if I want to start my app it is crashing all time. I found this problem:
E/androidRuntime: FATAL EXEPTION: main Process: com.inspredunity.gm.germanminelife, PID: 2605
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.inspredunity.gm.germanminelife/com.inspredunity.gm.germanminelife.MainActivity}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class android.support.design.widget.FloatingActionButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class android.support.design.widget.FloatingActionButton
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class android.support.design.widget.FloatingActionButton
E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.FloatingActionButton" on path: DexPathList[[zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/base.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_resources_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/base.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_dependencies_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_resources_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_0_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_1_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_2_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_3_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_4_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_5_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_6_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_7_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_8_apk.apk!/lib/x86, /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_slice_9_apk.apk!/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
E/AndroidRuntime: at com.inspredunity.gm.germanminelife.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.inspredunity.gm.germanminelife-EdgnsjPOMDBCjzzyKZd6KA==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
Here are my Gradle dependencies:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplemenstation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-inappmessaging-display:17.0.4'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.android.support:design:28.0.0'
implementation 'co.chatsdk.chatsdk:chat-sdk-core:4.4.8'
implementation 'co.chatsdk.chatsdk:chat-sdk-ui:4.4.8'
implementation 'co.chatsdk.chatsdk:chat-sdk-firebase-adapter:4.4.8'
implementation 'co.chatsdk.chatsdk:chat-sdk-firebase-file-storage:4.4.8'
implementation 'com.android.support:recyclerview-v7:28.0.0'
I tired every fix suggestion which I found at the internet but nothing worked. I hope you guys can help me.
If you need my MainActivity or my gradle file(s) please say it!
Thank you in advance!
FIXED
For any person still having this problem after febuary 2019, if you are using androidx or the new material libraries, This problem is happening because Google changed the naming format of the libraries using androidx.. you can check this official mapping https://developer.android.com/jetpack/androidx/migrate/artifact-mappings
and search for your library to see what the new name is, now that Google is in androidx
In your case, your library "android.support.design.widget.FloatingActionButton" in your xml file, is now called as using com.google.android.material.floatingactionbutton.FloatingActionButton
Android Support Library is no longer maintained. It is therefore recommended to use AndroidX Library instead.
FloatingActionButton using AndroidX:
1. Add in gradle:
implementation 'com.google.android.material:material:1.1.0'
2. Add in your layout:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="#drawable/share_button"
android:layout_margin="16dp" />
Did you add android support library to your project? If not try this one :
implementation "com.android.support:design:28.0.0"
For more details about how to setup support library, you can check this
https://developer.android.com/topic/libraries/support-library/setup
Add this into your gradle :
implementation com.android.support:design:28.0.0

Proguard causing runtime exception with Android Navigation Component

I'm experiencing this crash when using proguard after integrating the NavigationComponent (android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha01) into my project with target and compile sdk of 27
2018-05-16 12:13:14.044 24573-24573/com.mypackage.myapp.x E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mypackage.myapp.x, PID: 24573
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage.myapp.x/com.mypackage.myapp.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
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:826)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
Caused by: java.lang.RuntimeException: Exception inflating com.mypackage.myapp.x:navigation/nav_graph line 7
at androidx.navigation.j.a(Unknown Source:124)
at androidx.navigation.d.a(Unknown Source:4)
at androidx.navigation.fragment.NavHostFragment.a(Unknown Source:88)
at android.support.v4.app.Fragment.l(Unknown Source:15)
at android.support.v4.app.m.a(Unknown Source:369)
at android.support.v4.app.m.b(Unknown Source:7)
at android.support.v4.app.m.a(Unknown Source:74)
at android.support.v4.app.m.onCreateView(Unknown Source:216)
at android.support.v4.app.j.a(Unknown Source:4)
at android.support.v4.app.h.a(Unknown Source:2)
at android.support.v4.app.d.onCreateView(Unknown Source:0)
at android.support.v4.app.h.onCreateView(Unknown Source:0)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.b(Unknown Source:23)
at android.support.v7.app.d.setContentView(Unknown Source:4)
at com.mypackage.myapp.MainActivity.onCreate(Unknown Source:12)
at android.app.Activity.performCreate(Activity.java:7130)
at android.app.Activity.performCreate(Activity.java:7121)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1262)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2905)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
at java.lang.reflect.Method.invoke(Native Method)
2018-05-16 12:13:14.044 24573-24573/com.mypackage.myapp.x E/AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mypackage.myapp.fragments.MainFragment
at androidx.navigation.fragment.b$a.a(Unknown Source:58)
at androidx.navigation.fragment.b$a.a(Unknown Source:19)
at androidx.navigation.j.a(Unknown Source:16)
at androidx.navigation.j.a(Unknown Source:133)
at androidx.navigation.j.a(Unknown Source:31)
... 38 more
Caused by: java.lang.ClassNotFoundException: com.mypackage.myapp.fragments.MainFragment
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at androidx.navigation.fragment.b$a.a(Unknown Source:45)
... 42 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mypackage.myapp.fragments.MainFragment" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.mypackage.myapp.x-ysts055HQTtJTv5J2uej3g==/base.apk"],nativeLibraryDirectories=[/data/app/com.mypackage.myapp.x-ysts055HQTtJTv5J2uej3g==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 45 more
It might be because AAPT is not yet producing keep rules for the navigation component?
I know that Proguard and R8 should be keeping all the children of library classes but in this case, the fragment class seems to be missing. This keep rule solved my issue but technically we should not need this rule at all!
-keep class * extends android.support.v4.app.Fragment{}
If you are using AndroidX, then use this rule: -keep class * extends androidx.fragment.app.Fragment{}
If you use argType in your navigation XML, you also need a rule for the referenced classes, for example: -keep class com.example.model.MyModel. Or even better, exclude parcelable and serializable classes from being renamed, as recommended by the official documentation.
-keepnames class * extends android.os.Parcelable
-keepnames class * extends java.io.Serializable
My issue was that I was using the fragment name on the layout. After R8, the names are obfuscated causing the issue.
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent""
app:defaultNavHost="true"
app:navGraph="#navigation/navigation_home" />
In my case, the solution was to keep only the name in the Proguard file, as such:
#-------------------------------------------------
# JetPack Navigation
# This fixes: Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment androidx.navigation.fragment.NavHostFragment: make sure class name exists
#-------------------------------------------------
-keepnames class androidx.navigation.fragment.NavHostFragment
Did face the same issue. The answer above gave me the correct direction to look into.
According to navigation docs
-keep class * extends android.support.v4.app.Fragment{} <-this is not needed
All you need to do is keep names for data classes which are passed via safe args e.g
-keepnames class com.your.package.models.*
This is fixed since Android Gradle Plugin 4.1.
No need to define Proguard rules for fragments defined in the android:name attribute.
See https://issuetracker.google.com/issues/142601969
Same answer as #Antimonit at SO answer. This has been fixed after AGP(Android Gradle Plugin) plugin version 4.1 and onwards.
I also faced similar issue at AGP version 7.2.0 with the similar error message Error inflating class androidx.fragment.app.FragmentContainerView. But in my case there was one data model class which I was using as below which was not kept under the proguard keep flag
<fragment
android:id="#+id/fragment_id"
android:name="com.fragment.FragmentClassName"
android:label="#string/fragment_title"
tools:layout="#layout/fragment_layout">
<argument
android:name="argName"
android:defaultValue="#null"
app:argType="com.model.ArgClass"
app:nullable="true" />
<action
android:id="#+id/action_fragment_id_to_fragment_2_id"
app:destination="#id/fragment_2"
app:popUpTo="#id/fragment_2"
app:popUpToInclusive="true" />
</fragment>
In my case, after application of R8 my class ArgClass was getting renamed and hence my NavHostFragment was crashing
Adding #Keep annotation like below fixed the issue in my case
import androidx.annotation.Keep
#Keep data class ArgClass(val id: String)
This is also documented in Android official doc

Categories

Resources