Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Program type already present: android.support.v4.os.ResultReceiver

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'
like image 358
Tianheng Liu Avatar asked Dec 02 '25 10:12

Tianheng Liu


2 Answers

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
like image 161
dirkvranckaert Avatar answered Dec 05 '25 00:12

dirkvranckaert


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

like image 23
TomV Avatar answered Dec 05 '25 01:12

TomV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!