Installing javac for Apktool on linux

The build steps of the latest Apktool is detailed below

http://code.google.com/p/android-apktool/wiki/BuildApktool?tm=4

 

It uses something called gradlew to build the latest version of the binary.

The instructions are as follows:

We use gradle to build. Its pretty easy. First clone the REPO.

git clone git://github.com/iBotPeaches/Apktool.git
Move into the directory.

cd Apktool
Issue the build.

./gradlew build
Then look in

/brut.apktool/apktool-cli/build/libs/apktool-xxxxx.jar
Other commands such as clean are

./gradlew clean

If you attempt that and dont have JDK installed, it will error out.

You need to download the latest version of the JDK available as a .tar.gz file at http://www.oracle.com/technetwork/java/javase/downloads/index.html

I used jdk-7u9-linux-i586.tar.gz

Once extracted, set the path as the path of the folder containing the bin folder (which contains javac). Note that the path should be the parent of the bin folder, and not include the bin folder itself.

export JAVA_HOME=/home/droidzone/android/java/jdk1.7.0_09

Here, jdk1.7.0_09/bin contains javac.

The final file will be produced in a location brut.apktool/apktool-cli/build/libs/ relative to the parent and named of the form apktool-cli-1.5.1-SNAPSHOT.jar

So

cp brut.apktool/apktool-cli/build/libs/*jar ./

should get you the latest file.

Note that you need the wrapper too.

wget http://android-apktool.googlecode.com/files/apktool-install-linux-r04-brut1.tar.bz2
tar -jxvvf apktool-install-linux-r04-brut1.tar.bz2

Finally since the apktool refers to a file named apktool.jar, create a symlink.

 

Possible errors:

Exception in thread "main" java.lang.UnsupportedClassVersionError: brut/apktool/Main : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
Could not find the main class: brut.apktool.Main. Program will exit.

That happens when your main system version java is older than version 7.

You can solve it either by:

1. Upgrading your main java version

2. Setting the PATH of your local java to override your system java.

Eg: If PATH is :/usr/bin:~/bin, make it ~/bin:/usr/bin

3. Creating a symlink in /usr/bin, point it to your version

cd /usr/bin

su

mv java java.old

ln -s /home/droidzone/android/java/jdk1.7.0_09/bin/java java