Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

dex

dx

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?

like image 638
Sadra Naddaf Avatar asked Dec 01 '11 20:12

Sadra Naddaf


People also ask

Which will convert .class files to .DEX files?

bat --dex' command that can be used to convert Java byte code (. class) files into a Dalvik executable (. dex) file. The next tool used in the "ant -verbose debug" command is the "dex" tool, which converts Java byte code into a .

What is responsible for converting Java .class files into .DEX files?

Dalvik programs are written in Java using the Android application programming interface (API), compiled to Java bytecode, and converted to Dalvik instructions as necessary. A tool called dx is used to convert Java .class files into the .dex format.

What is difference between jar file and class file?

You can use JAR files to store class files. The class file does not target a specific hardware platform, but instead targets the Java virtual machine architecture. You can use JAR as a general archiving tool and also to distribute Java programs of all types, including applets.


2 Answers

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"
like image 93
Pavel Netesa Avatar answered Oct 22 '22 14:10

Pavel Netesa


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

like image 38
Ruchir Baronia Avatar answered Oct 22 '22 12:10

Ruchir Baronia