19

When I run my module in Android Studio I get this error:

Error:Android Dex: [GradleDevBuild] Failed to load dx.jar

I have searched endlessly for a solution online but everything is related to eclipse, there is nothing when it comes to Android Studio.

The path to the dex.jar is C:\AndroidSdk\build-tools\26.0.0\lib\dex.jar So it does exists, I've moved it out of the folder and was notified that it moved so AS is aware of where it is. I have tried copying it into the root directory and into the platform-tools folder however that did nothing.

This is the full list of errors that all seem to be stemming from this dx.jar error.

Error:Android Dex: [GradleDevBuild] Failed to load dx.jar
Error:Android Dex: [GradleDevBuild] java.lang.ClassNotFoundException: com.android.dx.command.DxConsole
Error:Android Dex: [GradleDevBuild] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
Error:Android Dex: [GradleDevBuild] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
Error:Android Dex: [GradleDevBuild] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Error:Android Dex: [GradleDevBuild] at org.jetbrains.android.compiler.tools.AndroidDxRunner.loadDex(AndroidDxRunner.java:80)
Error:Android Dex: [GradleDevBuild] at org.jetbrains.android.compiler.tools.AndroidDxRunner.runDex(AndroidDxRunner.java:136)
Error:Android Dex: [GradleDevBuild] at org.jetbrains.android.compiler.tools.AndroidDxRunner.main(AndroidDxRunner.java:336)
Error:Android Dex: [GradleDevBuild] Exception in thread "main" java.lang.NullPointerException
Error:Android Dex: [GradleDevBuild] at org.jetbrains.android.compiler.tools.AndroidDxRunner.runDex(AndroidDxRunner.java:139)
HDJEMAI
  • 7,766
  • 41
  • 60
  • 81
fourthking
  • 311
  • 1
  • 3
  • 17
  • Possible duplicate of [Android ADT error, dx.jar was not loaded from the SDK folder](https://stackoverflow.com/questions/5228453/android-adt-error-dx-jar-was-not-loaded-from-the-sdk-folder) – laffuste Jul 02 '17 at 12:09

8 Answers8

27

I just clean installed Android Studio on OS X and Ubuntu and had the same issue. Fixed by downgrading the build tools to 25.0.3.

For @emjapeve:

  • Select the SDK Manager (Tools/Android/SDK Manager).
  • Hit the SDK Tools tab, by default this only shows current tool versions.
  • Select the Show Package Details checkbox.

From here you can install / uninstall any versions you wish.

doz10us
  • 735
  • 6
  • 16
Mouse
  • 279
  • 2
  • 6
  • 4
    Why do I have to do this? – JohnyTex Jul 17 '17 at 10:10
  • 1
    Note: I ran into the same issue, and by uninstalling the latest version of the build tools, and installing v25.0.3, the problem was resolved. The KEY is to uninstall the other version or it will still get used. – BluJ IT Nov 12 '17 at 03:37
6

If you are doing a Legacy build then here is the fix ...

Android Build Tools when used by Android Studio can produces a dx.jar error during dexing.

Please revert the Android Build Tools to 25.0.3.

Tools->Android->SDK Manager
    Click on SDK Tools
    Check the Show Package Details Box in the Lower Right
    Unselect Android SDK Build Tools 26 or higher
    Select Android SDK Build Tools 25.0.3
jmb
  • 61
  • 1
  • 2
  • Worked perfectly for me, I had 27.0.3 installed and used the steps above and it was able to build the project with no errors. – stuartmclark Mar 31 '18 at 20:17
3

My fix is to copy

android-sdk/build-tools/25.0.3/lib

to the folder

android-sdk/build-tools/26.0.1/lib

Now all works great with Eclipse

Foobnix
  • 679
  • 5
  • 7
2

In my case I copied the dx.jar file from pathToYourSDK/build-tools/25.0.1/lib to pathToYourSDK/build-tools/25.0.1/ and it worked.

1

In sdk manager do the following In my case my 1. Android SDK tools version was 25.2.5 2. Android SDK platform tools version was 26 3. Android SDK Build tools version was 26.0.1

Deleted 3 Installed Android SDK Build tools version 25.0.3 Problem solved You can download and delete corresponding version of package according to your sdk tools version

s99
  • 37
  • 3
1

My case: IntelliJ IDEA, libgdx - project

In my case my Project was not configured for gradle yet after opening it for the first time. I restarted my IDE and clicked on the "configure gradle" Pop-up on the lower right site and it worked.

see this Thread: Module ... is not backed by gradle

Ueffes
  • 146
  • 12
1

With the new Eclipse update, the Android SDK's that are above 25.0.0 are making problems (with the lib\dex.jar) and you can't run the project if you have other SDK's in the same build-tools folder, cause the Eclipse will preselect the latest SDK and you can't switch to 25.0.0. Just remove the SDK's that are above 25 in the folder.

0

No need to uninstall build tools 'normally'. Just enough to go to the .../Sdk/build-tools/ and rename and chmod 000 all the folders for tools older than 24.x.x or 25.x.x (recovered as quickly when needed back)

(had this problem playing with rmaps (ancient project compiled in times of froyo with Eclipse) )

Oleg
  • 11
  • 1