Тип программы уже присутствует: com.squareup.okhttp.Address

Я пытаюсь настроить свое приложение для Android на использование Firebase Cloud Firestore. У меня тоже есть зависимости от OKHttp3. Gradle синхронизируется нормально, но я не могу скомпилировать приложение и запустить его. И я получаю следующую ошибку:

Program type already present: com.squareup.okhttp.Address

Я выполнил все шаги, описанные здесь: https://firebase.google.com/docs/firestore/quickstart, и я могу нормально запустить приложение, пока не добавлю эту строку в свой файл build.gradle:

implementation 'com.google.firebase:firebase-database:15.0.0'

Я проверил зависимости в проекте, и похоже, что Firestore имеет зависимости от com.squareup.okhttp, а у меня уже есть зависимости от com.squareup.okhttp3

Поэтому я не понимаю, почему они будут конфликтовать, поскольку у них разные структуры пакетов.

РЕДАКТИРОВАТЬ

Вот мои зависимости в моем build.gradle:

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.kotlin_version}"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.19.3'
implementation 'com.jakewharton:butterknife:8.8.0'
kapt 'com.jakewharton:butterknife-compiler:8.8.0'
compileOnly 'com.google.auto.value:auto-value:1.3'
annotationProcessor 'com.google.auto.value:auto-value:1.3'
implementation "com.android.support:design:${rootProject.ext.support_library_version}"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation "com.android.support:support-compat:${rootProject.ext.support_library_version}"
implementation "com.android.support:support-core-utils:${rootProject.ext.support_library_version}"
implementation "com.android.support:support-core-ui:${rootProject.ext.support_library_version}"
implementation "com.android.support:support-fragment:${rootProject.ext.support_library_version}"
implementation "com.android.support:gridlayout-v7:${rootProject.ext.support_library_version}"
implementation "com.android.support:recyclerview-v7:${rootProject.ext.support_library_version}"
implementation "com.android.support:customtabs:${rootProject.ext.support_library_version}"
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.google.code.gson:gson:2.8.0'
implementation "com.google.android.gms:play-services-auth:${rootProject.ext.play_services_version}"
implementation "com.google.android.gms:play-services-maps:${rootProject.ext.play_services_version}"
implementation "com.google.android.gms:play-services-location:${rootProject.ext.play_services_version}"
implementation "com.google.android.gms:play-services-analytics:${rootProject.ext.play_services_version}"
implementation "com.google.android.gms:play-services-wallet:${rootProject.ext.play_services_version}"
implementation "com.google.firebase:firebase-core:${rootProject.ext.firebase_version}"
implementation "com.google.firebase:firebase-crash:${rootProject.ext.firebase_version}"
implementation "com.google.firebase:firebase-messaging:${rootProject.ext.firebase_version}"
implementation "com.google.firebase:firebase-invites:${rootProject.ext.firebase_version}"
implementation "com.google.firebase:firebase-ads:${rootProject.ext.firebase_version}"

// Because RxAndroid releases are few and far between, it is recommended you also

// explicitly depend on RxJava's latest version for bug fixes and new features.
implementation 'io.reactivex.rxjava2:rxjava:2.0.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation('com.crashlytics.sdk.android:crashlytics:2.7.0') {
    transitive = true
}
implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'com.facebook.android:facebook-android-sdk:4.13.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'io.card:android-sdk:5.4.2'
implementation 'com.github.chrisbanes.photoview:library:1.2.3'
implementation 'uk.co.chrisjenx:calligraphy:2.1.0'
implementation 'com.tonicartos:superslim:0.4.13'
implementation 'com.sothree.slidinguppanel:library:3.1.1'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'konifar:fab-transformation:1.0.0'
implementation 'me.grantland:autofittextview:0.2.1'
implementation 'com.braintreepayments.api:braintree:2.3.3'
implementation 'se.emilsjolander:stickylistheaders:2.7.0'
implementation 'net.danlew:android.joda:2.9.4.1'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'ru.gildor.coroutines:kotlin-coroutines-retrofit:0.9.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.powermock:powermock-module-junit4:1.7.1'
testImplementation 'org.powermock:powermock-module-junit4-rule:1.7.1'
testImplementation 'org.powermock:powermock-api-mockito2:1.7.1'
testImplementation 'org.powermock:powermock-classloading-xstream:1.7.1'
testImplementation 'org.robolectric:robolectric:3.6.1'
testImplementation 'org.robolectric:shadows-multidex:3.6.1'
testImplementation 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.8.9'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
testImplementation 'joda-time:joda-time:2.9.4'
androidTestImplementation fileTree(include: 'robotium-solo-5.3.0.jar', dir: 'libs')

//Screenshots
androidTestImplementation 'com.squareup.spoon:spoon-client:1.2.0'

// Cucumber
androidTestImplementation 'info.cukes:cucumber-java:1.2.5'
androidTestImplementation('info.cukes:cucumber-android:1.2.4') {
    exclude module: 'cucumber-jvm-deps'
}
androidTestImplementation('info.cukes:cucumber-picocontainer:1.2.4') {
    exclude module: 'cucumber-jvm-deps'
}
androidTestImplementation 'info.cukes:cucumber-jvm-deps:1.0.3'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support:support-annotations:25.3.1'

// Set this dependency to use JUnit 4 rules
androidTestImplementation 'com.android.support.test:rules:0.5'

// Set this dependency to build and run Espresso tests
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2') {
    exclude module: 'support-annotations'
}
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:2.2.2'

}

Добавьте содержимое вашего файла build.gradle.

Alex Mamo 23.04.2018 15:28
stackoverflow.com/questions/48351721/…
John Boker 23.04.2018 15:41

попробовал разные ответы, предложенные в отправленной вами ссылке, но без разницы ...

Moh Kh 24.04.2018 11:07
4
3
5 284
2
Перейти к ответу Данный вопрос помечен как решенный

Ответы 2

Ответ принят как подходящий

ФИКСИРОВАННЫЙ

Оказалось, что проблема не связана с OkHttp - она ​​связана с компилятором Dexer в новой версии android studio (3.0.0 и выше) Заходим в файл gradle.properties и добавляем эту строку:

android.enableD8=false

решил мою проблему. Приложение теперь компилируется нормально

РЕДАКТИРОВАТЬ

Комментарии правильные - вам следует сделать это НЕТ. Проблема оказалась в том, что у проекта были зависимости gradle, конфликтующие с вручную импортированными файлами .jar. Если у вас есть эта проблема, проверьте, нет ли у вас:

  1. Различные версии одной и той же библиотеки, импортированные разными модулями в Gradle
  2. Jar-файл библиотеки, которую вы также импортируете с помощью Gradle

Это работает, даже если компилятор выдает предупреждение об этом.

saintjab 30.04.2018 19:26

Где в вашем файле вы поместили эту строку?

cincospenguinos 15.06.2018 03:13

Подскажите, пожалуйста, куда добавить в gradle.properties?

Leo 09.07.2018 08:56

Студия Android говорит: Предупреждение: опция android.enableD8 устарела и больше не должна использоваться.

Siddhesh Shirodkar 07.08.2018 11:26

Заходим в файл gradle.properties и добавляем эту строку:

android.enableR8=false
android.enableD8=false

Надеюсь, это сработает.

Другие вопросы по теме