I'm trying to edit an .apk file changing some variables or adding some functions in java files in it.
So, firstly, I used apktool to decompile the .apk. Then, I used dex2jar to make classes.dex to classes.jar and used jd-gui for reading the file. As you know, the files in .jar were all .class files which are binary files and cannot readable, so I tried to convert .jar to java files using
'Save all sources'
in jd-gui, and it gives me the java files which are readable and editable, which are good for me. Then I edited java files and make them into .jar file using
'jar cf newjar.jar javafiles'
However the problem is,
jar2dex command with the new .jar file, the edited one always failed, and the reason is 'no classfiles specified'.
I think it's because I made it from .java files not .class files. So what should I do? Do I have to make all java files into .class files with javac command? Or any idea?
The java source code obtained from dex2jar and jd-gui is for reference only, it is incomplete and/or incorrect all the time. Besides, if it were completely reliable, there'd be no real need for Open Source.
As @Robert Williams said, you should look into smali if you're serious about apk modifications. If you do, here's some links to get you started