android - 将 "FlexBoxLayout"添加到项目会中断编译

标签 android 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"
}

这给了我错误:

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

当我将 tools:replace="android:appComponentFactory"' 添加到我的 list 时,出现以下问题:

Manifest merger failed with multiple errors, see logs

这就是我有点放弃的地方,我什至不知道该看什么日志。

更新 当我只将 flexbox 添加到依赖项时,应用程序崩溃并在 androidx.core.view 上出现 NoClassDefFoundError .ViewCompat 类。

最佳答案

实现这一目标的步骤很少:

1 在项目结构中更新gradle版本到最新

enter image description here

2 在app的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 转到您的 Activity 类。一切都将带有红色下划线,导入将显示为灰色。删除灰色的导入。并使用包含 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> .

关于android - 将 "FlexBoxLayout"添加到项目会中断编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52629918/

相关文章:

android - Activity 未完成

android - AnimatedVectorDrawable 没有动画

android - 如何在Kotlin中为Android应用程序生成protobuf?

android - 计算 flexbox 中的行数

Android,在 RecyclerView 的每个项目下显示一个阴影(没有边距填充)

android - StaggeredLayout 与 FlexboxLayoutManager

android - 以编程方式设置 FlexboxLayout 的属性 layout_wrapbefore

android - Room Kotlin 找不到现场的二传手

Android自定义图库 View ,设置自己的边框

android - 在 FlexboxLayout 中换行