Android Studio: Failed to load dx.jar

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:AndroidSdkbuild-tools26.0.0libdex.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)

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.


    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
    

    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

    链接地址: http://www.djcxy.com/p/63518.html

    上一篇: 如何将Drawable转换为位图?

    下一篇: Android Studio:无法加载dx.jar