Reputation: 2760
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)
Upvotes: 91
Views: 56145
Reputation: 3
In my case, the issue was resolved by correctly setting the colors in the application. We carefully monitor the API version in each color used and simply change the color in case of a version higher than the minimum allowed. In the attributes, select Pick a Resource of the color that you want to check and pay attention here: check API version
Upvotes: 0
Reputation: 452
I had the issue with ImageFilterView converting jpg images to png solved the issue for me.
Upvotes: 0
Reputation: 131
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"
Upvotes: 0
Reputation: 2189
Since my implementation was already androidx.constraintlayout.ConstraintLayout
, just using a Clean Project solved my problem.
Upvotes: 1
Reputation: 515
change your constraint layout dependancy to implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
Upvotes: 0
Reputation: 1487
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.
Upvotes: 1
Reputation: 2367
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
Upvotes: 2
Reputation: 1854
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
Upvotes: 1
Reputation: 76679
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()
.
Upvotes: 51
Reputation: 7220
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!
Upvotes: 5
Reputation: 2299
I mean find mapping and use it in whole project.
Upvotes: 0
Reputation: 1410
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
Upvotes: 10
Reputation: 470
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.
Upvotes: 1
Reputation: 1253
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.
Upvotes: 4
Reputation: 4857
I has same issue after:
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.
Upvotes: 6
Reputation: 2355
I updated the dependency, yet it did not resolve the error. Then I did a clean project and build and it is working now.
Upvotes: 0
Reputation: 106
build.gradle => check dependencies version
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
to change
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
solved the problem
Upvotes: 7
Reputation: 121
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.
Upvotes: 0
Reputation: 4287
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.
Upvotes: 5
Reputation: 2760
I solve my problem by changing all occurrences of
androidx.constraintlayout.ConstraintLayout
to
androidx.constraintlayout.widget.ConstraintLayout
Upvotes: 184
Reputation: 1046
yepp. mavenCentral() and correct dependencies solve my same problems
Upvotes: 0