2

I'm added the RecycleView to my XML like this:

    <androidx.recyclerview
        android:id="@+id/recycleViewTest"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

My dependencies in build.gradle are defined like this:

dependencies
{
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.android.material:material:1.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation "androidx.recyclerview:recyclerview:1.0.0-alpha1"
}

The project compiles, but it crashes when I run it and I get the following exception:

Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class androidx.recyclerview
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class androidx.recyclerview
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.recyclerview" on path: DexPathList[[zip file "/data/app/

My compileSdkVersion is set to 28. Any suggestions please?

UPDATE:

I added to the dependencies:

 implementation 'com.android.support:recyclerview-v7:28.0.0-beta01'

So my dependency section look like this now:

    dependencies
    {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation 'com.google.android.material:material:1.0.0-alpha1'
        implementation 'com.android.support.constraint:constraint-layout:1.1.0'
        implementation 'com.android.support:recyclerview-v7:28.0.0-beta01'
    }

But now I'm getting a new error:

Manifest merger failed : Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.0.0-alpha1] AndroidManifest.xml:22:18-86
is also present at [com.android.support:support-compat:28.0.0-beta01] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:6:5-21:19 to override.

So I added the following attribute:

tools:replace="android:appComponentFactory"

To the the application tag like this:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    tools:replace="android:appComponentFactory"
    android:theme="@style/AppTheme">

But now I'm getting another error:

Manifest merger failed with multiple errors, see logs
0x29a
  • 733
  • 1
  • 7
  • 23

2 Answers2

3

androidx.recyclerview is a package name, you need the package+classname of a View to inflate it trough XML, I looked for you but the package androidx.recyclerview has now views.

If you intended to use the RecyclerView ( https://developer.android.com/guide/topics/ui/layout/recyclerview )

The correct gradle statement is:

implementation 'com.android.support:recyclerview-v7:27.1.1'

and the XML tag is:

android.support.v7.widget.RecyclerView
Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • 1
    Thanks, will try in a second. Strangely when I changed "androidx.recyclerview" to "androidx.recyclerview.widget.RecyclerView" in the xml, it worked – 0x29a Jul 31 '18 at 20:35
  • That what I was talking about the ```androidx.recyclerview``` is a package and you need the full name for a view. Only that I noticed that the library you tryint to use is still alpha and still not ready for production. Try to use the old support one until it becomes stable. – Marcos Vasconcelos Jul 31 '18 at 20:37
  • Clear, thanks! I added the library you proposed, but I'm getting a new error, could you please check? I updated my question – 0x29a Jul 31 '18 at 20:45
  • You must remove the other one "androidx" – Marcos Vasconcelos Jul 31 '18 at 20:56
  • It was already removed, I updated my question with the dependency list I currently have, thanks! – 0x29a Jul 31 '18 at 21:02
  • Stop using betas and alphas, search the released ones and use the same version for all – Marcos Vasconcelos Jul 31 '18 at 21:11
2

If you switch to AndroidX, you need to change

  1. android.useAndroidX = true and android.enableJetifier = true in gradle.properties
  2. the dependencies in build.gradle
  3. the imports in Java
  4. the class names in Java and layout XML files

consistently and for all parts that did belong to the support library before. You cannot mix support library with androidx, otherwise the Manifest merger will complain as in your case.

To switch the RecycleView in particular, change

  • dependency to implementation 'androidx.recyclerview:recyclerview:1.0.0'
  • XML layout file tag to androidx.recyclerview.widget.RecyclerView

mappings can be found in "Migration to AndroidX" guide here.

  • Thank you. This should be accepted answer because it correctly uses AndroidX instead of using appcompat-v7. – WSBT May 01 '19 at 00:03