I am trying to use FlexBoxLayout
in my app, but I am running into errors continuously. I have tried all kinds of settings and configs, but different errors keep popping up. What I have now:
build.gradle (app):
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"
}
And this gives me the error:
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.
When I add that tools:replace="android:appComponentFactory"'
to my Manifest, I get the following problem:
Manifest merger failed with multiple errors, see logs
And that is where I kind of give up, I don't even know what logs to go look at.
Update when I only add flexbox
to the dependencies, the app crashes with a NoClassDefFoundError
on the androidx.core.view.ViewCompat
class.
There are few steps to achieve this:
1 In project structure update gradle version to the newest
2 In app's build.gradle set compileSdkVersion 28
and in dependencies convert libs to androidx
according to 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 Sync project & Rebuild
4 Go to Your Activity class. Everything will be with red underline and imports will be grayed out. Remove grayed out imports. And import the rest with new import path which will contains androidx
. Bear in mind that all widgets in xml layouts have to be changed too. It will be easy to find because when You run Your app You will get error similar to this:
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",
At this case I have wrong path to CoordinatorLayout
which should be changed to <androidx.coordinatorlayout.widget.CoordinatorLayout>
.