How to convert .jar or .class to .dex file?

58.3k views Asked by At

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?

5

There are 5 answers

4
Pavel Netesa On BEST ANSWER

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"
8
Justin Breitfeller On

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.

0
Ruchir Baronia On

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

2
annoying_squid On

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 ....

0
scottyab On

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