ROM Android: Compile bagian tertentu dari source Android

From OnnoWiki
Revision as of 08:30, 10 November 2014 by Onnowpurbo (talk | contribs) (New page: How to Download/Compile Specific Parts of a ROM This is a tutorial about how to download and compile specific parts in AOSP based roms (such as CyanogenMod, AOKP, SlimRom etc) It’s main...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

How to Download/Compile Specific Parts of a ROM

This is a tutorial about how to download and compile specific parts in AOSP based roms (such as CyanogenMod, AOKP, SlimRom etc) It’s mainly dedicated for the people who want to get more familiar with the AOSP build environment, and would like to manipulate it’s behavior to complete specific tasks.

Introduction: Downloading ROM sources is done with the tool “repo”, this is the most awesome downloader in existence. Not only it looks very cool, it also reaches top speed at all times. But it’s only for linux (which is good, since when you are busy with aosp roms, you should be on linux!) Why is it awesome? Since you decide yourself how many jobs (aka connections) you make with the server. This means you always will get top speed, there is probably no faster download method available on the Internet (except for speedtests, but they don’t count). Next to the downloading of specific parts it’s of course also handy to know how to actually compile them.


Chapters: 1. Download 2. Compile 3. Automate (optional)


Chapter 1. Download: The easiest way of fetching for example a batch of AOSP apps is like this:

1. Choose the desired tag you want to use, in the example I will use android-4.2.2_r1 2. Now make a dir somewhere: mkdir ~/aosp-apps cd ~/aosp-apps 1 2

mkdir ~/aosp-apps cd ~/aosp-apps

3. Download repo when not installed yet: curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo chmod a+x ~/bin/repo 1 2

curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo chmod a+x ~/bin/repo

4. Enter the line that will download the initial manifest.

for AOSP: repo init -u https://android.googlesource.com/platform/manifest -b android-4.2.2_r1 1

repo init -u https://android.googlesource.com/platform/manifest -b android-4.2.2_r1

Enter your name and email address and wait until it completes

for CM: repo init -u https://github.com/Cyanogenmod/android -b cm-10.1 1

repo init -u https://github.com/Cyanogenmod/android -b cm-10.1

5. Go in the hidden “.repo” dir and change the manifest cd .repo gedit manifest.xml 1 2

cd .repo gedit manifest.xml

If you don’t have decent text editor such as “gedit”, install it! “sudo apt-get install gedit”


For example when you only want to download the apps, just remove all lines that are not app related. simple as that <?xml version=”1.0″ encoding=”UTF-8″?> <manifest> <remote name=”aosp” fetch=”..” /> <default revision=”refs/tags/android-4.2.2_r1″ remote=”aosp” sync-j=”4″ /> <project path=”packages/apps/BasicSmsReceiver” name=”platform/packages/apps/BasicSmsReceiver” /> <project path=”packages/apps/Bluetooth” name=”platform/packages/apps/Bluetooth” /> <project path=”packages/apps/Browser” name=”platform/packages/apps/Browser” /> <project path=”packages/apps/Calculator” name=”platform/packages/apps/Calculator” /> <project path=”packages/apps/Calendar” name=”platform/packages/apps/Calendar” /> <project path=”packages/apps/Camera” name=”platform/packages/apps/Camera” /> <project path=”packages/apps/CellBroadcastReceiver” name=”platform/packages/apps/CellBroadcastReceiver” /> <project path=”packages/apps/CertInstaller” name=”platform/packages/apps/CertInstaller” /> <project path=”packages/apps/Contacts” name=”platform/packages/apps/Contacts” /> <project path=”packages/apps/DeskClock” name=”platform/packages/apps/DeskClock” /> <project path=”packages/apps/Email” name=”platform/packages/apps/Email” /> <project path=”packages/apps/Exchange” name=”platform/packages/apps/Exchange” /> <project path=”packages/apps/Gallery” name=”platform/packages/apps/Gallery” /> <project path=”packages/apps/Gallery2″ name=”platform/packages/apps/Gallery2″ /> <project path=”packages/apps/HTMLViewer” name=”platform/packages/apps/HTMLViewer” /> <project path=”packages/apps/KeyChain” name=”platform/packages/apps/KeyChain” /> <project path=”packages/apps/Launcher2″ name=”platform/packages/apps/Launcher2″ /> <project path=”packages/apps/LegacyCamera” name=”platform/packages/apps/LegacyCamera” /> <project path=”packages/apps/Mms” name=”platform/packages/apps/Mms” /> <project path=”packages/apps/Music” name=”platform/packages/apps/Music” /> <project path=”packages/apps/MusicFX” name=”platform/packages/apps/MusicFX” /> <project path=”packages/apps/Nfc” name=”platform/packages/apps/Nfc” /> <project path=”packages/apps/PackageInstaller” name=”platform/packages/apps/PackageInstaller” /> <project path=”packages/apps/Phone” name=”platform/packages/apps/Phone” /> <project path=”packages/apps/Protips” name=”platform/packages/apps/Protips” /> <project path=”packages/apps/Provision” name=”platform/packages/apps/Provision” /> <project path=”packages/apps/QuickSearchBox” name=”platform/packages/apps/QuickSearchBox” /> <project path=”packages/apps/Settings” name=”platform/packages/apps/Settings” /> <project path=”packages/apps/SoundRecorder” name=”platform/packages/apps/SoundRecorder” /> <project path=”packages/apps/SpareParts” name=”platform/packages/apps/SpareParts” /> <project path=”packages/apps/SpeechRecorder” name=”platform/packages/apps/SpeechRecorder” /> <project path=”packages/apps/Stk” name=”platform/packages/apps/Stk” /> <project path=”packages/apps/Tag” name=”platform/packages/apps/Tag” /> <project path=”packages/apps/VideoEditor” name=”platform/packages/apps/VideoEditor” /> <project path=”packages/apps/VoiceDialer” name=”platform/packages/apps/VoiceDialer” /> </manifest> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

<?xml version=”1.0″ encoding=”UTF-8″?>

   <manifest>

   <remote  name=”aosp”
   fetch=”..” />
   <default revision=”refs/tags/android-4.2.2_r1″
   remote=”aosp”
   sync-j=”4″ />

   <project path=”packages/apps/BasicSmsReceiver” name=”platform/packages/apps/BasicSmsReceiver” />
   <project path=”packages/apps/Bluetooth” name=”platform/packages/apps/Bluetooth” />
   <project path=”packages/apps/Browser” name=”platform/packages/apps/Browser” />
   <project path=”packages/apps/Calculator” name=”platform/packages/apps/Calculator” />
   <project path=”packages/apps/Calendar” name=”platform/packages/apps/Calendar” />
   <project path=”packages/apps/Camera” name=”platform/packages/apps/Camera” />
   <project path=”packages/apps/CellBroadcastReceiver” name=”platform/packages/apps/CellBroadcastReceiver” />
   <project path=”packages/apps/CertInstaller” name=”platform/packages/apps/CertInstaller” />
   <project path=”packages/apps/Contacts” name=”platform/packages/apps/Contacts” />
   <project path=”packages/apps/DeskClock” name=”platform/packages/apps/DeskClock” />
   <project path=”packages/apps/Email” name=”platform/packages/apps/Email” />
   <project path=”packages/apps/Exchange” name=”platform/packages/apps/Exchange” />
   <project path=”packages/apps/Gallery” name=”platform/packages/apps/Gallery” />
   <project path=”packages/apps/Gallery2″ name=”platform/packages/apps/Gallery2″ />
   <project path=”packages/apps/HTMLViewer” name=”platform/packages/apps/HTMLViewer” />
   <project path=”packages/apps/KeyChain” name=”platform/packages/apps/KeyChain” />
   <project path=”packages/apps/Launcher2″ name=”platform/packages/apps/Launcher2″ />
   <project path=”packages/apps/LegacyCamera” name=”platform/packages/apps/LegacyCamera” />
   <project path=”packages/apps/Mms” name=”platform/packages/apps/Mms” />
   <project path=”packages/apps/Music” name=”platform/packages/apps/Music” />
   <project path=”packages/apps/MusicFX” name=”platform/packages/apps/MusicFX” />
   <project path=”packages/apps/Nfc” name=”platform/packages/apps/Nfc” />
   <project path=”packages/apps/PackageInstaller” name=”platform/packages/apps/PackageInstaller” />
   <project path=”packages/apps/Phone” name=”platform/packages/apps/Phone” />
   <project path=”packages/apps/Protips” name=”platform/packages/apps/Protips” />
   <project path=”packages/apps/Provision” name=”platform/packages/apps/Provision” />
   <project path=”packages/apps/QuickSearchBox” name=”platform/packages/apps/QuickSearchBox” />
   <project path=”packages/apps/Settings” name=”platform/packages/apps/Settings” />
   <project path=”packages/apps/SoundRecorder” name=”platform/packages/apps/SoundRecorder” />
   <project path=”packages/apps/SpareParts” name=”platform/packages/apps/SpareParts” />
   <project path=”packages/apps/SpeechRecorder” name=”platform/packages/apps/SpeechRecorder” />
   <project path=”packages/apps/Stk” name=”platform/packages/apps/Stk” />
   <project path=”packages/apps/Tag” name=”platform/packages/apps/Tag” />
   <project path=”packages/apps/VideoEditor” name=”platform/packages/apps/VideoEditor” />
   <project path=”packages/apps/VoiceDialer” name=”platform/packages/apps/VoiceDialer” />
   </manifest>

When done, save it and go a dir back in the terminal cd .. 1

cd ..

6. Download the packages repo sync -j16 (-j16 stands for 16 jobs max. This is for around a 100mbit line) 1

repo sync -j16 (-j16 stands for 16 jobs max. This is for around a 100mbit line)

(With a 60mb/s connection you already get the max download speed with ” -j4 ” which is the default of github)

The packages will be download as quickly as possible to your harddrive now.


Chapter 2. Compile: To compile the obtained packages separately you will need a AOSP environment (or CM/AOKP etc). When you have a succesfull environment which is able to compile for your device you may enter: source build/envsetup.sh lunch (now choose your device, for example, full_ariesve-userdebug) 1 2

source build/envsetup.sh lunch (now choose your device, for example, full_ariesve-userdebug)

now you’re theoretically ready to compile to compile an app on the easiest way: make Appname -j8 1

make Appname -j8

where “Appname” is the name of the folder placed in packages/apps/.. This also counts for “SystemUI” which is not in that folder make Calculator -j8 (for example) 1

make Calculator -j8 (for example)

And the -j param again stands for the number of jobs, remember that this is compiling and not downloading, so the “standard rule” with this is, number of cores of your CPU + 1. Which makes a regular quad core (-j5) but makes a i7 CPU with Hyper threading (-j9). When using -j16 for example on a regular quad core it could happen that your CPU will be overloaded so much that your mouse will lag all over the place. (Linux forces the cpu to perform higher then it actually should, resulting in unwanted situations)

When having trouble, when it stops or just nags about some missing symbols or something like that. You should try using the “-k” param, this tells the make command to keep going when a non-critical error occurs. make Calculator -k -j8 1

make Calculator -k -j8

When having issues with the local module tags, you should enter this: make Calculator -k LOCAL_MODULE_TAGS=optional -j8 1

make Calculator -k LOCAL_MODULE_TAGS=optional -j8

To compile other parts you also need to enter the folder name, here are some examples from /frameworks/base make android.policy (the power menu and lockscreen) make framework (the initial framework files) make framework-res (the initial framework resources) make services (the services.jar file) 1 2 3 4

make android.policy (the power menu and lockscreen) make framework (the initial framework files) make framework-res (the initial framework resources) make services (the services.jar file)

or more examples: make sdk (builds the android sdk) make modules (builds all modules) make installclean (removes all staging directories, such as out/target/product/boardname/system) make clean (removes the whole /out directory) make recoveryimage (builds the recovery from /bootable/recovery, customizable if wanted!) 1 2 3 4 5

make sdk (builds the android sdk) make modules (builds all modules) make installclean (removes all staging directories, such as out/target/product/boardname/system) make clean (removes the whole /out directory) make recoveryimage (builds the recovery from /bootable/recovery, customizable if wanted!)


Chapter 3. Automate

If you regularly want to compile specific ROM parts you can make a shell script that automates the process for you.

Make a new document with some name, for example “buildessentials”, open the file with your favorite text editor (gedit is recommended) and place this line at the very top of your document:

  1. !/bin/bash

1

  1. !/bin/bash

This indicates that this file should call /bin/bash, which is the shell interpreter.

Under this line you should place all the single commands that you want to be executed when running the script. For example: . build/envsetup.sh (inits the environement setup file, which is always needed) lunch full_ariesve-userdebug (chooses the wanted device, I chose for the i9001, which is called ariesve) make android.policy -j8 (builds android.policy.jar) make SystemUI -j8 (builds SystemUI.apk) make recoveryimage -j8 (builds recovery.img) 1 2 3 4 5

. build/envsetup.sh (inits the environement setup file, which is always needed) lunch full_ariesve-userdebug (chooses the wanted device, I chose for the i9001, which is called ariesve) make android.policy -j8 (builds android.policy.jar) make SystemUI -j8 (builds SystemUI.apk) make recoveryimage -j8 (builds recovery.img)

So your total output would be:

  1. !/bin/bash . build/envsetup.sh (inits the environement setup file, which is always needed) lunch full_ariesve-userdebug (chooses the wanted device, I chose for the i9001, which is called ariesve) make android.policy -j8 (builds android.policy.jar) make SystemUI -j8 (builds SystemUI.apk) make recoveryimage -j8 (builds recovery.img)

1 2 3 4 5 6

  1. !/bin/bash

. build/envsetup.sh (inits the environement setup file, which is always needed) lunch full_ariesve-userdebug (chooses the wanted device, I chose for the i9001, which is called ariesve) make android.policy -j8 (builds android.policy.jar) make SystemUI -j8 (builds SystemUI.apk) make recoveryimage -j8 (builds recovery.img)

Now you should change the permissions of the files, which need to be RWX-RX-RX, which is 755. This can be done by entering this in the shell: chmod 755 buildessential 1

chmod 755 buildessential

Now you can run the script by entering: ./buildessential 1

./buildessential

Thats it!


Referensi