问题
This may seem a bit weird, but I need to implement it.
I have an APK & I dont have its source code. Now I can break the apk , modify & repack it, but while doing so, I need to add my custom jar to it & make the app/apk refer this library/jar at run time.
If I just create a folder libs inside the apk & put my jar inside, I get a NoClassDefFound error.
Any idea how to implement it using ANT or any other tool ? Thanx in advance
回答1:
The Jar(s) you attach in your android project, are not copied into APK.
What happens is that, The code of your Jar(s) file becomes part of your Android code. That means you can not simply place(or copy) Jar files in your APK.
But, There is a way around. In APK, your source code can be found in the classes.dex file.
What you need to do is, follow the steps
1 - Extract APK using winRAR
2 - Convert classes.dex to Jar using dex2jar
3 - Extract Jar file
4 - You will have source code in *.class, You can use JdGUI to convert it to *.java.
Now, you can create new android project and use the code.
回答2:
This is not possible. All the classes are already compiled. You will need to "build" the APK again so that proper references could be remapped.
来源:https://stackoverflow.com/questions/16013169/how-can-i-add-a-jar-to-an-apk-make-the-apk-refer-to-it-without-eclipse