Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback

I completely new to Android Development and can't seem to resolve this error: "Error: Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback"

This is my dependencies:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1'
implementation "android.arch.navigation:navigation-fragment:1.0.0-alpha01"
implementation "android.arch.navigation:navigation-ui:1.0.0-alpha01"


androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
testImplementation 'junit:junit:4.12'
}

I've googled some and ended up on the developer page about "Resolve duplicate class errors", but I'm still not able to fix this. Help would be very much appriciated!

question from:https://stackoverflow.com/questions/51389533/program-type-already-present-android-support-v4-media-mediabrowsercompatcustom

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Option 1

Following worked for me Add the following in your gradle.properties file

android.useAndroidX = true
android.enableJetifier = false

Option 2 (if above does't work)

  1. Android studio -> Navigate -> Class
  2. Check include non-project classes
  3. Copy full class path android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat
  4. See where it is used. You may need to remove, one of them.

Option 3 you might be including package which is including modules as well so exclude the support-v4 module with following method

implementation ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
      exclude group: 'com.android.support', module:'support-v4'
}

You can analyze the conflicting modules using ./gradlew :YOURPROJECT:dependencies from a command line in your project repository. Check especially your third party libraries for occurences of "com.android.support-":

terminal_output

Then exclude the conflicting modules from these dependencies like:

   implementation ("com.jakewharton:butterknife:8.8.1") {
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'support-annotation'
    exclude group: 'com.android.support', module: 'support-compat'
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...