Gradle dependency exclusion not working - android

My project build.gradle dependencies are:
dependencies {
...
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-appinvite:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'co.realtime:messaging-android:2.1.58'
}
And the co.realtime:messageing-android build.gradle dependencies are:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.android.support:appcompat-v7:21.0.3'){
transitive = true;
}
compile ('com.google.android.gms:play-services:6.1.71'){
transitive = true;
}
compile ('com.googlecode.json-simple:json-simple:1.1'){
transitive = true;
}
}
If I try to compile my project I get the following error:
Error:Gradle: Execution failed for task
':app-module:processProdDebugResources'.
Error: more than one library with package name 'com.google.android.gms' You can temporarily disable this error with
android.enforceUniquePackageName=false However, this is temporary
and will be enforced in 1.0
If I use enforceUniquePackageName(false) I get:
cannot resolve symbol to GoogleCloudMessaging.INSTANCE_ID_SCOPE
So I guess I'll have to solve this by managing the dependencies. I've tried:
compile ('co.realtime:messaging-android:2.1.58'){
exclude module: 'com.google'
}
compile ('co.realtime:messaging-android:2.1.58'){
exclude group: 'com.google.android.gms', module: 'play-services-gcm'
}
But nothing seams to work... How can I solve this?
Thanks.

The problem was in 'play-services-gcm' instead of 'play-services'
compile ('co.realtime:messaging-android:2.1.58'){
exclude group: 'com.google.android.gms', module: 'play-services'
}
grrr those typo mistakes... Well I thought I could delete this question but, once in a while someone has the same issue, so I will leave this here hoping perhaps it helps someone in need.

Related

Java.util.zip.ZipException: duplicate entry: com/google/common/base/FinalizableReference.class

Why am getting this error it will not occurred when I sync the Gradle but when I'm running the project I am getting this error .
Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/common/base/FinalizableReference.class
I don't know which dependency cause this error, My dependencies are .
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:customtabs:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:percent:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.facebook.android:facebook-android-sdk:4.19.0'
compile 'com.google.android.gms:play-services-auth:11.0.0'
compile 'com.google.android.gms:play-services-location:11.0.0'
compile 'com.google.android.gms:play-services-maps:11.0.0'
compile 'com.google.android.gms:play-services-places:11.0.0'
compile 'com.google.maps.android:android-maps-utils:0.3.4'
compile 'io.nlopez.smartlocation:library:3.3.1'
compile 'com.appeaser.sublimenavigationviewlibrary:sublimenavigationviewlibrary:0.0.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5#aar'
compile 'com.afollestad:sectioned-recyclerview:0.4.1'
compile 'com.github.medyo:fancybuttons:1.8.3'
compile 'com.basgeekball:awesome-validation:2.0'
compile 'com.github.michaelye.easydialog:easydialog:1.4'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
Edit
I figured it out play service dependencies causing this problem. when I'm using 10.2.6 instead of 11.0.0 app is working perfectly, I just change dependecies to
compile 'com.google.android.gms:play-services-auth:10.2.6'
compile 'com.google.android.gms:play-services-location:10.2.6'
compile 'com.google.android.gms:play-services-maps:10.2.6'
compile 'com.google.android.gms:play-services-places:10.2.6'
but I want to use latest version of play-services 11.0.0 but it gives me the above problem. How to resolve this problem? Any help would be appriciated Thanks.
Finally problem is solved. Seems like its a bug google resolved this issue in updated version.
Use play Service Version 11.0.1
In project level gradle use
classpath 'com.google.gms:google-services:3.1.0'
Sometimes, this issue happens because of including different version of play-services (or some other libraries). Have a look at app dependencies using below:
gradle app:dependencies
or if you are using Gradle wrapper
./gradlew app:dependencies
There might be some other third party library that is using an older version of library. If that is the case, exclude the older library from the third party library and include the latest one.
You can do something like this:
compile ('com.thirdpartylib.android:library-sdk:8.3.0') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.android.gms', module: 'play-services-gcm'
compile 'com.android.support:support-v4:26.0.0'
compile 'com.android.support:support-annotations:26.0.0'
compile 'com.google.android.gms:play-services-gcm:11.2.0'
}
This should resolve any duplicate entry, the main reason for the issue

Gradle indentation issue in Android Studio 2.3

Every time I create a new Activity in AS 2.3 it messes up the build.gradle indentation that results in errors like this.
Error:Could not get unknown property 'compile' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I have to redo the indentations every time. Any idea how to fix this permanently?
Don't use compile as a property and don't change the gradle structure.
compile 'com.android.support:appcompat-v7:22.2.1' compile
'com.parse:parse-android:1.11.0'
Sometimes Gradle build messes up the code like above, it still happens. Probably related to Java JDK updates.
The problem seems to be caused by the lines which contain curly braces like:
compile('com.github.tony19:logback-android-core:1.1.1-4') {
exclude group: 'ch.qos.logback.core.net'
}
In order to avoid the bug just put all the lines with curly braces above the "usual" (i.e. compile 'something') lines like this:
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile('com.github.tony19:logback-android-core:1.1.1-4') {
exclude group: 'ch.qos.logback.core.net'
}
compile('com.github.tony19:logback-android-classic:1.1.1-4') {
exclude group: 'ch.qos.logback.core.net'
}
compile 'com.bolyartech.forge.android:forge-android:6.1.0'
compile 'com.bolyartech.scram_sasl:scram_sasl:2.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.squareup:otto:1.3.6'
compile 'com.google.code.gson:gson:2.7'
compile 'com.github.franmontiel:PersistentCookieJar:v0.9.3'
compile 'com.google.dagger:dagger:2.9'
...

ZipException: duplicate entry: android/support/v4/app/BaseFragmentActivityDonut.class [duplicate]

I am integrating my project into another app in android studio but it shows the below error, I am googling the issue but no use.
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/accessibilityservice/AccessibilityServiceInfoCompatJellyBeanMr2.class
below is my app dependencies
configurations { all*.exclude group: 'com.android.support', module: 'support-annotations' }
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':waleteros')
compile 'com.android.support:recyclerview-v7:+'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.jakewharton:butterknife:5.1.2'
compile files('src/libs/android_sync_service_library.jar')
compile "com.google.android.gms:play-services:3.1.+"
compile('com.crashlytics.sdk.android:crashlytics:2.2.2#aar') {
transitive = true;
}
and here is my library dependencies
configurations { all*.exclude group: 'com.android.support', module: 'support-v4' }
configurations { all*.exclude group: 'com.android.support', module: 'support-annotations' }
dependencies {
compile project(':ingosdk')
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/A2iA.Mobility.jar')
compile files('libs/acra-4.5.0.jar')
compile files('libs/bugsense-3.5.jar')
compile files('libs/deviceprint-lib-1.0.0.jar')
compile files('libs/FlurryAnalytics-5.3.0.jar')
compile files('libs/httpmime-4.1.2.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/volley.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile files('libs/android-support-v13.jar')
}
If you have the android-support-v4.jar in your libs folder.. delete it!
That solved my problem.
Even though the file is not added in the build.gradle file.. gradle includes it in the build anyway.
I had the same problem after upgrading the android SDK. I was able to run the application in the buildToolsVersion '23.0.1', I got the same error when I changed to buildToolsVersion '24.0.3'
I resolved the problem by updating my java version from 1.7 to 1.8 with compileSdkVersion 24
Similar issue, I'd just imported
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1.1'
and was getting this error, after adding "#aar", the problem was solved
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1.1#aar'
In my opinion this error is happened by duplicate jar file.
I delete my support-V4 jar file into my library and then clean build it works fine.
Thanks

Crouton depends on libraries but is not a library itself

I'm using Android Studio 0.6.1, with Crouton library and today after gradle sync I got next error:
Error:A problem occurred configuring root project 'project_name'.
Module version de.keyboardsurfer.android.widget:crouton:1.8.4 depends on libraries but is not a library itself
That's going on?
This issue due to com.android.support-v4 recent update.
So I changed
compile 'com.android.support:support-v4:20.+'
to
compile 'com.android.support:support-v4:19.1.+'
and crouton works fine
Different workaround is to use #aar:
compile('de.keyboardsurfer.android.widget:crouton:1.8.4#aar') {
exclude group: 'com.google.android', module: 'support-v4'
}
My solution according to #Revedko answer, using #aar and change all supports to version lower than 21 -> 20.+
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.loopj.android:android-async-http:1.+'
compile "com.bugsense.trace:bugsense:3.5"
compile('de.keyboardsurfer.android.widget:crouton:1.8.4#aar') {
exclude group: 'com.google.android', module: 'support-v4'
}
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:5.0.77'
}

Unsupported Gradle DSL method found: 'exclude()'

If:
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
compile 'de.keyboardsurfer.android.widget:crouton:1.8.3'
compile 'de.greenrobot:eventbus:2.2.0'
compile 'com.intellij:annotations:+#jar'
compile 'com.jpardogo.googleprogressbar:library:1.0.0'
compile project(':floatlabel')
compile project(':Android-SwipeToDismiss')
compile project(':Android-UndoBar') {
exclude group: 'com.nineoldandroids', module: 'library' // without or without this one
}
compile project(':AndroidSlidingUpPanel:library') {
exclude group: 'com.nineoldandroids', module: 'library' // without or without this one
}
}
I receive this error message:
Gradle 'mProject' project refresh failed: Build script error, unsupported Gradle DSL method found: 'exclude()'!
But this works:
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
compile 'de.keyboardsurfer.android.widget:crouton:1.8.3'
compile 'de.greenrobot:eventbus:2.2.0'
compile 'com.intellij:annotations:+#jar'
compile 'com.jpardogo.googleprogressbar:library:1.0.0'
compile project(':floatlabel')
compile project(':Android-SwipeToDismiss')
compile project(':Android-UndoBar')
compile project(':AndroidSlidingUpPanel:library')
}
configurations {
all*.exclude group: 'com.nineoldandroids', module: 'library'
}
Trying to understand why, please clarify!
Use
compile (project(':Android-UndoBar')) {
exclude group: 'com.nineoldandroids', module: 'library' // without or without this one
}
So with extra parentheses.

Categories

Resources