Multiple dex files error - Can't build any longer - Older Project


#1

Hello, I see this issue is affecting lots of older projects.

I was able to completely build my Ionic project and get it onto the Google Play store (it’s still there) but this error is beyond me so far.

I’ve seen several other posts, some with some cryptic answers, others with people asking same thing I am.

So far, I have gathered this:

  • Related to multiple plugins calling for various versions of a file (JAR?)
    – gradle dependencies doesnt work for me, says “no configuration”
    – I haven’t been able to get the “gradle” view from Android studio
    – Adding lines to build.gradle to dexOptions preDexLibraries == FALSE

  • Have tried to remove/add android platform multiple times

  • Have upgraded ionic

  • Have done “ionic state reset”

I can’t seem to find the dependency tree to figure out how to fix this.

FAILURE: Build failed with an exception.

  • What went wrong:

Execution failed for task ‘:transformClassesWithDexForDebug’.

> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;

Can someone help point me in right direction?

THANKS


Ionic Package: Execution failed for task "transform Classes WithDex For Debug"
#2

This used to happen in the native android apps. No idea how it is appearing on ionic.
Anyways, try with adding the following in your build.gradle

defaultConfig {
    multiDexEnabled true
}

Ionic native fcm plugin issue
#3

Thanks for reply, now I get a new error:

Subproject Path: CordovaLib

Starting a new Gradle Daemon for this build (subsequent builds will be faster).

Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.

java.lang.IllegalStateException: buildToolsVersion is not specified.
** at com.google.common.base.Preconditions.checkState(Preconditions.java:173)**
** at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:645)**
** at com.android.build.gradle.BasePlugin$10.call(BasePlugin.java:608)**
** at com.android.build.gradle.BasePlugin$10.call(BasePlugin.java:605)**
** at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:156)**
** at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:120)**
** at com.android.build.gradle.BasePlugin.lambda$createTasks$1(BasePlugin.java:603)**
** at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:93)**
** at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:82)**


I’m not sure why I can’t list the gradle dependencies…

$ gradle -q dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

No configurations


$ gradle projects
:projects

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'my-app’
No sub-projects

To see a list of the tasks of a project, run gradle :tasks
For example, try running gradle :tasks

BUILD SUCCESSFUL


#4

Hmm What i would do is to update my SDK, update cordova,ionic and create a new project and copy the files from the existing ones.
The other solution is to fix the gradle file but i don’t know what other errors it might bring.

Third solution can be that you can safely delete the whole .gradle folder located under project directory.
It will recreate once when you rebuild your project

Thanks
Sourav


#5

Deleted the .gradle folder, no dice still.

Sounds like I need to figure out which plugin(s) are calling the different versions of the files.

The gradle dependencies isn’t working for me.

Any other advice? I’m really sorta stuck here…


#6

Try removing platform and re add it after updation of SDK


#7

Man I can’t figure this out. Something to do with android-support-v4.jar being called multiple times… I’m about to give up.

I’ve been dealing with this for weeks now.

Can anyone explain what the issue is? Is it 2 different plugins each with their own version of the same file?

What is the solution? Remove the plugin? Change android API version? Remove calls in the plugin code to source the file again?

I’ve removed and replaced the android platform multiple times, I believe I’ve updated all plugins (some are old though)


FAILURE: Build failed with an exception.
  • What went wrong:
    Execution failed for task ‘:transformClassesWithDexForDebug’.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.967 secs

Error: /Path/To/App/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformClassesWithDexForDebug’.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformClassesWithDexForDebug’.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.967 secs

Error: /Path/To/App/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformClassesWithDexForDebug’.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

#8

Check your project dependencies. You might be adding dependency for android-support-v4.jar twice or it might already been referenced in your project by some plugin.


#9

Hi baviskarmitesh,

Thanks for responding and trying to help.

So about project dependencies… I’m doing this all through the command line (not android studio) and simply doing things like:

ionic plugin add plugin1
ionic plugin add another

Also, I had read to try “gradle -q dependencies” and similar commands, but I get no output, or a message about not finding any projects (while in the project root with ionic.config.json, package.json etc)

I realize that this first issue is around having duplicate v4 JAR images, but beyond that my knowledge is a bit stretched.

$ find . | grep support-v4.jar
./platforms/android/libs/android-support-v4.jar
./plugins/android.support.v4/android-support-v4.jar
$ find . -type f -name "*" | xargs egrep -A 0 -B 0 "support-v4.jar"
Binary file ./platforms/android/.gradle/2.14.1/taskArtifacts/fileSnapshots.bin matches
Binary file ./platforms/android/.gradle/2.14.1/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin matches
./platforms/android/build/intermediates/dex-cache/cache.xml:        jar="/PathToApp/platforms/android/libs/android-support-v4.jar"
./plugins/android.support.v4/plugin.xml:    <source-file src="android-support-v4.jar" target-dir="libs" />

I’ve tried removing both of the support-v4 files, I’ve tried removing their references in the plugin.xml, I’ve tried overwriting one with another…

Anything else you can suggest to view/determine where the conflict is happening?


#10

First try removing all the plugins depending on support v4 and check if the same error is there. If so open project.properties file and remove support v4 library and rebuild project. If it worked then add first plugin rebuild the entire project if error comes then search hack for that plugin with error or post here plugin name I may help you in that regard


#11

I have this problem also. The project isn’t event that old.


#12

Check your project file with multiple android support remove it should solve your problem


#13

How to remove the multiple android support option. Where is it located


#14

It Will be linked to your project via project.properties or inside some of the plugins. So remove it from individual plugin and keep it referenced from project.properties file.