Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patching Java .jar files and Android .aar files #15

Open
continuemycoding opened this issue Sep 23, 2017 · 9 comments
Open

Patching Java .jar files and Android .aar files #15

continuemycoding opened this issue Sep 23, 2017 · 9 comments

Comments

@continuemycoding
Copy link

patch-lib in dexpatcher-gradle-samples is not only patch library, I need patch only jar library sometimes.

@Lanchon
Copy link
Member

Lanchon commented Sep 23, 2017

hi, i don't understand.

  1. what exactly do you want to patch? an APK or something else?
  2. what do you want as output?

thanks

@continuemycoding
Copy link
Author

Sorry for my poor english.I want to patch a jar library to output a jar library.

@continuemycoding
Copy link
Author

I can do it using smali, but it is hard. I want to modify Android Jar files at source-level using Java.
@Lanchon thanks

@Lanchon
Copy link
Member

Lanchon commented Sep 23, 2017

what is an Android Jar file? are you talking about an "Android library" with an ".aar" extension?

@continuemycoding
Copy link
Author

I have made a mistake with JAR (Java ARchive), I want to patch a jar file to output a jar file or patch a aar file to output a aar file.

@continuemycoding
Copy link
Author

I want to patch some android jar file no source code, modify some code logic, use it for my app development.

@Lanchon
Copy link
Member

Lanchon commented Sep 23, 2017

Contents of different file types and what DexPatcher can patch

  • jar files are Java libraries and have compiled Java bytecode in them.
  • aar files are Android libraries and have a jar file (not Dalvik/Android bytecode!!!) and source code of Android resources in them.
  • dex files are Dalvik executables and have compiled Dalvik/Android bytecode in them.
  • apk files are Android apps and have dex files and compiled Android resources in them.

DexPatcher patches Dalvik/Android bytecode, not Java bytecode, so it only works with dex and apk files.

to patch jar or aar files you need to use solutions made for Java bytecode, of which are many.

@continuemycoding
Copy link
Author

Java bytecode can be converted to Dalvik/Android bytecode by dex2jar tools.so I hope you can upgrade DexPatcher support patch jar to output jar.

@Lanchon
Copy link
Member

Lanchon commented Sep 23, 2017

dxp does not patch java bytecode and never will.

How to patch a .jar file

if you trust dex2jar (sometimes it works fine... depends), then you can:

  • use android build tool's dx command to transform source.jar to source.dex.
  • compile your dxp patch using javac, adding dexpatcher-annotations-x.x.x.jar and source.jar to the compile classpath.
  • use dx to transform you compiled class files to patch.dex.
  • use the dexpatcher-tool command line tool to patch source.dex with patch.dex and produce patched.dex.
  • use d2j-dex2jar to transform patched.dex to patched.jar.

example: the dexpatcher-tool test build system and shell script.

How to patch an .aar file

inside the aar file there is a classes.jar file. extract it and patch it as per the above steps. if you need to patch the aar resources, go ahead and edit them manually; resources in aar files are not compiled.

@Lanchon Lanchon reopened this Sep 23, 2017
@Lanchon Lanchon changed the title Can you add library patcher only? Patching Java .jar files and Android .aar files Sep 23, 2017
@Lanchon Lanchon removed the invalid label Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants