将 "FlexBoxLayout" 添加到项目会中断编译
Adding "FlexBoxLayout" to a project breaks compilation
我正在尝试在我的应用程序中使用 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"'
添加到我的清单时,出现以下问题:
Manifest merger failed with multiple errors, see logs
这就是我有点放弃的地方,我什至不知道该看什么日志。
Update 当我仅将 flexbox
添加到依赖项时,应用程序崩溃并在 androidx.core.view.ViewCompat
[=34= 上出现 NoClassDefFoundError
].
尝试:
change
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:appcompat-v7:28.0.0'
to
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
您可以阅读此内容 here。
此外,我建议您在 Android Studio 3.2 中转到 Refactor->Refactor to AndroidX
如果适合您,请在此处更新。
实现这个的步骤很少:
1 在项目结构更新gradle 版本到最新
2 在应用程序的 build.gradle 中设置 compileSdkVersion 28
并在依赖项中根据 https://developer.android.com/jetpack/androidx/migrate
将库转换为 androidx
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 class。一切都将带有红色下划线,导入将显示为灰色。删除灰色的导入。并使用包含 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>
。
我正在尝试在我的应用程序中使用 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"'
添加到我的清单时,出现以下问题:
Manifest merger failed with multiple errors, see logs
这就是我有点放弃的地方,我什至不知道该看什么日志。
Update 当我仅将 flexbox
添加到依赖项时,应用程序崩溃并在 androidx.core.view.ViewCompat
[=34= 上出现 NoClassDefFoundError
].
尝试:
change
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:appcompat-v7:28.0.0'
to
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
您可以阅读此内容 here。 此外,我建议您在 Android Studio 3.2 中转到 Refactor->Refactor to AndroidX
如果适合您,请在此处更新。
实现这个的步骤很少:
1 在项目结构更新gradle 版本到最新
2 在应用程序的 build.gradle 中设置 compileSdkVersion 28
并在依赖项中根据 https://developer.android.com/jetpack/androidx/migrate
androidx
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 class。一切都将带有红色下划线,导入将显示为灰色。删除灰色的导入。并使用包含 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>
。