我将RecycleView添加到XML中,如下所示:
<androidx.recyclerview
android:id="@+id/recycleViewTest"
android:layout_width="match_parent"
android:layout_height="match_parent" />我在build.gradle中的依赖项定义如下:
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"
}该项目编译,但当我运行它时它会崩溃,并得到以下异常:
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/我的compileSdkVersion设置为28。有什么建议吗?
更新:
我添加了依赖项:
implementation 'com.android.support:recyclerview-v7:28.0.0-beta01'因此,我的依赖部分现在如下所示:
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'
}但现在我又犯了一个新错误:
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.因此,我添加了以下属性:
tools:replace="android:appComponentFactory"到应用程序标记,如下所示:
<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">但现在我又犯了一个错误:
Manifest merger failed with multiple errors, see logs发布于 2018-07-31 20:34:11
androidx.recyclerview是一个包名,您需要视图的package+classname来通过XML来膨胀它,我查找了您,但是包androidx.recyclerview现在有视图了。
如果您打算使用RecyclerView ( https://developer.android.com/guide/topics/ui/layout/recyclerview )
正确的gradle语句是:
implementation 'com.android.support:recyclerview-v7:27.1.1'XML标记是:
android.support.v7.widget.RecyclerView发布于 2018-12-20 08:24:43
如果您切换到AndroidX,则需要更改
android.useAndroidX = true与android.enableJetifier = true in gradle.properties对于以前属于支持库的所有部分来说,都是一致的。你不能把支持库和androidx混为一谈,否则Manifest合并会像你一样抱怨。
若要特别切换RecycleView,请更改
implementation 'androidx.recyclerview:recyclerview:1.0.0'的依赖androidx.recyclerview.widget.RecyclerView的XML布局文件标记映射可以在“向AndroidX迁移”指南这里中找到。
https://stackoverflow.com/questions/51621519
复制相似问题