How to convert .jar or .class to .dex file?
Asked Answered
G

5

19

I'm going to edit the Opera Mini v6.5 server because it is blocked in our country.

Now I have unpacked the ‍‍‍‍‍‍‍.apk file extracted classes.Dex then converted it via dex2jar.bat, now modified the server.

My problem is I want to repack the .jar or .class to classes.Dex. How do I do it?

Gymnast answered 1/12, 2011 at 20:53 Comment(0)
H
36

Here is a solution that was helpful in my case...

Suppose .jar file sits in "c:\temp\in.jar". In command prompt window cd to ..\android-sdk\platform-tools. To get .apk execute:

dx --dex --output="c:\temp\app.apk" "c:\temp\in.jar"

To get .dex file execute:

dx --dex --output="c:\temp\dx.dex" "c:\temp\in.jar"
Hartsock answered 31/12, 2012 at 12:20 Comment(4)
Not sure if this is because I'm on OS X but my dx binary is in sdk/build-tools/<version> instead of sdk/platform-tools.Zel
I run this line: 21.1.1 congba$ dx --dex --output="/Volumes/DATA/Dev_Tools/ba.dex" "/Volumes/DATA/Dev_Tools/gdx.jar" and get error: -bash: dx: command not foundAcie
@RichardFung Same with LinuxFlorentinaflorentine
i got no classfiles specifiedChadd
T
3

For mac, the dx command tool is stored in different directory as said in the top answer. Here is how you do it in mac:

   exampleName$ /Users/exampleName/Library/Android/sdk/build-tools/25.0.2/dx --dex --output="/Users/exampleName/Downloads/classes-dex2jar.jar" "/Users/exampleName/Downloads/name.dex"

More detailed explanation:

  • The dx tool is stored in the android SDK, but in a different directory on macs, the path for a mac is /Users/exampleName/Library/Android/sdk/build-tools/25.0.2/
  • The command is the same for windows and mac, the path is just different
  • The command for both platforms is dx --dex--output="c:\temp\app.apk" "c:\temp\in.jar"
  • The tool may take a few minutes to produce the dex file

If it's still not working for some reason, make sure you are following these requirements:

enter image description here

I know this is late, but I had to figure this out on my own after hours of trial and error—hope it helps some other mac user

Trundle answered 18/7, 2017 at 20:6 Comment(0)
C
1

To avoid downloading the entire Android Studio: You can go to command-tools download and extract the folder. Then go into it and find your sdkmanager tool. Then on your command-line type sdkmanager "build-tools;28.0.1". You can select which version of build-tools is appropriate depending on the java version you are working with. This will download it into the root directory of your command-line tools. Go into this folder and you should see the dx tool. Then you can type dx --dex --output="nameoffile.dex" nameoffile.jar.

A little extra note: If you are trying to convert a massive jar you might get a OUT OF MEMORY error. In this case you just pass the JVM the increase heap option dx -JXmx256m ....

Cashman answered 3/1, 2019 at 21:45 Comment(2)
Unfortunaly, dx -JXmx256m --dex --output="name.dex" "name.jar" doesn't work(No command specified).Despain
You should write one file at a timeLemay
S
0

To dexify a jar file, you would use dx.bat inside of your sdk's platform-tools folder. You can also look at the -dex task inside of the build.xml file inside of your tools\ant folder in your SDK.

Stinking answered 1/12, 2011 at 21:15 Comment(8)
Thanks for your answer now i have another problem i used this command line in run but nothing happened just opened and closed dx.bat e:\users\sadra\desktop\android-sdk-windows\platform-tools\dx –dex –output=classes.dex –locals=full –positions=lines classes.jar and i didn't find build.XML in that folder now what should i do???Gymnast
Try looking in e:\users\sadra\desktop\android-sdk-windows\tools\ant\build.xml. You could also just use ant (by setting the properties needed by the -dex step) to do your conversion.Stinking
thanks a lot again but I'm no Ob and didn't understand what u said i didn't find build.xml again also another item how about using smali and how to ???Gymnast
Are you sure you got no error when you ran the dx command? If there was no error, you should see a classes.dex file sitting in the directory somewhere.Stinking
here is the link what i see after using that it says no command linkGymnast
again hi i have updated my sdk and build.xml apeared I changed my command line to this C:\GOOGLE\android-sdk-windows\platform-tools\dx ––dex ––output=classes.dex –locals=full ––positions=lines jsdt.jar now after taking a moment there is an error :5error ; aborting so what should i do now??Gymnast
Unfortunately I don't know what that error means. Are you sure it's not giving you something more helpful?Stinking
You can do some research on the ANT build system. The file should be in the directory I pointed you to. It has the code necessary to run a dex target that should convert a jar to a dex / apk file.Stinking
D
0

Sounds like you need the apktool, it allows you to repack and resign a apk, without the need to get in to running dx and aapt yourself.

Here's an article on how to unpack and repack

Daysidayspring answered 30/5, 2013 at 9:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.