Trying to create a .dex file, returns compilation error

After compiled a simple test and created the .jar file using Java 17, knowing Android 14 SDK (API 34) is based on Java 17 , I tried to compile with Android sdk d8.bat utility to obtain a .dex file with this command since they are same Java version for compatibility:

C:\path-to-project>C:\...\Android\Sdk\build-tools\34.0.0\d8.bat --release --output C:\path-to-project\target --lib "C:\Program Files\Android\Android Studio\plugins\android\lib\android.jar" C:\path-to-project\target\myproject.jar

but I obtain this compilation error :

Warning in C:\path-to-project\target\myproject.jar:org/springframework/boot/loader/net/protocol/nested/NestedLocation.class at Lorg/springframework/boot/loader/net/protocol/nested/NestedLocation;create(ILjava/lang/String;)Lorg/springframework/boot/loader/net/protocol/nested/NestedLocation;:
Type `java.nio.file.Path` was not found, it is required for default or static interface methods desugaring of `Lorg/springframework/boot/loader/net/protocol/nested/NestedLocation;create(ILjava/lang/String;)Lorg/springframework/boot/loader/net/protocol/nested/NestedLocation;`
Error in C:\path-to-project\target\myproject.jar:org/springframework/boot/loader/jar/NestedJarFileResources.class at Lorg/springframework/boot/loader/jar/NestedJarFileResources;addToExceptionChain(Ljava/io/IOException;Ljava/io/IOException;)Ljava/io/IOException;:
com.android.tools.r8.internal.Sb: Class or interface java.io.IOException required for desugaring of try-with-resources is not found.
Compilation failed
Exception in thread "main" java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: Lorg/springframework/boot/loader/jar/NestedJarFileResources;addToExceptionChain(Ljava/io/IOException;Ljava/io/IOException;)Ljava/io/IOException;, origin: C:\path-to-project\target\myproject.jar:org/springframework/boot/loader/jar/NestedJarFileResources.class
        at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:126)
        at com.android.tools.r8.D8.main(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:5)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: Lorg/springframework/boot/loader/jar/NestedJarFileResources;addToExceptionChain(Ljava/io/IOException;Ljava/io/IOException;)Ljava/io/IOException;, origin: C:\path-to-project\target\myproject.jar:org/springframework/boot/loader/jar/NestedJarFileResources.class

and it looks related to this java.nio.file.Path which doesn’t allow or just fails on desugaring in some spring framework jar file… do you know maybe what’s related to con compiling that vaadin flow project?

Thanks in advance!
Cheers!

While Android applications are written in Java, they are executed on the Dalvik virtual machine, not the JVM .
The Dalvik virtual machine allows Android applications to run on different underlying architectures without the need for recompilation

please refer :

Hello @ecohen , in fact I was thinking and trying about converting from .jar , which can’t be executed on Dalvik, and create a .dex file , which can be executed from DalvikVM…
So as far as I got documented, there is that dx.bat/d8.bat (depends from the Android API version) utility that should do that.
Also because it should just read those .class files which are in fact contained in target\classes and those .class comes from .java though … just I can’t find why it breaks at that :

Exception in thread "main" java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete,...

maybe in pom.xml file should be added something like to enable the full r8 so it could be compiled as like as I read somewhere it can be enabled in gradle if used too?

Seems it created the classes.dex file modifying command as like :

C:\...\Android\Sdk\build-tools\34.0.0\d8.bat --release --output C:\path-to-project\target --lib "C:\Program Files\Android\Android Studio\plugins\android\lib\android.jar" C:\path-to-project\target\myproject.jar --min-api 34 --no-desugaring

because probably I have to specify to use Java 17 of API 34 and excluding totally Java 8. I’ll let you know if I’ll reach to create an .apk file to run on android device…

In the meanwhile , thanks for now!

A kind reminder that this is a Vaadin forum (and the Vaadin Flow category in it) and not an Android forum.

1 Like