pxb1988 / dex2jar

Tools to work with android .dex and java .class files
Apache License 2.0
12.36k stars 2.12k forks source link

dex2jar: use classes as android library? #615

Open mhous33 opened 7 months ago

mhous33 commented 7 months ago

I am trying to rebuild an apk in android studio that I decompiled with jadx. The apk depends on a deprecated version of the koin dependency injection framework. I have tried adding current koin dependencies to my build.gradle, but it does not resolve the dependencies. I have also tried adding the koin java source to the project, but the source does not compile. So I had the idea to use dex2jar to get the koin class files and build a standalone jar to add to my project. I think I have done this correctly, as the koin import statements are satisified, however, when I try to build the apk, android studio throws the error: "error: cannot find symbol" referring to one of the classes in the koin jar library. Any ideas as to why this is not working?

ThexXTURBOXx commented 7 months ago

Three possibilities:

  1. dex2jar is not perfect - in fact no dalvik converter is perfect and they cannot be perfect either. It could just be one of the cases where dex2jar just cannot deal with the given dalvik bytecode
  2. The class it is referring to could be a nested class. There are a few well-known problems within dex2jar when it tries to deal with those
  3. Try to use my fork, which has a few more fixes (and also an experimental -cf option, which might give better/more accurate output)

Overall, you have not provided enough data to figure this issue out yet - no mention of the specific symbol name or anything.

mhous33 commented 7 months ago

Thanks for the reply! I just tried again, using your latest release. Here are my steps: 1) d2j-dex2jar.sh .apk 2) extract dex2jar.jar 3) delete all contents except org/koin directory 4) jar -cf koin.jar * 5) copy koin.jar to android studio project libs directory 6) In android studio: project structure > dependencies > Add Dependency > JAR/AAR Dependency libs/koin.jar implementation This produces the following in my build.gradle dependencies list: implementation(files("libs/koin.jar")) 7) Run app

This produces the following error:

/home/mhous33/AndroidStudioProjects/RetroRazr/app/src/main/java/com/motorola/retrorazr/RazrApplication.java:24: error: cannot find symbol ComponentCallbacksExtKt.startKoin$default(this, this, CollectionsKt.listOf((Object[]) new Function1[]{KoinModulesKt.getButtonsModule(), KoinModulesKt.getSoftKeysModule(), KoinModulesKt.getDialNumberModule(), KoinModulesKt.getStatusBarModule(), KoinModulesKt.getStateModule()}), null, false, null, 28, null); ^ symbol: method startKoin$default(RazrApplication,RazrApplication,List,,boolean,,int,) location: class ComponentCallbacksExtKt

Let me know if I can provide any more details!

ThexXTURBOXx commented 7 months ago

ComponentCallbacksExtKt.startKoin$default is exactly something that dex2jar probably tries to convert to Java, but is not able to: It tries to replace the $ by a ., but this fails as default by its own is a reserved keyword in Java. Hence, it is not possible to properly convert this function. There are a few workarounds, but none has been implemented yet. Your best bet currently is to just rename this function on your own (it should exist - just with a slightly different, but very similar name).

mhous33 commented 7 months ago

Thanks for the info! I will have to try a different approach.