Skip to content

Instantly share code, notes, and snippets.

@wreszelewski
Last active March 4, 2022 08:29
Show Gist options
  • Save wreszelewski/6b47cd5ae5c000b9f2e6 to your computer and use it in GitHub Desktop.
Save wreszelewski/6b47cd5ae5c000b9f2e6 to your computer and use it in GitHub Desktop.
Compiling dalvikvm for Ubuntu 14.04, creating EC2 image, running hello world
#Some references:
# by Huber Flores:
# https://gist.github.com/huberflores/4687766
# https://gist.github.com/huberflores/9886339
# https://gist.github.com/huberflores/4714824
# by Hai on StackOverflow:
# http://stackoverflow.com/questions/14951374/didnt-find-class-foo-on-path-dexpathlist
# AOSP tutorial: https://source.android.com/source/index.html
#Create t2.medium instance with 100GB storage
#Initialize build environment
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java6-installer
sudo update-java-alternatives -s java-6-oracle
sudo apt-get install bison g++-multilib git gperf libxml2-utils
sudo apt-get install git
sudo apt-get install flex
sudo apt-get install zip
sudo apt-get install lib32z1
echo "export USE_CCACHE=1" >> ~/.bashrc
echo "PATH=~/bin:$PATH" >> ~/.bashrc
#Reload bash in order to apply changes you've made
mkdir ~/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
mkdir android
cd android
#Download source
repo init -u https://android.googlesource.com/platform/manifest -b android-4.4.4_r2
#Command below is time consuming, using screen is recommended.
#Due to server overload or exceeding quota this command may fail.
#You should run it again and again to complete it without error message.
repo sync
#Building. It may be time consuming, using screen is not necessary but may be helpful.
prebuilts/misc/linux-x86/ccache/ccache -M 50G
. build/envsetup.sh
lunch 2 #aosp-x86_eng (or sth similar)
make -j4 dalvikvm core dexopt ext framework android.policy services libjavacore
#After that you should have exec ~/android/out/host/linux-x86/bin/dalvikvm
#Some references:
# by Huber Flores:
# https://gist.github.com/huberflores/4687766
# https://gist.github.com/huberflores/9886339
# https://gist.github.com/huberflores/4714824
# by Hai on StackOverflow:
# http://stackoverflow.com/questions/14951374/didnt-find-class-foo-on-path-dexpathlist
# AOSP tutorial: https://source.android.com/source/index.html
# by kohviuba on Github: https://github.com/kohviuba/scalingAndroidImages/blob/master/rund.sh
#Compile dalvikvm
#Create t1.micro with 8GB free space
#On bigger machine:
scp -r ~/android/out [email protected]:
#On micro machine:
sudo mkdir /opt/android
sudo mv ~/out /opt/android/
#Create file /bin/rund with contents:
#!/bin/sh
# base directory, at top of source tree; replace with absolute path
base=/opt/android
# configure root dir of interesting stuff
root=$base/out/host/linux-x86
export ANDROID_ROOT=$root
# configure bootclasspath
bootpath=$base/out/target/product/generic_x86/system/framework
export BOOTCLASSPATH=$bootpath/core.jar:$bootpath/ext.jar:$bootpath/framework.jar:$bootpath/android.policy.jar:$bootpath/services.jar
export LD_LIBRARY_PATH=$bootpath/lib:$LD_LIBRARY_PATH
# this is where we create the dalvik-cache directory; make sure it exists
export ANDROID_DATA=/tmp/dalvik_$USER
mkdir -p $ANDROID_DATA/dalvik-cache
exec dalvikvm -Xdexopt:none $@
sudo ln -s /opt/android/out/host/linux-x86/bin/dx /bin/dx
sudo ln -s /opt/android/out/host/linux-x86/bin/dalvikvm /bin/dalvikvm
#Install dependencies:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java6-installer
sudo update-java-alternatives -s java-6-oracle
sudo apt-get install lib32z1
sudo apt-get install bison g++-multilib git gperf libxml2-utils
#Here you can create AMI with Amazon console.
#Now you can test your installation, create Foo.java:
public class Foo{
public static void main (String[] args){
System.out.println(System.currentTimeMillis() + "");
System.out.println("Here we do smt");
System.out.println(System.currentTimeMillis() + "");
}
}
#Compile it:
javac Foo.java
#Create dex:
dx --dex --output=foo.jar Foo.class
#And run:
rund -cp foo.jar Foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment