Reputation: 31
Got this error when I try to connect my app to Firebase.
Below are the dependencies in app/build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
implementation 'com.google.firebase:firebase-core:16.0.0'
}
apply plugin: 'com.google.gms.google-services'
Upvotes: 3
Views: 4472
Reputation: 1232
The error is because there are duplicate libraries in the project, as a result of using androidx along with the older support libraries. You can either manually go through the code base and change the necessary import lines, or let Android Studio do the work:
In Android Studio, right click on app director. Refactor -> Migrate to Android X
Upvotes: 1
Reputation: 1464
Just started a new project in Android studio targetting the latest Android version. Studio generated all the dependencies with androidx, however I've added databinding myself using adding this block in my build.gradle file:
android {
dataBinding {
enabled = true
}
}
But then I started seeing these errors:
Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
Checking the Gradle dependency-tree learned me that MyResultReceiver came in through an androidx.core dependency but also through some app-compat dependency that came in through the non-androidx databinding library.
The answer from @kamarudeen-ayankunbi seems to solve this indeed. If you read the docs (https://developer.android.com/topic/libraries/support-library/androidx-overview) Google event states that after starting a new project in Android studio targetting the latest API and using androidx that you should add those two properties to your gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
Upvotes: 5