I am using Picasso library for images in my android library, and if i run app for API 26 it compiles okay it runs and everything is perfect, if i run for API 21 (5.0) i always receive duplicate entry: okio/AsyncTimeout$1.class
I already excluded in my gradle
configurations {
all*.exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
But no success, if i assemble in terminal i get same error, only libraries i use in my lib project are exoplayer and picasso (others are support libraries) I also tried to remove Picasso then it builds normally. Is it maybe connected that the other libraries of main project are causing it?
Try to add this in project level grandle:
configurations{
all*.exclude module: 'okhttp'
all*.exclude module: 'okio'
}
Related
I had several libraries conflict issues. That i resolved by adding
configurations {
all {
exclude module: 'httpclient'
exclude module: 'commons-logging'
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.httpcomponents'
exclude module: 'xmlParserAPIs'
exclude module: 'xpp3'
exclude module: 'opengl-api'
}
}
But still following error present. And i am unable to build signed apk.
I have tried project clean/rebuild option.
Error: android defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
Thanks in advance for your help.
Problem
How to see which dependency is creating conflicts. It is same like shooting in dark.
Solution
Some AS plugin that will show you which projects dependency hierarchy. You can find where issue presents exactly and solve that.
Gradle View is an Android Studio plugin that you can install and show dependency hierarchy.
Methods Count is another plugin, it also shows dependency tree.
The error may be comes from different module but if issue is httpcomp... or xpp3 then
I just add these lines of code in app Gradle
dependencies {
......
configurations {
all*.exclude group: 'xpp3', module: 'xpp3'
implementation.exclude group: "org.apache.httpcomponents", module: "httpclient"
}
}
done
I'm receiving a runtime error No interface method trackUsage() in UsageTracker.java when the lines run in the Espresso test to scroll to a certain element in the RecyclerView list:
onView(withId(R.id.recyclerView)).perform(scrollTo(hasDescendant(withText(text))));
I'm using RecyclerViewActions for the scrollTo() method.
Here are my current configurations and gradle dependencies:
Android Studio 3.0 Canery 9
compileSdkVersion 25
buildToolsVersion "26.0.1"
junit:junit:4.12
com.android.support.test:runner:1.0.0
com.android.support.test:rules:1.0.0
com.android.support.test.espresso:espresso-contrib:2.2.2
com.android.support.test.espresso:espresso-core:2.2.2
Android Support Library: 25.3.1
Also, for each of the androidTestCompile's I'm using the following excludes:
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'recyclerview-v7'
Full error message: No interface method trackUsage(Ljava/lang/String;)V in class Landroid/support/test/internal/runner/tracker/UsageTracker; or its super classes (declaration of 'android.support.test.internal.runner.tracker.UsageTracker' appears in /data/app/adamhurwitz.github.io.doordashlite.test-2/base.apk)
I was experiencing the same issue with rules 1.0.0 and runner 1.0.0. Though I was able to solve it by just adding espresso-core 3.0.0. Which avoids the use of outdated versions such as suggested in Erics answer.
com.android.support.test:rules:1.0.0
com.android.support.test.runner:1.0.0
com.android.support.test.espresso:espresso-core:3.0.0
EDIT:
Meanwhile one should use the AndroidX libraries, the current versions as of 2021 / 12 are:
androidx.test:rules:1.4.0
androidx.test:runner:1.4.0
androidx.test:core:1.4.0
androidx.test.espresso:espresso-core:3.4.0
The up to date versions can in general be found on the Android Developers page.
I had the same problem. To fix it I changed the following dependencies from:
com.android.support.test:runner:1.0.0
com.android.support.test:rules:1.0.0
to:
com.android.support.test:runner:0.5
com.android.support.test:rules:0.5
UPDATE:
Michael's answer is better, don't use this outdated version anymore!
I've following dependency added in build.gradle file.
compile 'com.aerisweather:aeris-maps-lib:2.0.0#aar'
It is from
https://oss.sonatype.org/content/repositories/comaerisweather-1027/com/aerisweather/aeris-maps-lib/2.0.0/
If you the see artifacts from following URL, It has android support v7 library classes.
https://oss.sonatype.org/#nexus-search;quick~aerisweather
I want to exclude that package when running/packaging the application. I'm unable to run/package the app due to duplicate class error.
I've tried adding configurations like this,
configurations {
all*.exclude group: 'com.android.support', module: 'appcompat-v7'
}
But this excludes it from entire project which leads me to many errors.
I've tried everything but still getting following error.
Error:Execution failed for task ':transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v7/appcompat/R$anim.class
This library has also as dependency support-v4 and mediarouter-v7.
You need to exclude them all from aeris-maps-lib and include as your own dependency.
def supportLibraryVersion = '25.0.1'
dependencies {
compile "com.android.support:support-v4:${supportLibraryVersion}"
compile "com.android.support:support-annotations:${supportLibraryVersion}"
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
//... other deps
compile ('com.aerisweather:aeris-maps-lib:2.0.0#aar', {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'mediarouter-v7'
})
}
PS.
aeris-maps-lib has also com.google.android.gms:play-services dependency, which is the whole Play Services package (it's large) and you will need to enable MultiDex or shrink code with proguard.
not a direct answer, but an advice.
The exclusion feature provided by gradle (exclude method invocation) doesn't work for contents inside local aar files as those contents aren't defined by dependency management and hence aren't recognised by the same.
As far as the dependency resolution is concerned, the aar file is an individual unit (including all the resources/classes within). So the file needs to be built in a way which doesn't include those entries; Or if the file is not built by you, you can unpack and omit the files in question and repack.
While there may be hackish ways to drop certain files using gradle (I couldn't find any reliable one yet), where we could possibly hook into some intermediate build steps and get rid of the files; but the generally advised best practise is to avoid packaging publicly available dependencies into the aar/jar to avoid duplicate entry issues and keep the aar/jar size smaller.
Note: I know there are a thousand questions about this error on SO, and I swear I've read all of them, but none of the solutions have worked. (More detail on my many unsuccessful attempts below.)
When I try to build my cordova app for Android, I get the following error:
:processDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':processDebugResources'.
> 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
My question: How can I fix this and build my app?
Background
From the many SO answers I've read, I know this is almost certainly a problem with plugins adding duplicate Google Play dependencies. My app (and all its plugins) were working great until my most recent plugin addition: the Urban Airship cordova plugin. Here is my current plugin list:
cc.fovea.cordova.purchase 4.0.0 "Purchase"
com.xmartlabs.cordova.market 1.1 "Market"
cordova-google-play-services 25.0.0 "Google Play Services for Android"
cordova-plugin-analytics 1.3.3 "Google Analytics Plugin"
cordova-plugin-console 1.0.2 "Console"
cordova-plugin-device 1.1.0 "Device"
cordova-plugin-dialogs 1.2.0 "Notification"
cordova-plugin-file 3.0.0 "File"
cordova-plugin-inappbrowser 1.1.1 "InAppBrowser"
cordova-plugin-network-information 1.1.0 "Network Information"
cordova-plugin-splashscreen 3.0.0 "Splashscreen"
cordova-plugin-statusbar 2.0.0 "StatusBar"
cordova-plugin-whitelist 1.2.0 "Whitelist"
cordova-plugin-x-socialsharing 5.0.7.1 "SocialSharing"
cordova-plugin-x-toast 2.3.1 "Toast"
urbanairship-cordova 4.0.1 "Urban Airship"
I've read through every plugin's plugin.xml, and the only other one which references Google Play Services is Appfeel's cordova-plugin-analytics.
I'm using cordova 5.4.1 and cordova-android#4.1.1. Here is my config.xml. I'm not using an IDE.
Also, another answer recommended investigating the compile dependencies and looking for duplicates using ./gradlew dependencies. Doing so gave me this output. As you can see, it has many duplicates: lots of com.google.android.gms and lots of com.android.support and lots of CordovaLib.
What I've tried
Removing and re-adding the Android platform. It changed nothing.
Removing and re-adding cordova-google-play-services. I was unable to remove it and got the following error:
Error: The plugin 'cordova-google-play-services' is required by (cordova-plugin-analytics), skipping uninstallation.
(I did not install cordova-google-play-services explicitly – it was installed automatically by cordova-plugin-analytics.)
Earlier in my project I tried to use the more common analytics plugins by danwilson and cmackay, but I ran into similar issues just installing those plugins, which is why I'm now using Appfeel's Google Analytics plugin (which installed without problems and works great).
Adding a build-extras.gradle in /platforms/android with the following code:
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.google.android.gms', module: 'play-services-analytics'
}
When I run this, I do avoid the "more than one library" error, but instead I get dozens of package-does-not-exist errors like this one:
:compileDebugJava
/Users/sarah/Development/app/platforms/android/src/com/urbanairship/cordova/CordovaAutopilot.java:31: error: package android.support.v4.app does not exist
import android.support.v4.app.NotificationCompat;
^
I've also tried a variety of other exclusion combinations that were motivated from the ./gradlew dependencies output I mentioned above.
Updating the Android platform, updating cordova
Making sure I have the most current version of gradle
Updating everything I can in the Android SDK Manager. Here's a screenshot of the Extras I have installed. And a screenshot of Tools. And other SDK packages.
Adding a build-extras.gradle that uses dependencies with exclusions instead of configurations. I've tried about twenty different combinations of packages and groups and modules (again motivated by the ./gradlew dependencies output) . Sometimes I try excluding only groups or only modules. Sometimes I try excluding with or without the version numbers. (As you can see, I don't really know what I'm doing re:gradle.) Here's one attempt:
dependencies {
compile('com.urbanairship.android:urbanairship-sdk:6.4.1') {
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-basement'
exclude group: 'com.android.support', module: 'support-v4'
}
}
Here's another:
dependencies {
compile('com.urbanairship.android:urbanairship-sdk:6.4.1') {
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
exclude group: 'com.google.android.gms', module: 'play-services-basement'
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.google.android.gms:play-services-location:8.1.0') {
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
exclude group: 'com.google.android.gms', module: 'play-services-basement'
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:cardview-v7:23.1.0') {
exclude group: 'com.android.support', module: 'support-v4'
}
}
In my research I discovered that the Urban Airship plugin has its own build-extras.gradle in /platforms/android/urbainairship-cordova. So I tried adding compile exclusions to that build-extras.gradle instead using a zillion combinations like those I mentioned in #7. Eventually I exclude too much and end up with package-does-not-exist errors like those shown in #3, but backing off results in the same more-than-one-library error.
Commenting out <dependency id="cordova-google-play-services" /> in the analytics plugin's plugin.xml.
My question
Sorry for the long post, but this all seems like relevant troubleshooting info! To restate my question from the beginning: how do I fix this error and build successfully?
I ran into this recently with com.android.support conflicts and (for that)
I would highly recommend https://github.com/dpa99c/cordova-android-support-gradle-release which is a "plugin to align various versions of the Android Support libraries specified by other plugins".
To avoid the problem of removing all versions of the support libs, which can lead plugins having missing dependencies/failing gradle syncs, they use some clever gradle dependency resolution to solve the problem:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group in ['com.android.support'] && !(details.requested.name in ['multidex', 'multidex-instrumentation'])) { details.useVersion "26.1.0"}
}
}
I reckon you could do the same for your Google Plays Services libs by adding another inner condition:
if (details.requested.group in ['com.google.android.gms'] && !(details.requested.name in ['multidex', 'multidex-instrumentation'])) {
details.useVersion "11.8.0" //Or whichever GMS level you're targeting.
}
I have a module dependency in my project. This dependency contains old version of google services. But my main project includes the latest one. As a result I get exception while building project:
Error:(93, 17) error: cannot find symbol method getMapAsync(<anonymous OnMapReadyCallback>)
It seems that Gradle tries to use older version of google services api. How can I exclude this library in a final project? I've heard about transitive dependencies. Is it correct way to solve this problem?
This is how you can exclude a transitive dependency:
configurations {
compile.exclude module: 'commons'
all*.exclude group: 'org.gradle.test.excludes', module: 'reports'
}
dependencies {
compile("org.gradle.test.excludes:api:1.0") {
exclude module: 'shared'
}
}
See https://docs.gradle.org/current/userguide/dependency_management.html
If you don't want to exclude the dependency you can also use a resolutionStratgy to force a version number across projects
See https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html