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?

Sadra
  • 2,480
  • 2
  • 20
  • 32

5 Answers5

35

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"
Pavel Netesa
  • 2,092
  • 1
  • 16
  • 11
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

Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83
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 ....

annoying_squid
  • 513
  • 5
  • 10
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

scottyab
  • 23,621
  • 16
  • 94
  • 105
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.

Justin Breitfeller
  • 13,737
  • 4
  • 39
  • 47
  • 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??? – Sadra Dec 02 '11 at 12:12
  • 1
    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. – Justin Breitfeller Dec 02 '11 at 14:47
  • 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 ??? – Sadra Dec 02 '11 at 15:10
  • 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. – Justin Breitfeller Dec 02 '11 at 15:16
  • here is the link what i see after using that it says no command [link](http://www.mediafire.com/?418z8pbjhoo3ch4) – Sadra Dec 02 '11 at 21:16
  • 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?? – Sadra Dec 04 '11 at 13:52
  • Unfortunately I don't know what that error means. Are you sure it's not giving you something more helpful? – Justin Breitfeller Dec 04 '11 at 16:42
  • 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. – Justin Breitfeller Dec 04 '11 at 23:59