[HOW-TO] Dev basic´s: Source, Compiling, Github & co ~ Day 4

Search This thread
F

fuss132

Guest
Welcome to fuss132 dev basic´s

So you want to become a developer for android? You dont know where to start? Well, I will try to give you some point you can start with.
"There are many tutorials on compiling source code?", you may ask "So no need of this?". No, youre not right. Of course there are many how tos that explain you how to compile something... but to do the magic there is more needed than just "Execude this commands and ready". You need to know the things behind, you need to get the flair of android.



What I want:

First of all, I know that there are many people that see how devs are failing; or some that need help and those people cant help them. They have the time to learn something, but they dont know how. You can expect a point to start with, some welcome drink of android development. Expect the falir of android! Join the android open source project! I posted this in the I9100G section, because I use my kernel (called horsepower) as an example, but it can be used for every device! And please if I helped you thank me in whatever post I helped you :) I´m doing this in my spare free time to help you!




What I dont want:

I cant give you everything! You will need some time, it took me one and a half years to get to know a big part of how android works and stuff. You will not be a "full" developer after this! Furthermore, I dont teach you for 10 variants of my kernel coming up at the forum or of cm roms what ever! Android is an opensource project. This means creating something new - but together. If you did something you think its worth to publish make a git push request and your work will be included to my kernel f.e. Every dev that notice your work will let you post in his thread and your work will be thanked!



Also required for this howto:

  • A computer running ubuntu 12
  • Some basic ubuntu terminal knowledge
  • Time and more time

Also a good internet connection could be usefull



How it will work:
So you think you can manage this? Good luck, I will help you whereever I can. But please understand, that my work on kernels and roms will come first ;) I will try to post every day a new tutorial. We will start with setting up your computer and will end up in some weeks with compiling your own aosp rom. Ready? So lets go to the second post here and start with Day 1: Introduction



PS: Well we only have one forum so, besides this fact that this is about learning developing, I posted it here...
 
Last edited:
F

fuss132

Guest
Day one: Introduction and downloading source code

This is all for jellybean!
So no longer talking about developement, let´s do some of itselfe.
We first need the source code. For completeness we will download both - kernel source and main rom source. If you dont know what kernel is for please stop reading here... you will fail 99,9999%. (Maybe you just forgot which files this is for: Kernel is the boot.img in your update.zip´s and the rest located in /system is the compiled main rom.)



1. Creating your working directory and stuff

You should know the commands, just use the same folder names and structure for a better chance that I can help you if something goes wrong.

cd
mkdir cyanogenmod
cd cyanogenmod



2. Downloading the source and required software

At this part we use a very useful build script made by teamhacksung, thanks to them!
Staying at your /cyanogenmod folder do the following (What this git command mean ~ well dont think about it we will learn it afterwards):

git clone git://github.com/teamhacksung/buildscripts.git -b cm-10.1 buildscripts
ln -s buildscripts/samsung/build.sh
./build.sh prepare

This script will now do some very useful things for you :D Select the specifics of your system and wait for finishing till the point "Download sources?" Tipe a "y" and select "cm-10.1". (When it asks for your folder you want the source in only tipe "sources" and hit enter). This will download the main uncompiled canogenmod sources for you (including some kernel and device specific stuff). It will take looong :D Depeding on your net connection. Some hours usually



3. Downlading kernel sources and recovery stuff

Everything went well? So this means we need to go further. In /cyanogenmod/sources should now be some folders and files... And now we should download a kernel source for our device (choose one for your device, I will use I9100G ones).
Navigate to your source and execute

cd
cd cyanogenmod
cd sources
mkdir kernel/samsung/
cd kernel/samsung/
git clone https://github.com/fuss132/android_kernel_samsung_t1.git -b greenblob-4.2.2 t1

Hah, you now have latest greenblobkernel source on your computer.
But to finally build the kernel and rom we will also need some device specific files for our I9100G. For other devices you will find these files when you search on gitbub. Or google device xy ics device tree.

cd
cd cyanogenmod
cd sources
git clone git://github.com/CyanogenMod/android_device_samsung_i9100g.git -b cm-10.1 device/samsung/i9100g

As it finished you have all the sources you need

Thats enough for day one, I think. See you soon :)
 
Last edited:
F

fuss132

Guest
Day 2: Github basics part 1

So we successfully downloaded all sources. Brilliant, now let´s go on. In future time you may work on kernels of even the main rom, and of course you should upload the changes you made to contribute to the community. You will need github for this. For some basic info go here I will only focus on how to use it.


The script from above post should already installed git, if not do the following:

sudo apt-get install git

And you should also register an account for free at github.com -> here

As you did this we will also need to set up your github account on your computer, so use the following commands and replace it with the email adress and username you chose before:

First we should be in our kernel example local repository so use cd /cyanogenmod/sources/kernel/samsung/t1 to switch to it
git config --global user.name "Your Name Here"
git config --global user.email "your_email@youremail.com"

If you now upload some changes you have to enter your password every time. To make the things easier we will use an ssh key and will add it to our github account. Its not important to know what all these commands are doing just do them :D

ssh-keygen -t rsa -C "your_email@youremail.com"
//Now you need to enter a passphrase.
sudo apt-get install xclip
xclip -sel clip < ~/.ssh/id_rsa.pub <- this is the path to your stored key

Now go to https://github.com/settings/ssh, login and click "add ssh key". Choose a name (doesnt matter which one) and paste your key from your clipboard into the field below. Thats it github is now set up



1. Some basics commmands

There are some basic commands you should know. Firstly, some explanations for you. The source you downloaded is stored on www.github.com.
With git clone git@github.com/pathtsource you can download new files and sources from existing repositorys.

When you change some files in your local repository (all files from one source path f.e. cd /cyanogenmod/sources/kernel/samsung/t1 and then execute and then) use git status to display the changes you made.

You made some changes? Then pack these changes into a commit by typing git add -A and also add a commit message that will appear later like git commit -m "Camera freeze fix" and finally upload it: git push. We will make some practical examples tomorrow, so dont worry about this now. Just keep that in mind.


Thanks for reading and see you tomorrow! :)
As usuall, if you like this thread and stuff please submit it as news tip! ;)
 
Last edited:
F

fuss132

Guest
Day 3: Github basics part 2 and preparing for compiling

Welcome to Day 3: Github basics part 2 and preparing for compiling! Lets beginn our "session" with a short test. Remember which command you have to use for cloing a repository (downloading the files to your computer)? Well we need this one here.

1. Again Github basics

Imagine the following situation; You want to help another person to fix a bug. You should create your own repository first to dont mix files up. In short we copy all files from a repository to our own new one. We have a point to start then and will use his code, but his code wont change when we change ours.

Go to www.github.com/ and login

I create a short repository for you all, nothing special but you can practise with it.
Open the following page (its the repositiory shown in your webbrowser: https://github.com/fuss132/lerninggit_practical_repository. Click on fork at the right:

Github_fork.jpg


If github is asking you to which user it should fork the files click the only availabe button ^^


You have now your own repository with the same files. We will download the files now. Open your terminal and navigate to the folder (it should be an empty one). So you have to do the following:


Now we "fix the bug" and do some changes to your local files.

cd tutorialmembers
sudo gedit memberlist
// add your name to the list, save and exit //
cd ..

So we made the changes, now we will upload them, you should know the commands already. If you have any questions please post in this thread

git status
git add -A
git commit -m "add my name to the list"
git push

Brilliant, if you know visit https://github.com/yournamehere/lerninggit_practical_repository you will see that your changes have been uploaded. So you fixed my problem, you should now share the solution with me.

Open your repository in a webbrowser https://github.com/yournamehere/lerninggit_practical_repository and click on Pull Requests on the right side. Now select on the right side as head repo mine fuss132 one and as base repo in the left the default, your one. Describe what you did in the filed below and finally click on "Send pull request.

Thats it you now shared it with me and I will include your changes to my repo :)



2. Back to the roots: Prepare for compiling

Now cd to the folders you downloaded all the sources in. You should see folders like bionic, fendor, main... I will call this main source directory now
If you would compile the sources now you would stuck after some seconds :D Android needs a special java version for building. And this one cant be downloaded anymore. Well, bad situation... We will give up here we will never compile android :'(

Ok, **** you java we will rule you :D

There is an error only because the build system does not recognize the java version when it is an openSDK

$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.1) (6b24-1.11.1-4ubuntu2)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)


To work around it, you can just comment out the following lines in build/core/main.mk:

cd build/core/
gedit main.mk

instead of
ifneq ($(shell java -version 2>&1 | grep -i openjdk),)
java_version :=
endif

there should be

# ifneq ($(shell java -version 2>&1 | grep -i openjdk),)
# java_version :=
# endif

Java is now no longer checking its version and everything is working. Stupid solution, but working :p


The second part is that the linker would complain that it cannot find -lGL .

The workaround for it would be:

just execute this line:

sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so


The last thing what we need is again the buildscript file, just do the following (you dont have to remember this):

// be in the main directory of your sources //
gedit build.sh
copy all lines from https://github.com/teamhacksung/buildscripts/blob/ics/samsung/build.sh and paste them into your file
save and close
in terminal: chmod 777 build.sh


Thats it for today, thanks for reading! Please press thanks if you like it and maybe click on "newsworthy thread". Questions, as usuall in this thread please :)
 
Last edited:
F

fuss132

Guest
Day 4: Compiling your first things and looking into the source code

It´s been a long time since we met the last time, I hope you didnt forgot everything. If you did - you know - just go to through the first posts and learn again. Sorry that it took so long for you to wait, but I´m writing this in my spare free time and I´m involved into many many projects at this time that are more important that this one. But I didnt forget you! :) So lets go in again and start coding!

1. Going through the source code

I know, I turned things around in the title of this thread, but compiling will take a very long time so lets go through the source code first.
Open a file explorer and navigate to your root forlders. You will see there many folders. As you all know, Cyanogenmod is a Custom Rom and adds much features to your devices, thats why they are using custom product configs. One for each phone and one for all phones.

Let´s go into the folder vendor/cm. You will see a file called "vendorsetup.sh" in which all available devices are written in.


Ok, you will wonder why theres only something like this in your folder if you downloaded the sourcecode for Cyanogenmod 10:

for combo in $(cat vendor/cm/jenkins-build-targets)
do
add_lunch_combo $combo
done

Because since cm10 they´re doing things a bit different. In the next few days we will download the aokp source code and start porting aokp to a new device, because aokp is using the old building system like in cm9 and previous version - and I want that you know all of them. So back to our cm10 thing: All product specific files are now directly in the source code of the device, the device tree. Its the one we downloaded and stored in /device/samsung/i9100g.

But to build a fully working Cyanogenmod Rom we need more that only te device tree, we need some proprietary files from your device. In short, they are files that are very device specific like camera.t1.so (a camera module only for our device) that is pre generated and could not be build by our system. (Thats also the reason why developers cant edit it. We are not able to edit it, too). To pull all those files from your device, please connect it and be sure that you are already running a cyanogenmod 10 rom, otherwise some files might be different and not be copyed - your rom will not be successfully build.

Open our terminal and execute:

Code:
sudo bash
cd cyanogenmod/sources/device/samsung/i9100g
chmod 777 proprietary-files.sh
./proprietary-files.sh

Using adb all the files are now being pulled from your device and stored in the right directory of your system. If you successfully did this (and I didnt forget something) we should be now able to compile our own cyanogenmod rom.

2. Compiling your rom

So let´s go! (We will update the sourcecode before again, maybe some cool things changed). We will not use the build script for this, we´re doing things "oldschool". If you want to make things as easy as possible do ./build.sh i9100g and everything will be done for you.

sudo bash
cd cyanogenmod/sources
repo sync

/* start building*/
. build/envsetup.sh
lunch

/* pick the device you are building for */
make bacon or make fullota or make -jx (where x is the number of your cpu cores)

And now we have to wait some hours depending on your computer. I´ll catch you guys in the next tutorial!

Please press thanks and submit this thread as newsworthy one! Thank you and have a good time :)
 
Last edited:
F

fuss132

Guest
Oh no, it was just one... hmm thats why I want to became a computer scientist not a mathematician ^^
 

Kingspp

Senior Member
Apr 10, 2012
704
275
Mysore
This happens when fuss is in playful mood...lol.. hoping to see more of it..... I have already built a rom...its a modified stock rom...but I am failing to compile and decompile systemui Apk...using apktool..I tried installing framework-res apk...but eventually found out that apktool won't work for ics...so any help from your side is appreciated... :)

Sent from my GT-I9100G using xda premium
 

superatmos

Retired Recognized Developer
Mar 29, 2011
493
1,202
Bangalore
This happens when fuss is in playful mood...lol.. hoping to see more of it..... I have already built a rom...its a modified stock rom...but I am failing to compile and decompile systemui Apk...using apktool..I tried installing framework-res apk...but eventually found out that apktool won't work for ics...so any help from your side is appreciated... :)

Sent from my GT-I9100G using xda premium

Use apk-manager or the latest smali and baksmali binaries.
 
  • Like
Reactions: Kingspp

alexsc13

Senior Member
Jul 13, 2012
66
22
Awesome guide you are doing here! Cannot wait to see how it continues today. Big thumbs up for this mate!
 

Top Liked Posts

  • There are no posts matching your filters.
  • 3
    This is so not the purpose of this thread...you have been asking questions again and again without even bothering to study how build.sh works...I can't possibily spoon feed you...look at all the previous posts...It is more like I'm compiling instead of you? I'm like "remote controlling" you...please...XDA is not a place for "no brainer guides"....at least try understanding k? I will leave that last question to you...calm down, I know you are desperate to be a "kernel developer" again as you did for the S Plus...the transition takes time...build.sh is written in very simple shell language...try looking at it and understand the flow...or refer the ICS branch of Blazing kernel to understand the structure of the kernel directories...I changed it in JB for many reasons...try discovering that as well...;)...good luck...cheers...

    *p.s. It took me months to actually compile my first kernel...but at least I understand how things work...I believe you can do better than me...
    1
    newsworthy thread

    @fuss

    Submitted as newsworthy thread :). Guys pls do the same if its useful to u guys :cowboy:. First to comment n ur thread :D
    1
    Good one Fuss :) Should be recommended to make this sticky once you complete the tutorial. :)
    1
    This happens when fuss is in playful mood...lol.. hoping to see more of it..... I have already built a rom...its a modified stock rom...but I am failing to compile and decompile systemui Apk...using apktool..I tried installing framework-res apk...but eventually found out that apktool won't work for ics...so any help from your side is appreciated... :)

    Sent from my GT-I9100G using xda premium

    Use apk-manager or the latest smali and baksmali binaries.
    1
    after compiling kernel i have the boot.img in /home/thegame97/Source/out/target/product/i9100g

    do you think is correct ?

    I think yes :p