I am developing a library for Android, and this library has some activities with its layouts.
In the layout, I have the next code
...
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.floatingactionbutton.FloatingActionButton
...
I am using Androidx.
An I get the following error:
Error inflating class android.support.constraint.ConstraintLayout
The first attempt to solve this was to changeandroid.support.constraint.ConstraintLayout to androidx.constraintlayout.widget.ConstraintLayout
But when I do this I get the following error:
androidx.constraintlayout.widget.ConstraintLayout cannot be cast to
androidx.constraintlayout.widget.Group
So I try to change to androidx.constraintlayout.widget.Group
I get the following error:
androidx.constraintlayout.widget.Group cannot be cast to
android.view.ViewGroup
I did a refactor again to androidx and then I get the following error:
Didn't find class "androidx.constraintlayout.ConstraintLayout"
Any idea?
Thanks
Follow this steps
First add below dependencies in your Build.Gradle file
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
Use this ConstraintLayout like this
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content">
</androidx.constraintlayout.widget.ConstraintLayout>
Make sure you have correct imports of ConstraintLayout for in your activity if you have used
import androidx.constraintlayout.widget.ConstraintLayout
Related
After migration to AndroidX my app crashes after calling Snackbar.make() method. The error looks like
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.internal.SnackbarContentLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.internal.SnackbarContentLayout"
It's strange that internal Snackbar method make() is still trying to access SnackbarContentLayout class in old support package instead new material's one. Please advice what I'm doing wrong.
UPDATE
Finally I found a solution. There is a custom layout in my project which overrides
Snackbar's design_layout_snackbar_include and it had wrong class in root view tag:
<view
xmlns:android="http://schemas.android.com/apk/res/android"
class="android.support.design.internal.SnackbarContentLayout"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
I changed it to com.google.android.material.snackbar.SnackbarContentLayout
ensure that your project is set up to migrate old packages to Androidx by including this in your gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
I'm trying to transition from using a FrameLayout to using FragmentContainerView and from the tutorials I've seen, it should be pretty easy. However, when I run my app after making the change, I get
Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: java.lang.ClassNotFoundException: androidx.fragment.app.FragmentContainerView
my layout file is pretty simple:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="#layout/app_bar_main">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragment_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Do I need to add something into my build.gradle or something? Why can't it find the class?
That's in androidx.fragment 1.2.0 or higher:
implementation "androidx.fragment:fragment:1.2.0"
Thanks to #Salam El-Banna and his link, I found that in case an application crashes in release build we should add in proguard-rules.pro (one or two lines, depending on android:name in <FragmentContainerView>:
#-------------------------------------------------
# JetPack Navigation
# This fixes:
# Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment androidx.navigation.fragment.NavHostFragment: make sure class name exists
# Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists
#-------------------------------------------------
-keepnames class androidx.navigation.fragment.NavHostFragment
-keepnames class com.google.android.gms.maps.SupportMapFragment
Make sure their are no custom constructors like this.
ex:
FragmentName (val ctx: Context): Fragment() {
change to
FragmentName: Fragment() {
The reason is when the inflater inflates FrgmentContainer, it calls default constructor to initialize the fragments. If their is no default constructor available, it will crash.
If you are using kotlin the latest FragmentContainerView implementation stays under:
implementation("androidx.fragment:fragment-ktx:1.3.6")
I'm trying to change a ConstraintLayout to RelativeLayout in XML. Every time I do, I get the Missing Classes error:
The following classes could not be found: android.support.constraint.RelativeLayout
What am I missing?
RelativeLayout is not inside that package, you should use :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
Or if you are importing inside your class:
import android.widget.RelativeLayout;
Problem is that just I can't user overlayTop but I've got Support Design Library 23.1 included and every component usable just this one not
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/nes_scroll"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:behavior_overlayTop="44dp">
...
and here's error:
Error:(50) No resource identifier found for attribute behavior_overlayTop in package com.scroll.example
also it's not usable in Java source too, it's just red line and offers to create class related to setOverlapTop().
I'm trying to use TextInputLayout in my XML, and I'm meeting this error :
java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.jechange.moncompte/fr.jechange.moncompte.SignUpActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.design.widget.TextInputLayout
[...]
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.design.widget.TextInputLayout
[...]
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/design/R$styleable;
I've imported the design library, and the support-v7-appcompat library. And I'm using the Theme.AppCompat.Light.NoActionBar theme.
The XML in which I'm using the Text Input Layout contains just something like that:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:res="http://schemas.android.com/apk/res-auto"
style="#style/matchParent">
<android.support.design.widget.TextInputLayout
android:id="#+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
if you are calling layout(containg TextInputLayout) from activity then
nothing just use YouActivityClassName.this in place of getApplicationcontext or YourApplicationClassName.getcontext() or other where you are passing context
I had the same issue fixed here.
Make sure you don't have any other support library import v4 and v7. You can use only the design-support library. Also you should make sure your theme "matchParent" inherit from Theme.AppCompat for all the platform you trying to run.
My issue was only on Lollipop because of the values-21/style.xml.
Hope it will help.