Installation Page

Steps working for: Ubuntu 14.04 64-bit

Installation Steps

Helpful installations:

$ sudo apt-get install flex
$ sudo apt-get install lib32z1
$ sudo apt-get install libsdl1.2debian:i386
$ sudo apt-get install libgl1-mesa-glx:i386
$ sudo apt-get install bison g++-multilib git gperf libxml2-utils (Ubuntu 14.04)

Install Repository:

$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ sudo apt-get install curl
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

Downgrade make from 4.0 to 3.81:
Donwload make from a mirror in http://packages.ubuntu.com/trusty/i386/make/download

$ sudo dpkg -i make_3.81-8.2ubuntu3_i386.deb

Install Synaptic Package Manager
Force Version of make to 3.81
Check version:

$ make -version

Note: On Ubuntu 15.04, after the dpkg command make changes its version to 3.81, verify with make -version


Install Java JDK 6:
Download JDK from http://ghaffarian.net/downloads/Java/JDK/

$ chmod a+x jdk-6u45-linux-x64.bin
$ ./jdk-6u45-linux-x64.bin
$ sudo mkdir /usr/lib/jvm
$ sudo mv jdk1.6.0_45 /usr/lib/jvm
$ sudo update-alternatives --config java

Choose any version and check the number of alternatives <nAlternatives>

$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_45/bin/java <nAlternatives>
$ sudo update-alternatives --config java

Choose alternative <nAlternatives>
Check version:

$ java -version

Solutions to JDK6 Problems in Ubuntu 15.04 64-bit:

1) “Picked up JAVA_TOOL_OPTIONS: - javaagent:/usr/share/java/jayatanaag.jar”
Add the following line to your ~/.bashrc file:

$ unset JAVA_TOOL_OPTIONS

2) Non setup of javac, jar, and other tools' versions:

$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_45/bin/javac
$ sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.6.0_45/bin/javah
$ sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.6.0_45/bin/javap
$ sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.6.0_45/bin/javadoc
$ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.6.0_45/bin/jar

Configure ssh keys:
Download ssh.zip

$ unzip ssh.zip
$ cd ssh
$ cp .ssh ~/.ssh

Download, Compile and Run AOSP (ASM's used version):

$ git config --global user.email "aaa@bbb.com"
$ git config --global user.name "AAA BBB"
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.4_r1.2
$ repo sync

(time for a coffee break)

$ source build/envsetup.sh
$ lunch 1
$ make -j8

(time to take a nap)

$ emulator

Checkout ASM source code:

$ git clone -b asm_project_release_r1 gitolite3@git.androidsecuritymodules.org:asm/manifests
$ mkdir .repo/local_manifests
$ cp manifests/local_manifest.xml .repo/local_manifests/
$ repo sync

Build ASM kernel (for x86 emulator):

$ source build/envsetup.sh
$ lunch 2
$ cd kernel/goldfish
$ ARCH=x86 make -j8 goldfish_defconfig
$ ARCH=x86 make -j8
$ cd ../..

Build ASM (for x86 emulator):

$ . build/envsetup.sh
$ lunch aosp_x86-eng
$ make -j8

Install Android Studio (not a good way to do it, install through http://developer.android.com/sdk/index.html):

$ apt-add-repository ppa:paolorotolo/android-studio
$ sudo apt-get update
$ sudo apt-get install android-studio
$ export ANDROID_HOME=~/Android/
$ PATH=~${PATH}:~/Android/Sdk/platform-tools/
$ PATH=~${PATH}:~/Android/Sdk/tools/

Install API 19 through SDK Manager


Run ASM (on emulator):
Create an sdcard image (found error “command not found” when running mksdcard, so went to sdk/tools/ created the image and moved it to the project directory, but this was done before exporting Android to PATH):

$ mksdcard 512M sdcard.img
$ emulator-x86 -kernel kernel/goldfish/arch/x86/boot/bzImage -sdcard sdcard.img -wipe-data -gpu off -qemu -show-kernel -enable-kvm -usbdevice keyboard

Send APK file to emulator (à pata):

$ mv ASM.apk ~/Android/Sdk/platform-tools/
$ adb install [path]ASM.apk

Run the “Hello World” ASM app on emulator (automatically):

$ cp out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/classes.jar ~/Android/Sdk/platforms/android-19/android.jar

Download demoasm.zip
Unzip demoasm.zip
Open Android Studio
Open an existing Android Studio Project
Tools → Android → Sync Project with Gradle files

$ emulator-x86 -kernel kernel/goldfish/arch/x86/boot/bzImage -sdcard sdcard.img -wipe-data -gpu off -qemu -show-kernel -enable-kvm -usbdevice keyboard

Run
Check the app's hooks' work with logcat on Android Studio


Install TortoiseHG and access TrUbi

$ sudo add-apt-repository ppa:tortoisehg-ppa/releases
$ sudo apt-get update
$ sudo apt-get install tortoisehg

File → New Repository
Destination path: hg clone https://etraudonun@bitbucket.org/kostah50/trubitest
Repository Registry → default → trubitest → Synchronize → Manage HTTPS connection security and user authentication (padlock) → Fill username and password


Getting the original kernel versions used in ASM

$ git clone https://android.googlesource.com/kernel/goldfish.git
$ cd goldfish
$ git checkout android-goldfish-3.4 
$ git clone https://android.googlesource.com/kernel/msm.git
$ cd msm
$ git checkout android-msm-mako-3.4-kitkat-mr0

NDK Installation & Configuration

Android Studio Configuration to Open AOSP


http://source.android.com/source/initializing
https://source.android.com/source/building-running.html#emulate-an-android-device
http://www.androidsecuritymodules.org/pages/sourcecode.html
https://plus.google.com/+UdiCohen/posts/Urt2uFHgm7V
https://shuhaowu.com/blog/setting_up_intellij_with_aosp_development.html
http://www.phonesdevelopers.com/1805032/

https://source.android.com/source/building-kernels.html#id-version
https://android.googlesource.com/?format=HTML