从Java源代码创建DEX文件 [英] Creating a DEX file from Java source code

查看:268
本文介绍了从Java源代码创建DEX文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上广泛搜索了使用Android SDK DX工具创建Android DEX文件(Java Dalvik字节码)的综合指南。

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.

我的目标是创建一个包含DEX字节代码的Jar文件,该代码可以在运行时由应用程序加载。

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

要创建Jar文件,我一直在执行以下步骤:

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


  1. 包含公共类的Java源代码(Name.java)

  2. 将步骤1中的.java文件编译成.class文件使用 javac Name.java

  3. 从类文件创建一个Jar文件。 jar cvf output.jar name.class

  4. 使用dx工具将类文件转换为classes.dex。 ./ dx --dex --output = classes.dex output.jar

  5. 使用aapt重新打包classes.dex文件jar文件。

  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.

到目前为止,我已成功进入第4步,这是我遇到问题的地方。运行dx工具时,我收到以下错误:

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

我想知道是否有人之前遇到过这个问题,我在Stack Overflow上找不到任何答案,并且网络的其余部分没有向我提供任何解决方案。

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.

提前致谢。

推荐答案

结果jar命令的输出需要与类的名称相同。

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

output.jar 重命名为 Name.jar 似乎解决问题。

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

这篇关于从Java源代码创建DEX文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆