Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx - android

I just made a migration to androidx through Android Studio menu option Refactor -> Refactor to AndroidX
I'm getting the following error:
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
Any idea?
Stacktrace:
2018-10-19 00:25:58.128 28131-28131/com.midounoo.midounoo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.midounoo.midounoo, PID: 28131
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.midounoo.midounoo/com.midounoo.midounoo.Base.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6255)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.constraintlayout.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.midounoo.midounoo-2/base.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.midounoo.midounoo-2/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:609)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.midounoo.midounoo.Base.MainActivity.onCreate(MainActivity.java:43)
at android.app.Activity.performCreate(Activity.java:6666)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6255)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)

I solve my problem by changing all occurrences of
androidx.constraintlayout.ConstraintLayout
to
androidx.constraintlayout.widget.ConstraintLayout

Add androidx.constraintlayout.widget.ConstraintLayout to the dependencies:
dependencies {
// https://mvnrepository.com/artifact/androidx.constraintlayout/constraintlayout
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}
It's available on mavenCentral().

I had the same problem, I resolved it as follows:
In your dependecies if you have added
implementation 'androidx.constraintlayout:constraintlayout:1.x.x' that is correct
but in your xml layout file you have to use the widget as
androidx.constraintlayout.widget.ConstraintLayout

build.gradle => check dependencies version
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
to change
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
solved the problem

I has same issue after:
migration support library to androidx;
increment targetSdkVesrsion to 29;
I also use:
implementation "uk.co.chrisjenx:calligraphy:2.3.0"
I tried all posts from this question, but none success.
I fix it by adding one string .disableCustomViewInflation() to Calligraphy init:
#Override
public void onCreate() {
super.onCreate();
// ...
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/Sans-Regular.ttf")
.setFontAttrId(R.attr.fontPath)
.disableCustomViewInflation() // <----- this fix
.build());
// ...
}
I hope next release of Calligraphy (Christopher Jenkins thanks for your great job) will fix it inside too.

If after adding mavenCentral() as a repository in your Gradle file and changing androidx.constraintlayout.ConstraintLayout to androidx.constraintlayout.widget.ConstraintLayout didn't solve your problem then try doing Invalidate cache and restart from the file menu. It worked for me.

make sure your project migrate to androidx completely , In my case I found :
<android.support.constraint.ConstraintLayout
instead of
<androidx.constraintlayout.widget.ConstraintLayout
So change it and my problem fixed!

After clicking on Refactor -> Migrate to AndroidX , Make sure your all dependencies in the build.gradle(Module:app) is marked to the newest version.
If its not, dependency will appear in yellow highlighted color and you can change it by hovering the mouse over it.
Secondly,
Change the ConstraintLayout tag in all XML layout files to
androidx.constraintlayout.widget.ConstraintLayout
For more safer option, clean your project and sync it again after the above steps.

Make Sure you have added the dependency for constraint layout
dependencies {
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}
and have made the changes to
<androidx.constraintlayout.widget.ConstraintLayout instead of
<android.support.constraint.ConstraintLayout

I copied and pasted an existing ConstraintLayout tag from the xml, which was causing the issue for me. Simply deleting, and re-adding the ConstraintLayout tags in AndroidStudio from scratch fixed the issue for me.

Make sure to change to
<androidx.constraintlayout.widget.ConstraintLayout
instead of
<android.support.constraint.ConstraintLayout
and
<androidx.constraintlayout.widget.Barrier
instead of
<android.support.constraint.Barrier

I had this issue with Android Studio 4.0. I used android studio 4.0 for a couple of days without problems. Seemingly out of nowhere the designer view stopped working.
I could only fix this by uninstalling android studio and installing the newest android studio version.

Since my implementation was already androidx.constraintlayout.ConstraintLayout, just using a Clean Project solved my problem.

yepp.
mavenCentral() and correct dependencies solve my same problems

I had a similar error.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.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:2757)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2818)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6393)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
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:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:652)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:812)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.myapp.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:6858)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2710)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2818)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6393)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
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)
... 23 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.constraintlayout.widget.R$styleable" on path: DexPathList[[zip file "/data/app/com.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 25
Following the recomendations:
add androidx.constraintlayout.ConstraintLayout to the dependencies:
dependencies {
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}
And the repository mavenCentral().
Works for me. I could compile the APK.

I updated the dependency, yet it did not resolve the error.
Then I did a clean project and build and it is working now.

Find all default before to click Refactor -> Refactor to AndroidX
Open this https://developer.android.com/jetpack/androidx/migrate/class-mappings and find "android.support.v4.widget.DrawerLayout". In same line AndroidX class name is "androidx.drawerlayout.widget.DrawerLayout" copy it.
Replace all "android.support.v4.widget.DrawerLayout" to "androidx.drawerlayout.widget.DrawerLayout" in your project"s code, layout and menu. After all replace it will work.
I mean find mapping and use it in whole project.

change your constraint layout dependancy to implementation 'androidx.constraintlayout:constraintlayout:2.0.2'

None of the solution worked for me, looking closely at the exception stack trace:
Caused by: android.content.res.Resources$NotFoundException: Resource "com.XXX.XXX:drawable/walpaper" (7f0800aa) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0800aa a=-1 r=0x7f0800aa}
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2690)
at android.content.res.Resources.loadDrawable(Resources.java:2614)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3791)
at android.view.ViewGroup.<init>(ViewGroup.java:524)
at android.view.ViewGroup.<init>(ViewGroup.java:520)
at android.view.ViewGroup.<init>(ViewGroup.java:516)
drawable background image loading was causing some issue on my old test device (newer devices load it just fine). Just removed the following line from my layouts it is working fine now, need to figure out how to set the background now..
android:background="#drawable/walpaper"

I had the issue with ImageFilterView converting jpg images to png solved the issue for me.

Related

Error inflating class after migration to androidx

I made a migration to Androidx but after the migration, I'm getting the following error:
Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
I studied all the resources and migrated to Androidx, but I still have a lot of problems.
Can someone help me?
I will post the sections of the code below.
--------- beginning of crash ---------
2019-01-23 09:47:34.171 17578-17578/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: ir.bijac.com.bijac, PID: 17578
java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.bijac.com.bijac/ir.bijac.com.bijac.TestActivity}: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at ir.bijac.com.bijac.BaseActivity.onCreate(BaseActivity.java:43)
at ir.bijac.com.bijac.TestActivity.onCreate(TestActivity.java:22)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/coreui/R$attr;
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:202)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at ir.bijac.com.bijac.BaseActivity.onCreate(BaseActivity.java:43) 
at ir.bijac.com.bijac.TestActivity.onCreate(TestActivity.java:22) 
at android.app.Activity.performCreate(Activity.java:6679) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
2019-01-23 09:47:34.171 17578-17578/? E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.coreui.R$attr" on path: DexPathList[[zip file "/data/app/ir.bijac.com.bijac-2/base.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_dependencies_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_0_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_1_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_2_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_3_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_4_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_5_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_6_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_7_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_8_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/ir.bijac.com.bijac-2/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 27 more
build gradle:
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 28
defaultConfig {
applicationId "ir.bijac.com.bijac"
minSdkVersion 18
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestUtil 'androidx.test:orchestrator:1.1.1'
configurations.all { resolutionStrategy.force 'com.android.support:support-v4:28.0.0' }
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'com.daimajia.slider:library:1.1.5#aar'
implementation "cz.msebera.android:httpclient:4.4.1.2"
implementation 'org.apache.httpcomponents:httpcore:4.4.10'
implementation 'com.androidadvance:topsnackbar:1.1.1'
implementation 'co.ronash.android:pushe-base:1.4.1'
implementation 'com.google.android.gms:play-services-gcm:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.4#aar') {
transitive = true;
}
}
--------- activity_main.xml ---------
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
You are likely to have a reference to android.support.design.widget.CoordinatorLayout in some of your xml layout files.
Press CTRL + SHIFT + F or go to Edit/Find/Find in Path and just search for android.support.design.widget.CoordinatorLayout and replace it with androidx.coordinatorlayout.widget.CoordinatorLayout.
You may use CTRL + SHIFT + R or Edit/Find/Replace in Path instead to replace all matches at once.
in XML file, replace
androidx.appcompat.widget.RecyclerView
with:
androidx.recyclerview.widget.RecyclerView
It looks like app is trying to inflate android.support.design.widget.CoordinatorLayout from support library instead of androidx library. Try doing following things and check if it works.
Do clean and build your app.
Try Invalidate Cache and Restart.
Also make sure you are not using coordinator layout from support library anywhere else.
Make sure in your activities and fragments there is no reference to the old support libraries in the imports section.Make sure all layouts are not using the ols support widgets too.
Add these two lines in gradle.properties file to automatically migrate existing project to Androix.
android.useAndroidX=true
android.enableJetifier=true
more info here -> https://developer.android.com/jetpack/androidx/migrate
this will automatically solve ur problem.
Simply Just go to XML file (in `res/layout) and replace
androidx.appcompat.widget.RecyclerView
with:
androidx.recyclerview.widget.RecyclerView
You have to replace all android.support.design classes with new classes of AndroidX. Here are the links with the correspondences between old and new classes:
https://developer.android.com/jetpack/androidx/migrate/artifact-mappings
https://developer.android.com/jetpack/androidx/migrate/class-mappings
Fore more you can read the guide how to migrate to AndroidX:
https://developer.android.com/jetpack/androidx/migrate
Edit --> Find --> Find in Path
Replace all of following
android.support.v7.widget.CardView
--> androidx.cardview.widget.CardView
android.support.design.widget.TextInputLayout
--> com.google.android.material.textfield.TextInputLayout
android.support.v4.widget.NestedScrollView
--> androidx.core.widget.NestedScrollView
android.support.v4.view.ViewPager
--> androidx.viewpager.widget.ViewPager
androidx.constraintlayout.ConstraintLayout
--> androidx.constraintlayout.widget.ConstraintLayout
androidx.core.view.ViewPager
--> androidx.viewpager.widget.ViewPager
androidx.core.widget.SwipeRefreshLayout
--> androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android.support.design.widget.AppBarLayout
--> com.google.android.material.appbar.AppBarLayout
android.support.design.widget.CollapsingToolbarLayout
--> com.google.android.material.appbar.CollapsingToolbarLayout
android.support.v7.widget.Toolbar
--> androidx.appcompat.widget.Toolbar

Error inflating class android.support.design.widget.CoordinatorLayout after migration to androidx

I just made a migration to Androidx but after the migration, I'm getting the following error:
Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout`
Any idea?
Stacktrace:
Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at ir.bijac.com.bijac.BaseActivity.onCreate(BaseActivity.java:43)
at ir.bijac.com.bijac.TestActivity.onCreate(TestActivity.java:22)
compileSdkVersion 28
minSdkVersion 18
targetSdkVersion 28
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
} ```
I had a similar experience after migrating to Androidx. I resolved the issue following these steps:
[1]
Ensure that the layout file uses this
<androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
[2]
Follow this step if Android studio did not change the support libraries imports after migration to Androidx.
Go to the class file(java or kt), DELETE all imports related to the former libraries and allow Android Studio to import the appropriate Androidx libraries. Do these for all other migration issues.
This is what your dependencies should look like:
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.drawerlayout:drawerlayout:1.0.0' //DrawerLayout
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
implementation 'com.google.android.material:material:1.0.0' //androidx AppBarLayout, CollapsingToolbarLayout etc.
implementation 'androidx.webkit:webkit:1.0.0' //androidx webview
Do you by any chance have some forgotten layout-land directory or something? Which maybe contains some XML files the migration skipped over. I just discovered that this is what happened in my project. (maybe inside a different falvor?)

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

App SDK migration from 27.0.2 to 27.1.0 failed (crash)

I've just upgraded my Gradle this morning with the new SDK:
// https://developer.android.com/studio/build/multidex.html
implementation 'com.android.support:multidex:1.0.3'
// https://developer.android.com/topic/libraries/support-library/revisions.html
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:customtabs:27.1.0'
implementation 'com.android.support:gridlayout-v7:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:support-v13:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:exifinterface:27.1.0'
Unfortunately now there is a crash during my first Activity starts. This Activity has not layout. It worked perfectly before this SDK upgrade...
03-06 10:20:33.117 18722-18722/com.xxx.dev E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.azeoo.dev, PID: 18722
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.dev/com.xxx.ui.intro.WelcomeActivity}: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class LinearLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class LinearLayout
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class LinearLayout
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
at android.content.res.TypedArray.getString(TypedArray.java:202)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1006)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at com.android.internal.policy.DecorView.onResourcesLoaded(DecorView.java:1776)
at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2613)
at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2686)
at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2049)
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
at android.support.v7.app.AppCompatDelegateImplV9.initWindowDecorActionBar(AppCompatDelegateImplV9.java:175)
at android.support.v7.app.AppCompatDelegateImplBase.getSupportActionBar(AppCompatDelegateImplBase.java:145)
at android.support.v7.app.AppCompatActivity.getSupportActionBar(AppCompatActivity.java:109)
at com.xxx.ui.BaseActivity.onCreate(BaseActivity.java:759)
at com.xxx.ui.intro.WelcomeActivity.onCreate(WelcomeActivity.java:45)
at android.app.Activity.performCreate(Activity.java:6672)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Thank you very much guys for your support!
Remove your
buildToolsVersion from your app-level gradle file in case you want to upgrade to 27.1.0. So if you put
buildToolsVersion 27.0.2
or buildToolsVersion 27.0.3
there might be a conflict cause buildToolsVersion 27.1.0 is not released yet.
So, removing the buildToolsVersion x.x.x might do the trick !!
Edit 1
Even though removing buildToolsVersion might work, i would recommend to stick to 27.0.2 because 27.1.0 is causing some undesired crashes and has a few bugs.
One of which is :-
java.lang.ClassCastException: android.support.v7.widget.ActivityChooserView$InnerLayout cannot be cast to android.support.v7.widget.LinearLayoutCompat
Even google has announced it ( in GOOGLE ISSUE TRACKER ). So , guys better stick to 27.0.2 untill the fixed and stable version is released.

Error when setting contentscrim color on CollapsingToolbarLayout

My app recently started to crash on any activity or fragment that has a CollapsingToolbarLayout with the following error log:
`
Unable to start activity ComponentInfo{com.radioafrica.music/com.radioafrica.music.activity.PlaylistTracks}: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class android.support.design.widget.CollapsingToolbarLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NoSuchMethodError: No static method setLayoutDirection(Landroid/graphics/drawable/Drawable;I)V in class Landroid/support/v4/graphics/drawable/DrawableCompat; or its super classes (declaration of 'android.support.v4.graphics.drawable.DrawableCompat' appears in /data/data/com.radioafrica.music/files/instant-run/dex/slice-com.android.support-support-v4-24.0.0-beta1_f8cf3ba4c70f87f407a745b9fa14a2205d0b587c-classes.dex)
at android.support.design.widget.CollapsingToolbarLayout.setStatusBarScrim(CollapsingToolbarLayout.java:663)
at android.support.design.widget
`
When i comment out collapsingToolbarLayout.setStatusBarScrim(color); , it works fine, but the downside is that i cant set a scrim color and the title doesnt show on the toolbar. Is this a bug with the support library?
I managed to get rid of the error by going through my build.gradle file and removing any dependency that might have another version of the v4 support library. It seems that the conflicting versions of the libraries were the problem.
I got the same error and long time stared on my dependencies versions.
Then I try remove this line and everything works fine. But I do’t understand the reason, sorry.
compile "com.android.support:support-v4:+

Categories

Resources