2

I am trying to build Android apps manually from the command line.
But, whenever I am running dx.bat command which is located inside the Android SDK build-tools directory, I am always getting an error. Whichever option I give, I always get the same error. While running dx --help, I got this error :
-Djava.ext.dirs=E:\.android\SDK\build-tools\29.0.2\lib is not supported. Use -classpath instead. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.

When I had Android Studio, I didn't get any such problems. What mistake am I doing and how to get the dx.bat file to work right?

Kanzariya Hitesh
  • 118
  • 1
  • 15
Puspam
  • 2,137
  • 2
  • 12
  • 35

1 Answers1

6

I had solved this issue by editing the dx.bat file.
As mentioned in the error

-Djava.ext.dirs=E:\.android\SDK\build-tools\29.0.2\lib is not supported.  Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

I had just changed this line of the dx.bat file (last line) :

call "%java_exe%" %javaOpts% -Djava.ext.dirs="%frameworkdir%" -jar "%jarpath%" %params%

to this :

call "%java_exe%" %javaOpts% -classpath "%frameworkdir%" -jar "%jarpath%" %params%
Puspam
  • 2,137
  • 2
  • 12
  • 35
  • 2
    I had the same issue and above solution works, at least for d8 or dx.bat. However, since Android Studio notices such changes, it removes those files from time to time. Thus, the better solution is to point JAVA_HOME (temporarily) to a Java8 installation and no change of above file is necessary. It seems like the option -Djava.ext.dirs= is not supported anymore in Java11 or Java15 and hence above error occurs. – auermich Nov 12 '21 at 12:23