android - 将“FlexBoxLayout”添加到项目会中断编译
问题描述
我正在尝试FlexBoxLayout
在我的应用程序中使用,但我不断遇到错误。我尝试了各种设置和配置,但不断出现不同的错误。我现在拥有的:
build.gradle(应用程序):
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.android:flexbox:1.1.0'
implementation "androidx.appcompat:appcompat:1.0.0"
}
这给了我错误:
清单合并失败:来自 [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 的属性 application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) 也存在于[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory)。建议:将 'tools:replace="android:appComponentFactory"' 添加到 AndroidManifest.xml:23:5-131:19 的元素以覆盖。
当我将它添加tools:replace="android:appComponentFactory"'
到我的清单时,我遇到了以下问题:
清单合并失败并出现多个错误,请参阅日志
这就是我放弃的地方,我什至不知道要看什么日志。
当我只添加flexbox
到依赖项时更新NoClassDefFoundError
,应用程序在androidx.core.view.ViewCompat
类上崩溃。
解决方案
有几个步骤可以实现这一点:
1 在项目结构中更新 gradle 版本到最新
2 在应用程序的 build.gradle 集compileSdkVersion 28
和依赖项中,androidx
根据https://developer.android.com/jetpack/androidx/migrate将库转换为
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android:flexbox:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
3 同步项目和重建
4 转到您的活动课程。一切都将带有红色下划线,并且导入将变灰。删除灰显的导入。并使用新的导入路径导入其余部分,该路径将包含androidx
. 请记住,xml 布局中的所有小部件也必须更改。这很容易找到,因为当您运行您的应用程序时,您将收到类似以下的错误:
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.CoordinatorLayout" on path: DexPathList[[zip file "/data/app/com.example.mimok.flexbox2-1/base.apk",
在这种情况下,我的路径错误CoordinatorLayout
,应该更改为<androidx.coordinatorlayout.widget.CoordinatorLayout>
.
推荐阅读
- c# - 由于包不兼容,添加迁移失败
- cassandra - 为什么连接经常超时
- mysql - 获取最佳射手名单
- axon - Axon 框架:微服务应该共享事件吗?
- python - 为什么我收到这两个错误?[wkhtmltoimage]
- linux - 安装和配置 virtualenv 和 python (Linux)
- java - Java - 使用 JTable 显示数组
- sql-server - SQL Server - 按给定日期拆分日期范围
- php - Change input number by step on button click
- javascript - I m confused with Object.entries()[i]