如何从命令行合并两个dex文件

huangapple go评论72阅读模式
英文:

How to merge two dex files from command line

问题

过去的几天里,我深入研究了 Android Studio 在幕后的工作原理。

我探索了许多工具,如 aapt、dx、dalvikvm 等等。

现在我有一个非常简单的问题。我有一个大小约为 2.7MB 的 jar 文件(例如称为 abc.jar),我的应用程序中还有一小段 Java 代码。

首先,我将源代码编译成了 .class 文件。然后,我将我的 .class 文件和 abc.jar 文件一起转换成了 .dex 文件。
这大约花了 40 到 50 秒的时间。但我成功地运行了应用程序。

我用来将源代码和 abc.jar 转换成 dex 文件的命令

dx --dex --output=classes.dex abc.jar *class_files*

现在的问题是,每当我修改我的代码时,我必须重新对所有东西(包括 abc.jar)进行 redex 处理,这需要很长时间。我现在想知道是否有任何方法,我只需对 abc.jar 进行一次 dex 处理,然后每当我对代码进行更改时,只需使用 dexed 版本的 abc.jar,并将其添加到我的源代码中。

就像 Android Studio 一样。如果你添加一些外部库,起初会花费一些时间来对这些进行 dex 处理,但之后无论何时修改代码,都不需要从头开始对所有进行 redex 处理,而是只需使用 pre-dexed 的库版本,并将它们添加到 apk 中。

提前感谢你的帮助。

英文:

From last few days I was getting in depth How actually android studio works behind the hood.

I explored many tools like aapt, dx, dalvikvm and many others.

Now I have a very simple problem. I have a jar file (called abc.jar for example) which is about 2.7 MB and I also have a very small java code in my application.

First i compiled my source code into .class files. Then I dexed my .class files and abc.jar file into .dex file.
It took about 40 to 50 secs. But i was able to run the application successfully.

Command that I used to dex my source code and abc.jar

dx --dex --output=classes.dex abc.jar *class_files*

Now the problem is whenever i modify my code I have to redex all the stuff (including the abc.jar) which takes years. What I now want is that Is there anyway by which i have to just dex abc.jar once and then whenever i make changes to my code i would just take the dexed version of abc.jar and add it to my source code.

Like android studio does. If you add some external libaries, at first it takes some time to dex those libaries but after that whenever you modify your code it does not have to redex all the libaries from scratch instead it just takes the pre-dexed libaries and adds them to the apk.

Thank you in advance

答案1

得分: 2

终于经过几天的研究,我找到了一种方法...

我只是使用了 d8,因为 dx 已被弃用。

d8 dexfile1.dex dexfile2.dex

输出将会是 classes.dex

英文:

Finally after days of research I found a way...

I juts used d8 as dx has been depreciated.

d8 dexfile1.dex dexfile2.dex

Output would be classes.dex

huangapple
  • 本文由 发表于 2020年8月28日 15:08:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63629066.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定