简体   繁体   English

如何将Jess(.jar文件)库转换为.dex文件,或在Android上运行Java类文件?

[英]How to convert Jess (.jar files) libraries to .dex file, or run java class files on Android?

I am trying to run Jess on Terminal IDE (android), but when I try to run the following: 我试图在终端IDE(android)上运行Jess,但是当我尝试运行以下命令时:

terminal++@192.168.0.102:~/sdcard/myJess$ dx --dex --output=jess.dex Jess71p2/lib/jess.jar

I get the message: 我收到消息:

warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)

UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError
    at java.util.HashMap.makeTable(HashMap.java:569)
    at java.util.HashMap.doubleCapacity(HashMap.java:589)
    at java.util.HashMap.put(HashMap.java:419)
    at com.android.dx.rop.code.RegisterSpec.intern(RegisterSpec.java:71)
    at com.android.dx.rop.code.RegisterSpec.makeLocalOptional(RegisterSpec.java:124)
    at com.android.dx.rop.code.RegisterSpec.withReg(RegisterSpec.java:482)
    at com.android.dx.ssa.SsaRenamer$BlockRenamer$RenamingMapper.map(SsaRenamer.java:325)
    at com.android.dx.ssa.RegisterMapper.map(RegisterMapper.java:53)
    at com.android.dx.ssa.NormalSsaInsn.mapSourceRegisters(NormalSsaInsn.java:43)
    at com.android.dx.ssa.SsaRenamer$BlockRenamer.visitNonMoveInsn(SsaRenamer.java:555)
    at com.android.dx.ssa.NormalSsaInsn.accept(NormalSsaInsn.java:199)
    at com.android.dx.ssa.SsaBasicBlock.forEachInsn(SsaBasicBlock.java:957)
    at com.android.dx.ssa.SsaRenamer$BlockRenamer.process(SsaRenamer.java:341)
    at com.android.dx.ssa.SsaRenamer$1.visitBlock(SsaRenamer.java:146)
    at com.android.dx.ssa.SsaMethod.forEachBlockDepthFirstDom(SsaMethod.java:787)
    at com.android.dx.ssa.SsaRenamer.run(SsaRenamer.java:143)
    at com.android.dx.ssa.SsaConverter.convertToSsaMethod(SsaConverter.java:53)
    at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:100)
    at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:74)
    at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:269)
    at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:131)
    at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:85)
    at com.android.dx.command.dexer.Main.processClass(Main.java:299)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:278)
    at com.android.dx.command.dexer.Main.access$100(Main.java:56)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:229)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:250)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:136)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:113)
    at com.android.dx.command.dexer.Main.processOne(Main.java:247)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183)
    at com.android.dx.command.dexer.Main.run(Main.java:139)
    at com.android.dx.command.dexer.Main.main(Main.java:120)
    at com.android.dx.command.Main.main(Main.java:89)
    at com.spartacusrex.spartacuside.external.dx.main(dx.java:14)
    at dalvik.system.NativeStart.main(Native Method)

I have tried other approaches, like connecting via ssh to other machine, but it is not available and fast as local. 我尝试了其他方法,例如通过ssh连接到其他计算机,但是它不可用并且无法像本地一样快速。 Does anyone know a solution or other method? 有谁知道解决方案或其他方法?

Jess 7 is not compatible with Android. Jess 7与Android不兼容。 Jess 8, which will be released any day now, will be. 杰西8,将会在今天的任何一天发布。 So keep an eye on www.jessrules.com . 因此,请留意www.jessrules.com。

You need to add --no-strict to dx options, and if you are facing OutOfMemory Exception, you should edit your dx script and extend the memory range : 您需要在dx选项中添加--no-strict ,并且如果您遇到OutOfMemory异常,则应编辑 dx脚本并扩展内存范围:

dalvikvm -Xss262912 -Xmx500M -cp $APK com.spartacusrex.spartacuside.external.dx $@

Change the -Xmx500M to your required memory -Xmx500M更改为所需的内存

That is, until you stop receiving OOM exception. 也就是说,直到停止接收OOM异常为止。

For me ,while dexing tools.jar from JDK's tools.jar, it's limit was -Xmx900M after which, no more memory could be allocated because my phone had around 900-990MBs free. 对我来说,从JDK的tools.jar中-Xmx900M tools.jar时,限制是-Xmx900M此后,由于我的手机有大约900-990MB的可用空间,因此无法分配更多的内存。

  • The next step after dexing the class files is to repack any remaining resource file from your jess.jar because dex file has no resources. 解压缩类文件后的下一步是重新打包jess.jar中所有剩余的资源文件,因为dex文件没有资源。
  • Observe the contents of that jar file with java command or with winrar or any file explorer and find resources folder(s). 使用java命令或winrar或任何文件浏览器观察该jar文件的内容,并找到资源文件夹。 You'll probably find more than one such resources folders, extract all of those. 您可能会发现多个这样的resources文件夹,并将其全部提取出来。
  • Make sure that your dex file has name classes.dex then repack all files together in a new jess_for_android.jar, keep all the resources in the same directory tree as they were in original jess.jar file 确保您的dex文件具有名称classes.dex然后将所有文件重新打包到一个新的jess_for_android.jar中,并将所有资源与原始jess.jar文件中的资源保持在同一目录树中

  • Lastly, when you try to use it, use dalvikvm command , not the java or you will(possibly) get errors : 最后,当您尝试使用它时,请使用dalvikvm命令,而不要使用java否则(可能)会出现错误:

     dalvikvm -cp path_To_your_repacked_jar Main_className $@ 

memory options -Xss and -Xmx are optional. 内存选项-Xss和-Xmx是可选的。

Hope this helps, If you get Jess tool working, please provide a link to it. 希望对您有所帮助,如果您可以使用Jess工具,请提供指向它的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM