I'm trying to use Jersey on Android by adding
compile org.glassfish.jersey.core:jersey-client:2.16
to my build.gradle file. It gives me an unexpected top-level exception, so I added multiDexEnabled true to it as well.
Now I get:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/inject/Qualifier.class
I figured out that Jersey is trying to import both javax.inject:1 and javax.inject:2.4.0-b09. Okay no problem, we'll exclude the older one as recommended here. So I tried:
compile ('org.glassfish.jersey.core:jersey-client:2.16') {
exclude (module: 'javax.inject:1')
}
and
compile ('org.glassfish.jersey.core:jersey-client:2.16') {
exclude (group: 'javax.inject:javax.inject:1')
}
But the module won't go away no matter what. I'm at the end of my rope here and have no idea why this isn't working.
compile ('org.glassfish.jersey.core:jersey-client:2.16') {
exclude (group:'javax.inject', module:'javax.inject')
}
Worked. Thanks RaGe!
Related
I have tried many different ways of getting Vimeo networking into my app, but nothing has worked. If I remove the implementation it works just fine so I know this is the issue.
compile 'com.vimeo.networking:vimeo-networking:1.1.1'
gives me this error
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
I have searched all over and have yet to find a solution (yes I have tried cleaning and rebuilding the project)
SOLUTION: anthonycr's answer was perfect, but I also had to do this:
implementation ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version") {
exclude group: 'org.jetbrains', module: 'annotations'
}
implementation ('com.vimeo.networking:vimeo-networking:1.1.1') {
exclude group: 'org.jetbrains', module: 'annotations'
}
I believe this is the result of the vimeo-networking library including a dependency which you are also separately including in your gradle file. Looking at the gradle file for a hint, a prime suspect is the intellij annotations jar 'com.intellij:annotations:12.0#jar' dependency, which I have seen cause similar problems when also included in your main project as well as a sub-projects.
The solution to this is to exclude the annotations jar when compiling in the vimeo-networking library as follows:
compile ('com.vimeo.networking:vimeo-networking:1.1.1') {
exclude group: 'org.jetbrains', module: 'annotations'
}
Try this and see if it fixes your build exception. Generally I've seen that the cause for the Unable to merge dex error is that there are multiple definitions of the same class in the final dex file, usually resulting from the inclusion of a jar file multiple times.
I got the following error when doing a release build on Android Studio 3
Error:Error: json 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]
The following is my dependencies:
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:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.evernote:android-job:1.2.0'
compile 'com.amitshekhar.android:android-networking:1.0.0'
compile 'com.facebook.stetho:stetho:1.5.0'
compile "me.tatarka.redux:redux-core:0.10"
compile "me.tatarka.redux:redux-android:0.10"
compile "me.tatarka.redux:redux-android-lifecycle:0.10"
compile "me.tatarka.redux:redux-thunk:0.10"
annotationProcessor "org.immutables:value:2.5.5" // <-- for annotation processor
provided "org.immutables:value:2.5.5" // for annotations
provided "org.immutables:builder:2.5.5" // for annotations
compile "me.tatarka.redux:redux-monitor:0.10"
testCompile 'junit:junit:4.12'
}
It's saying json but I can't find which of the the above dependencies is causing the problem.
Here is what I get when I run
gradlew assembleRelease
Task :app:lintVitalRelease
/Users/kruyvanna/Projects/key/HappyKey_Android2/app/build.gradle: Error: json 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]
Explanation for issues of type "DuplicatePlatformClasses":
There are a number of libraries that duplicate not just functionality of
the Android platform but using the exact same class names as the ones
provided in Android -- for example the apache http classes. This can lead
to unexpected crashes.
To solve this, you need to either find a newer version of the library which
no longer has this problem, or to repackage the library (and all of its
dependencies) using something like the jarjar tool, or finally, rewriting
the code to use different APIs (for example, for http code, consider using
HttpUrlConnection or a library like okhttp.)
1 errors, 0 warnings
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:lintVitalRelease'.
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org
I fixed it by adding:
configurations {
all {
exclude group: 'org.json', module: 'json'
}
}
to module gradle file, no removal of dependencies was needed.
Add this in your app/build.gradle
configurations {
all {
exclude module: 'commons-logging'
}
}
Go to the commandline and look at the dependency tree. This will give you a list of everything that your app uses:
./gradlew dependencies
I added dependencies one by one and found this one causing the error
compile "me.tatarka.redux:redux-monitor:0.10"
I am trying to add the Paho MQTT service (and client) to my Android app, but I am running into a com.android.builder.packaging.DuplicateFileException runtime exception, when running my app.
It appears to me that everything is setup right, and when I clean/build, I get no errors at all.
My app build.gradle file looks like:
dependencies {
compile fileTree(dir: '../org.eclipse.paho.android/service/libs', excludes: ["org.eclipse.paho.client.mqttv3-1.1.0.jar"], include: '')
compile fileTree(include: ['*.jar'], dir: 'libs', excludes: ["*org.eclipse.paho.client.mqttv3-1.1.0.jar"])
compile (project(':org.eclipse.paho.android.service')){
// exclude module: "org.eclipse.paho.client.mqttv3"
transitive=true
}
// Uncommenting the below (when commenting out the above) WORKS.
// However, I need to be able to alter the source, to I do need to be able
// to import the Paho MQTT service as a module to my app.
// compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
// compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
...
However, when I run, I receive a DuplicateFileException exception:
* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK org/eclipse/paho/client/mqttv3/internal/nls/messages_zh_TW.properties
File1: /Users/me/.gradle/caches/modules-2/files-2.1/org.eclipse.paho/org.eclipse.paho.client.mqttv3/1.1.0/89d827ffa47c241f2627421ef1d6c7a8c207a341/org.eclipse.paho.client.mqttv3-1.1.0.jar
File2: /Users/me/myapp/code/myapp-android/org.eclipse.paho.android.service/build/intermediates/bundles/default/classes.jar
My file hierarchy looks like:
which appears ok to me.
Does anyone have any pointers on how to resolve this? The error claims that org.eclipse.paho.client.mqttv3-1.1.0.jar is clashing with classes.jar, but my gradle file explicitly excludes the compiling of org.eclipse.paho.client.mqttv3-1.1.0.jar (or so I think it does).
I'm at a loss here; any pointers are welcomed.
This happens because two of your dependencies are using Eclipse Paho MQTT library.
Following should fix the issue
Add following to your app level gradle file
packagingOptions {
exclude 'META-INF/ECLIPSE_.SF'
exclude 'META-INF/ECLIPSE_.RSA'
}
compile("one-of-your-dependency:1.0.0"){
exclude group: 'org.eclipse.paho'
}
How do I fix this?
Error:Execution failed for task ':androidmapsutils:processReleaseResources'.
> Error: A library uses the same package as this project: com.google.maps.android
If you use enforceUniquePackageName=false you'll eventually stumble upon this bug -
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. java.util.zip.ZipException: duplicate entry: ... BuildConfig.class
and in order to fix that you'll have to check if some of your dependencies have multidex as a dependency in it and exclude it, for example the Facebook SDK -
compile('com.facebook.android:facebook-android-sdk:+') {
exclude group: 'com.android.support', module: 'multidex'
}
You can refer to this Stack Overflow and this Issue Tracker
compile project(path: ':backend', configuration: 'android-endpoints')
compile project(':library')
Check included package name
com.google.maps.android.
Introduction
I created a project in Android Studio. This project was compiling and running flawlessly. I tried to add ImageMagick from the following link:
https://android-arsenal.com/details/1/1416
Files
Here is an overview of my project's file structure. I'll try to restrict it to the important files.
-AppRoot
-build.gradle
-settings.gradle
-app
-build.gradle
-...
-gradle-imagemagick-master
-build.gradle
-...
-...
The root settings.gradle file looks like this:
include ':app'
include ':gradle-imagemagick-master'
The root build.gradle looks like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven {
url "https://jitpack.io"
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The build.gradle file in the app folder looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.apppackage.www.approot"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':gradle-imagemagick-master')
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.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
The build.gradle file in the gradle-imagemagick-master folder looks like this:
plugins {
id 'groovy'
id 'maven-publish'
id "com.jfrog.bintray" version "1.4"
}
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
repositories {
jcenter()
}
dependencies {
compile gradleApi()
compile localGroovy()
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude module: 'groovy-all'
}
}
publishing {
publications {
MyPublication(MavenPublication) {
from components.java
groupId 'com.eowise'
artifactId 'gradle-imagemagick'
version '0.5.2'
}
}
}
bintray {
user = ''
key = ''
publications = ['MyPublication']
pkg {
repo = 'maven'
name = 'gradle-imagemagick'
licenses = ['MIT']
vcsUrl = 'https://github.com/eowise/gradle-imagemagick.git'
version {
name = '0.5.2'
vcsTag = 'v0.5.2'
}
}
}
At this point it will clean, rebuild, and run without error on an android emulator. I also have code that gets called as a result of a button press within my MainActivity that runs without error or crash.
Step 1
The problem comes when I try to use ImageMagick. The first thing I try to do is add the following:
try
{
Magick m = new Magick();
m.convert("", Closure.IDENTITY);
m.convert("", new PatternSet());
} catch (Exception ex) {}
This is within the function called as a result of the button press. At this point I get
Cannot resolve symbol 'Closure'
Cannot resolve symbol 'PatternSet'
as errors on the lines with m.convert. At this point it will not build. I then add the lines
import org.gradle.api.tasks.util.PatternSet;
import groovy.lang.Closure;
to the top of my MainActivity. This fails to build. The errors it yields are:
Error:(18, 33) error: package org.gradle.api.tasks.util does not exist
Error:(19, 19) error: package groovy.lang does not exist
Error:(71, 35) error: cannot find symbol variable Closure
Error:(71, 22) error: cannot access GroovyObject
class file for groovy.lang.GroovyObject not found
Error:(72, 39) error: cannot find symbol class PatternSet
Error:(72, 22) error: cannot access DefaultTask
class file for org.gradle.api.DefaultTask not found
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Step 2
In order to get rid of the first two errors, I added
compile gradleApi()
compile localGroovy()
to the top of the dependencies closure in the build.gradle file in the app folder. At this point I click Build>Rebuild Project and it says BUILD SUCCESSFUL. Then I click the Run button and it fails returning an error:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: C:\Users\<my user>\.gradle\caches\3.3\generated-gradle-jars\gradle-api-3.3.jar
File2: C:\Users\<my user>\.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9\gradle-3.3\lib\groovy-all-2.4.7.jar
Step 3
From what I've read, usually this can be fixed or worked around by adding
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'
}
to the android closure (within the build.gradle file in the app folder). I've tried different combinations of these including using pickFirst rather than exclude. If my packagingOptions closure does not contain the line exclude 'META-INF/LICENSE' or pickFirst 'META-INF/LICENSE' it continues to return the same error (Duplicate files copied above).
When I add
packagingOptions {
exclude 'META-INF/LICENSE'
}
to my android closure, I am able to Build>Rebuild Project and I get BUILD SUCCESSFUL. Then I click the Run button and I get a new error:
Error:trouble processing "javax/xml/XMLConstants.class":
Error:Ill-advised or mistaken usage of a core class (java.* or javax.*)
Error:when not building a core library.
Error:This is often due to inadvertently including a core library file
Error:in your application's project, when using an IDE (such as
Error:Eclipse). If you are sure you're not intentionally defining a
Error:core class, then this is the most likely explanation of what's
Error:going on.
Error:However, you might actually be trying to define a class in a core
Error:namespace, the source of which you may have taken, for example,
Error:from a non-Android virtual machine project. This will most
Error:assuredly not work. At a minimum, it jeopardizes the
Error:compatibility of your app with future versions of the platform.
Error:It is also often of questionable legality.
Error:If you really intend to build a core library -- which is only
Error:appropriate as part of creating a full virtual machine
Error:distribution, as opposed to compiling an application -- then use
Error:the "--core-library" option to suppress this error message.
Error:If you go ahead and use "--core-library" but are in fact
Error:building an application, then be forewarned that your application
Error:will still fail to build or run, at some point. Please be
Error:prepared for angry customers who find, for example, that your
Error:application ceases to function once they upgrade their operating
Error:system. You will be to blame for this problem.
Error:If you are legitimately using some code that happens to be in a
Error:core package, then the easiest safe alternative you have is to
Error:repackage that code. That is, move the classes in question into
Error:your own package namespace. This means that they will never be in
Error:conflict with core system classes. JarJar is a tool that may help
Error:you in this endeavor. If you find that you cannot do this, then
Error:that is an indication that the path you are on will ultimately
Error:lead to pain, suffering, grief, and lamentation.
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process
Conclusion
This is where I am currently stuck. It seems that I shouldn't be adding the 2 compile lines in my app folder's build.gradle file because these lines are already in the gradle-imagemagick-master's build.gradle file. I believe that this duplicate compiling is causing the duplicate license files error. Is there another way that I can get the imports in my MainActivity to be recognized?