duplicate classes or library dependency conflicts [duplicate] - java

When I build the android project, it show "Duplicate class" exception,
1 exception was raised by workers: java.lang.RuntimeException:
java.lang.RuntimeException:
Duplicate class android.arch.core.executor.DefaultTaskExecutor found in modules classes.jar (android.arch.core:core:1.0.0-alpha1) and classes.jar(android.arch.core:runtime:1.1.1)
Duplicate class android.arch.core.executor.TaskExecutor found in modules classes.jar (android.arch.core:core:1.0.0-alpha1) and classes.jar (android.arch.core:runtime:1.1.1)**
How could I find and fix what lib use duplicate class in my project?
app.Gradle
android {
compileSdkVersion 28
buildToolsVersion ’28.0.3’
defaultConfig {
minSdkVersion 18
targetSdkVersion 28
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
dependencies {
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation ’org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31’api('com.google.maps:google-maps-services:0.9.3') {
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}
implementation 'com.android.support:appcompat-v7:28.0.0’
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.android.exoplayer:exoplayer:2.8.2’
implementation 'android.arch.persistence.room:runtime:1.0.0-alpha1'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-alpha1'
implementation 'com.jakewharton.rxbinding:rxbinding:1.0.1'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.8'
implementation 'com.google.android.gms:play-services-places:16.1.0'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation 'com.facebook.android:facebook-android-sdk:5.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.1'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.3.8'
implementation 'com.artemzin.rxjava:proguard-rules:1.3.3.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.1'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation ('com.github.bumptech.glide:glide:4.9.0') {
exclude group: "com.android.support"
}
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.10.11'
implementation project(':lib-zxing')
implementation 'com.googlecode.mp4parser:isoparser:1.1.22'
implementation 'com.github.lassana:continuous-audiorecorder:1.3.1'
implementation 'me.leolin:ShortcutBadger:1.1.22#aar'
implementation 'com.timehop.stickyheadersrecyclerview:library:0.4.3'
implementation 'org.jsoup:jsoup:1.11.3'
testImplementation 'junit:junit:4.13-beta-2'
}
lib-zxing
android {
compileSdkVersion 28
buildToolsVersion ’28.0.3’
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0’
testImplementation 'junit:junit:4.13-beta-2'
}

You need to exclude the arch Jar. First of all check where the duplicate comes from. You can see it if you print your dependency tree with a gradle task:
./gradlew -q dependencies app:dependencies --configuration compile
Then exclude the older arch Jar like you did for glide but with the correct exclude, for example:
implementation ('android.arch.persistence.room:runtime:1.0.0-alpha1') {
exclude group: "android.arch.core"
}

You can use search everywhere dialog(Dialog that opens on pressing shift twice).
Simply copy class name and paste it in search dialog and it will show results in drop down. You can browse result and check for duplicate entries, Complete path of class will be displayed next to class name so you can find relative libraries and can safely exclude it from anyone of the library.

Related

while implementing GCS, Duplicate class found error after adding implementation 'com.google.cloud:google-cloud-storage' in gradle android

when i add Google cloud storage implementation to my existing android app, in gradle
( implementation 'com.google.cloud:google-cloud-storage:1.113.1' ) ,
i am getting these dependency errors
Duplicate class com.google.api.Advice found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.Advice$1 found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.Advice$Builder found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.AnnotationsProto found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.AuthProto found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.AuthProvider found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.AuthProvider$1 found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.AuthProvider$Builder found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.AuthProviderOrBuilder found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.AuthRequirement found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.AuthRequirement$1 found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.AuthRequirement$Builder found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.AuthRequirementOrBuilder found in modules jetified-proto-google-common-protos-1.18.1.jar
Duplicate class com.google.api.Authentication found in modules jetified-proto-google-common-protos-1.18.1.jar
like this i am getting 100's of lines please help
here my build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
android {
compileSdkVersion 29
defaultConfig {
applicationId "XXXXXXXXXXXXXXXXXX"
//noinspection StringShouldBeInt
minSdkVersion 19
targetSdkVersion 29
versionCode 6
versionName "1.6"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/INDEX.LIST'
exclude 'google/protobuf/field_mask.proto'
exclude 'google/protobuf/type.proto'
exclude 'google/protobuf/api.proto'
exclude 'google/protobuf/empty.proto'
exclude 'google/protobuf/source_context.proto'
exclude 'google/protobuf/wrappers.proto'
exclude 'google/protobuf/struct.proto'
exclude 'google/protobuf/any.proto'
exclude 'google/protobuf/timestamp.proto'
exclude 'google/protobuf/AbstractMessageLite'
exclude 'google/protobuf/WireFormat'
exclude 'google/protobuf/WrappersProto'
exclude 'google/protobuf/Writer'
exclude 'google/api/Advice'
exclude 'google/api/AdviceOrBuilder'
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
zipAlignEnabled true
shrinkResources true
}
debug {
minifyEnabled false
}
}
}
dependencies {
//--required
//progress bar
implementation 'com.victor:lib:1.0.4'
//wallpaper
implementation 'com.github.bumptech.glide:glide:4.9.0'
//auto update
implementation 'org.jsoup:jsoup:1.13.1'
//tablayout
implementation 'com.google.android.material:material:1.2.1'
//rain layout
implementation 'com.luolc:emoji-rain:0.1.1'
implementation 'com.gauravk.bubblenavigation:bubblenavigation:1.0.7'
//counter animation
implementation 'com.robinhood.ticker:ticker:2.0.2'
// round imageview
implementation 'com.joooonho:selectableroundedimageview:1.0.1'
implementation 'com.github.mklimek:frame-video-view:1.3.3'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.daimajia.easing:library:2.4#aar'
implementation 'com.daimajia.androidanimations:library:2.4#aar'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation files('libs/...')
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.media:media:1.1.0"
//GCS begin
implementation 'com.google.cloud:google-cloud-storage:1.113.1'
//GCS end
//implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.google.android.gms:play-services-ads:19.4.0'
implementation 'com.firebaseui:firebase-ui-auth:4.3.0'
implementation 'com.firebaseui:firebase-ui-firestore:5.1.0'
implementation 'com.google.firebase:firebase-storage:19.2.0'
implementation 'com.google.firebase:firebase-firestore:21.6.0'
implementation 'com.google.firebase:firebase-auth:19.4.0'
//toast
implementation 'com.sdsmdg.tastytoast:tastytoast:0.1.1'
//progress bar
annotationProcessor 'com.google.auto.value:auto-value:1.5.1'
}
apply plugin: 'com.google.gms.google-services'
i tried to exclude groups like this but didn't help
implementation ('com.google.apis:google-api-services-translate:v2-rev47-1.22.0') {
exclude group: 'com.google.guava'
}
implementation ('com.google.cloud:google-cloud-translate:0.5.0') {
exclude group: 'io.grpc', module: 'grpc-all'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'com.google.api-client', module: 'google-api-client-appengine'
exclude group: 'com.google.api.Advice', module: 'jetified-proto-google-common-protos'
}
and i tried this
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/INDEX.LIST'
exclude 'google/protobuf/field_mask.proto'
exclude 'google/protobuf/type.proto'
exclude 'google/protobuf/api.proto'
exclude 'google/protobuf/empty.proto'
exclude 'google/protobuf/source_context.proto'
exclude 'google/protobuf/wrappers.proto'
exclude 'google/protobuf/struct.proto'
exclude 'google/protobuf/any.proto'
exclude 'google/protobuf/timestamp.proto'
exclude 'google/protobuf/AbstractMessageLite'
exclude 'google/protobuf/WireFormat'
exclude 'google/protobuf/WrappersProto'
exclude 'google/protobuf/Writer'
exclude 'google/api/Advice'
exclude 'google/api/AdviceOrBuilder'
}
}
i checked all already available answers but didn't get solution.
if i remove implementation 'com.google.cloud:google-cloud-storage:1.113.1' every thing works normal.
but i need to add cloud storage implementation into my android app to store images.
thanks in adavance
These packagingOptions are rather useless and should be removed.
The issue isn't GCS, but rather com.google.api.grpc:proto-google-common-protos.
An exclusion might look alike this:
implementation ("com.google.cloud:google-cloud-storage:1.113.1") {
exclude group: "com.google.api.grpc", module: "proto-google-common-protos"
}
Run ./gradlew app:dependencies > dependencies.txt to get the dependency tree.

Problem compiling to Android 4 after migrating to AndroidX

I have an Android (Java) project and after migrating to AndroidX I have received the following error (d8 errors):
Program type already present: com.enterprisedt.BaseIOException
Note that gradle synchronization occurs normally. This error appears only at compile time for the device. And the weirdest thing, it only happens when I'm compiling for an Android 4 device.
When trying to compile for Android 5+, the compilation succeeds and the app runs smoothly.
build.gradle
[...]
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
applicationId "br.com.example"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
}
dependencies {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.android.support', module: 'support-annotations'
all*.exclude group: 'com.android.support', module: 'appcompat-v7'
all*.exclude group: 'com.android.support', module: 'support-v13'
}
implementation project(':mylib')
// These 3 libraries are required for the project.
implementation files("libs/activation.jar")
implementation files("libs/mail.jar")
implementation files("libs/edtftpj.jar")
implementation files("libs/commons-net-3.0.1.jar")
implementation files("libs/commons-validator-1.4.0.jar")
implementation files("libs/itextpdf-5.4.0.jar")
implementation('com.appsee:appsee-android:2.3.3#aar') {
transitive = true
}
implementation('com.optimizely:optimizely:1.4.2#aar') {
transitive = true
}
implementation('io.fabric.sdk.android:fabric:1.4.8#aar') {
transitive = true
}
implementation('com.crashlytics.sdk.android:crashlytics:2.10.1#aar') {
transitive = true
}
implementation "com.onesignal:OneSignal:$oneSignalVersion"
implementation "androidx.percentlayout:percentlayout:$percentLayoutVersion"
implementation "androidx.legacy:legacy-support-v4:$legacyVersion"
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation "androidx.recyclerview:recyclerview:$recyclerViewVersion"
implementation "androidx.annotation:annotation:$androidxAppCompatVersion"
implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.guava:guava-collections:r03'
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation "com.google.android.material:material:$materialVersion"
implementation "com.google.android.gms:play-services-maps:$gmsVersion"
implementation "com.google.android.gms:play-services-analytics:$gmsVersion"
implementation 'com.google.dagger:dagger:2.24'
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
implementation 'com.squareup:otto:1.3.8'
implementation 'org.jetbrains:annotations:17.0.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.squareup.picasso:picasso:2.71828', {
exclude group: 'com.android.support', module: 'support-annotations'
}
implementation 'com.lapism:searchview:4.0'
implementation 'com.sromku:simple-storage:1.2.0'
implementation 'me.dm7.barcodescanner:zxing:1.9.8', {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
implementation 'com.nononsenseapps:filepicker:2.5.2'
implementation 'io.github.yavski:fab-speed-dial:1.0.6'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.1'
implementation 'com.github.arimorty:floatingsearchview:2.1.1'
implementation 'net.i2p.android.ext:floatingactionbutton:1.10.1'
implementation 'org.zakariya.stickyheaders:stickyheaders:0.7.11'
implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'
implementation 'com.prolificinteractive:material-calendarview:1.4.3'
implementation 'uk.co.chrisjenx:calligraphy:2.3.0', {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
// debug
debugImplementation 'com.facebook.stetho:stetho:1.5.1'
debugImplementation 'com.gu.android:toolargetool:0.1.5#aar'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-all:1.10.19'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02', {
exclude group: 'com.android.support', module: 'support-annotations'
}
}
[...]
build.gradle (project)
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://maven.google.com' }
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.5'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath 'io.fabric.tools:gradle:1.31.1'
classpath 'com.google.gms:google-services:4.3.2'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://www.jitpack.io" }
maven { url 'http://dl.bintray.com/optimizely/optimizely' }
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://maven.google.com' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots"}
maven { url 'https://dl.bintray.com/guardian/android' }
}
}
build.gradle (local lib: "mylib")
[...]
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
[...]
dependencies {
// here, I repeat those 3 libraries mentioned (activation, mail, edtftpj)
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.browser:browser:1.0.0'
implementation "com.google.android.gms:play-services-location:17.0.0"
implementation "com.google.android.gms:play-services-maps:17.0.0"
implementation "com.google.android.gms:play-services-analytics:17.0.0"
implementation "com.google.android.material:material:1.0.0"
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.annotation:annotation:1.1.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
api 'br.com.concretesolutions:canarinho:1.1.0'
api 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
}
gradle.properties
org.gradle.jvmargs=-Xmx2048M
org.gradle.configureondemand=false
android.enableJetifier=true
android.useAndroidX=true
The 3 libraries I mentioned (activation, mail, edtftpj) need to be in both lib and project, because it is actually used.
This I already tried:
./gradlew clean
Android Studio -> File -> invalidate cache and restart
Android Studio -> Build -> Clean Project
Remove one of the duplicate libraries (this generated another error because I use the library tools in both modules)
Add the following code to build.gradle:
packagingOptions {
exclude 'com/sun/mail/dsn/mailcap'
exclude 'dsn.mf'
exclude 'javamail.charset.map'
exclude 'javamail.default.address.map'
exclude 'javamail.default.providers'
exclude 'javamail.imap.provider'
exclude 'javamail.pop3.provider'
exclude 'javamail.smtp.address.map'
exclude 'javamail.smtp.provider'
exclude 'mailcap'
exclude 'mimetypes.default'
exclude 'mailcap.default'
exclude 'com.enterprisedt.BaseIOException'
exclude 'javax.activation.*'
}
Can anybody help me ?

error: failed to open APK: Invalid offset

All projects build successfully but
I'm getting this error when I try to run or debug the project.
error:
Android resource linking failed W/ziparchive( 6524): Zip: didn't find
signature at start of lfh, offset=41550366 error: failed to open APK:
Invalid offset.
I did try to build, clean, rebuild
Invalidate cashes restart
sync project with Gradle files
update Gradle, android studio to the latest version
my Build.gradle app :
apply plugin: 'com.android.application'
android {
defaultConfig {
applicationId "com.geesdsada.app"
minSdkVersion 17
targetSdkVersion 28
versionCode 4
versionName "4.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
defaultConfig {
multiDexEnabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileSdkVersion 28
buildToolsVersion '28.0.3'
}
dependencies {
//fonts
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
//CounterFAB
implementation 'com.github.andremion:counterfab:1.0.1'
//
implementation 'com.github.jd-alexander:android-flat-button:v1.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.stripe:stripe-android:6.1.2'
implementation 'com.google.android.gms:play-services-base:16.1.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.8'
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.squareup.okhttp3:okhttp:3.0.1'
implementation 'com.github.d-max:spots-dialog:0.7#aar'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'io.paperdb:paperdb:2.1'
//add libraries
implementation 'me.zhanghai.android.materialratingbar:library:1.3.2'
implementation 'com.stepstone.apprating:app-rating:2.0.0'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'io.paperdb:paperdb:2.1'
implementation 'com.github.rey5137:material:1.2.4'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
implementation 'com.parse:parse-android:1.16.3'
//update version to the latest one
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.firebaseui:firebase-ui-database:1.2.0'
implementation 'com.cepheuen.elegant-number-button:lib:1.0.2'
implementation 'com.squareup.picasso:picasso:2.5.0'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
all code is finely written and was working well, but suddenly this error showed up.
I was getting this in Android Studio and all I did to fix it was go to "Build" > "Clean Project" and it just worked. Now Rebuild (Build -> Rebuild) your project.

Program type already present: com.google.common.annotations.GwtCompatible

I'm getting the following error when building my android project :
Program type already present:
com.google.common.annotations.GwtCompatible Message{kind=ERROR,
text=Program type already present:
com.google.common.annotations.GwtCompatible, sources=[Unknown source
file], tool name=Optional.of(D8)}
gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.www.www"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// multi-dex support (When your app and the libraries it references exceed 65,536 methods)
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/INDEX.LIST'
}
}
dependencies {
// multi-dex support (When your app and the libraries it references exceed 65,536 methods)
implementation 'com.android.support:multidex:1.0.3'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//this is for the google "text recognizer"
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.google.apis:google-api-services-customsearch:v1-rev63-1.23.0'
//for firebase database connection
implementation 'com.google.firebase:firebase-database:16.0.1'
//implementation 'com.google.firebase:firebase-core:16.0.0'
// for firebase authentication
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
// for Google Natural Language Processing (part of google cloud services)
implementation ('com.google.cloud:google-cloud-language:1.31.0')
// {
// exclude group: 'com.google.guava'
// }
}
apply plugin: 'com.google.gms.google-services'
The following resolves THAT issue :
implementation ('com.google.cloud:google-cloud-language:1.31.0') {
exclude group: 'com.google.guava'
}
But then I am missing guava functions, because the following error will be thrown at runtime :
Didn't find class "com.google.common.base.MoreObjects"
Caused by: java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/common/base/MoreObjects;
When I run the following code :
public void testSomething(View view){
// Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient
try {
InputStream inputStream = getAssets().open("www.json");
GoogleCredentials googleCredential = GoogleCredentials.fromStream(inputStream);
}
catch (Exception e){
Log.e(TAG,e.getMessage());
e.printStackTrace();
}
I'm going in circles here. I'm desperate to find the answer.
I have checked other questions/topics, no answers that help me.
I solved same problem by making below changes:
implementation ('com.google.apis:google-api-services-drive:v2-rev105-1.17.0-rc'){
exclude module: 'guava-jdk5'
}
implementation ('com.google.api-client:google-api-client-android:1.20.0'){
exclude module: 'guava-jdk5'
}
Change Gradles To This :
implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0' exclude module: 'guava-jdk5'
implementation 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'guava-jdk5' exclude module: 'httpclient'
implementation 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
This Worked For Me

Unable to build apk or run the app

The gradle build completes successfully , but while running the application or trying to build the apk I am getting an error:
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't write [F:\TravEz\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\hp.gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.0.aar\51b8cdc0bcfc98652d9ae95f70697b30\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/design/widget/CoordinatorLayout$Behavior.class]))
I have tried all the methods mentioned here
Here is my project level gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io"}
//Glomadrian maven for animated switch
maven { url "https://dl.bintray.com/glomadrian/maven"}
maven { url "http://dl.bintray.com/lukaville/maven"}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is my app level gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.travez.travez"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dexOptions {
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
compile 'com.github.florent37:materialtextfield:1.0.7'
//library for cardview
implementation 'com.android.support:cardview-v7:26.1.0'
//library for dialog box
implementation 'com.github.d-max:spots-dialog:0.7#aar'
//library for animated switch
implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//Firebase authentication library
implementation 'com.google.firebase:firebase-auth:11.0.4'
//Firebase database library
implementation 'com.google.firebase:firebase-database:11.0.4'
//Google play services and maps libraries
implementation 'com.google.android.gms:play-services-maps:11.0.4'
implementation 'com.google.android.gms:play-services:11.0.4'
implementation 'com.google.android.gms:play-services-location:11.0.4'
//Geofire library
compile 'com.firebase:geofire-android:2.3.0'
//Runtime perission library
compile 'com.github.karanchuri:PermissionManager:0.1.0'
//Material Edit Text library
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
//Calligraphy library
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
// CircleView library
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'id.zelory:compressor:2.1.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
compile 'com.android.support:multidex:1.0.0'
compile 'com.nbsp:library:1.8'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
Is written twice, remove one of them.
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
Replace the + with the current version of the library
The problem is because you have duplicated support library in your dependencies.
android-image-cropper is using support library 27+, you can check its build.gradle. MaterialEditText is using support library 22.2.0. Material Animated Switch is using support library 22.2.0. You need to exlude the support libraries from them.
So, instead using the following:
compile 'com.github.florent37:materialtextfield:1.0.7'
implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
use the following:
implementation 'com.android.support:support-annotations:26.1.0'
implementation ('com.github.florent37:materialtextfield:1.0.7') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
exclude module: 'support-annotations'
}
implementation ('com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
}
implementation ('com.theartofdev.edmodo:android-image-cropper:2.6.0') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
}
You can check the dependencies tree if you still found the conflicted libraries with:
./gradlew app:dependencies

Categories

Resources