6

I have searched extensively on the web for a comprehensive guide to creating an Android DEX file (Java Dalvik bytecode) using the Android SDK DX tool.

My aim is to create a Jar file that contains DEX byte code which can be loaded by an application at runtime.

To create the Jar file I have been following these steps:

  1. Java source code containing a public class (Name.java)
  2. Compile .java file from step 1 into .class file using javac Name.java
  3. Created a Jar file from the class file. jar cvf output.jar name.class
  4. Use the dx tool to convert class file into classes.dex. ./dx --dex --output=classes.dex output.jar
  5. Use aapt to repackage the classes.dex file with the jar file.

So far I have managed to make it to step 4, which is where I am experiencing issues. When running the dx tool, I get the following error:

UNEXPECTED TOP-LEVEL EXCEPTION:
java.io.FileNotFoundException: /home/del/Desktop/AndroidJarBuilder/output.jar (No such file or directory)
 at java.util.zip.ZipFile.open(Native Method)
 at java.util.zip.ZipFile.<init>(ZipFile.java:215)
 at java.util.zip.ZipFile.<init>(ZipFile.java:145)
 at java.util.zip.ZipFile.<init>(ZipFile.java:159)
 at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
 at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
 at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
 at com.android.dx.command.dexer.Main.processOne(Main.java:632)
 at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
 at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
 at com.android.dx.command.dexer.Main.run(Main.java:246)
 at com.android.dx.command.dexer.Main.main(Main.java:215)
 at com.android.dx.command.Main.main(Main.java:106)
1 error; aborting

I wonder if anyone has experienced this problem before, i could not find any answers on Stack Overflow, and the rest of the web did not provide me with any solutions.

Thanks in advance.

asked Mar 30, 2015 at 14:06
4
  • The error is pretty clear that "output.jar" doesn't exist. Commented Mar 30, 2015 at 15:52
  • yes it is pretty clear. However output.jar does in fact exist. Commented Mar 31, 2015 at 8:08
  • I wouldn't run the dx command on output.jar if output.jar wasn't present would I! Commented Mar 31, 2015 at 8:48
  • The only way I'm aware of to get that exception is if the file doesn't exist, or the user that dx is running as doesn't have the right permissions on the file/containing directory/etc. Commented Apr 1, 2015 at 4:03

1 Answer 1

1

Turns out the output of the jar command needs to be the same as the name of the class.

Renaming output.jar to Name.jar seemed to resolve the issue.

answered Mar 31, 2015 at 10:49
Sign up to request clarification or add additional context in comments.

1 Comment

This makes no sense. The name of the jar is arbitrary, and a jar typically contains many classes.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.