How to compile ss for android on Ubuntu 18.04.2 LTS.
一、Introduction
In this article, I assume you have learned both How to create a regular app and How to install Ubuntu system(Arbitrary version but it’s better to know about 18.04.2 LTS as this post base on it).
二、Prerequisites.
1、 Android Studio runs on Ubuntu system with at least 30GB spaces of hard disks.
2、JDK 1.8+.
3、Git.
As I metioned above, To install ubuntu is a necessary skill So that I won’t show you how to install here. Because there are many articles will point out a wrong way to you to set jdk 1.8 into system environment(This is very important as an incorrect setting will lead errors when you compile the shadowsocks project on Android Studio), But don’t worry I will walk you through how to correctly set environment for JDK. Additionally, Git is easily to be installed on Ubuntu so that I won’t teach you here too, if you have any problem with it, Just leave a comment. and you don’t need to learn NDK but just download it automatically by Android Studio.
三、Install JDK 1.8+ and Set environment for it. (Ignore this step if you alread know )
1、Open the following website and do as the pic shows, I will illustrate you.
Click here to download JDK 1.8+
2、After downloaded it, Open the terminal on the folder where the jdk-8u201-linux-x64.tar.gz contained.
3、Switch your role to root.(if you don’t know how to switch to root role, google or baidu it).
4、Create a folder for jdk. typing the following code on terminal to make a folder.(Make sure now you’re root role)
mkdir /usr/local/java
5、Extract jdk-8u201-linux-x64.tar.gz to /usr/local/java . Just code as the following commands.
tar -zxvf jdk-8u201-linux-x64.tar.gz -C /user/coal/java
6、For now, You have installed JDK1.8+ into your system. but you have to set environment for it to make sure you can run jdk everywhere you need.
7、Open the /etc/environment file by following code(vi can do same thing but it’s a bit difficult to learners on Linux):
gedit /etc/environment
1、JAVA_HOME.
2、CLASSPATH.
3、PATH.
The following code is mine. You should change it according to your jdk version and jdk folder name.
JAVA_HOME=/usr/local/java/jdk1.8.0_201
CLASSPATH=.:${JAVA_HOME}/lib
PATH="/usr/local/java/jdk1.8.0_201/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
I have makred parts you have to change in the pic. Please, write these code carefully. If you don’t, You won’t compile this project successfully.
8、Save and then close it. and then, update it by following code:
source /etc/environment
9、Now, you have set JDK environment. To verify your setting whether it’s correct. Do two steps:
First Step.
1、echo $JAVA_HOME
2、echo $CLASSPATH
3、echo $PATH
Make sure these constants will print right things on your Terminal, Just like my pic shows:
Second Step.
1、Relogin your root account.
2、Check your JDK environment whether it’s right on.
Just code:
java -version
If your terminal prints as my pic shows. Congratulations! You’re now successfully setting JDK Environment on your ubuntu system.
四、Pull shadowsocks from github and compile it.
The newest version of shadowsocks is easier compiled than ever. You just need to import it from github into Android Studio as a regular android project.
When it’s sync failed and shows the error message as the pic. Just click the Install NDK Text(blue color) below.
Now, It’s doing the last step to install NDK tool.
After that, You can run it on your handsets.
Finally, if you have any problem with it, just leave a comment. Thank you for your reading.