5,600,664 Members 35,330 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
fuss132
Old
(Last edited by fuss132; 28th August 2012 at 10:47 AM.)
#1  
fuss132's Avatar
Recognized Developer - OP
Thanks Meter 5005
Posts: 1,469
Join Date: Dec 2010
Location: Augsburg

 
DONATE TO ME
Default [HOW-TO] Dev basicīs: Source, Compiling, Github & co ~ Day 4

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...
The Following 62 Users Say Thank You to fuss132 For This Useful Post: [ Click to Expand ]
 
fuss132
Old
(Last edited by fuss132; 17th March 2013 at 02:13 PM.)
#2  
fuss132's Avatar
Recognized Developer - OP
Thanks Meter 5005
Posts: 1,469
Join Date: Dec 2010
Location: Augsburg

 
DONATE TO ME
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.

Quote:
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):

Quote:
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 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 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

Quote:
cd
cd cyanogenmod
cd sources
mkdir kernel/samsung/
cd kernel/samsung/
git clone https://github.com/fuss132/android_k...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.

Quote:
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
The Following 24 Users Say Thank You to fuss132 For This Useful Post: [ Click to Expand ]
 
fuss132
Old
(Last edited by fuss132; 18th July 2012 at 03:01 PM.)
#3  
fuss132's Avatar
Recognized Developer - OP
Thanks Meter 5005
Posts: 1,469
Join Date: Dec 2010
Location: Augsburg

 
DONATE TO ME
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:

Quote:
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:

Quote:
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

Quote:
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!
The Following 18 Users Say Thank You to fuss132 For This Useful Post: [ Click to Expand ]
 
fuss132
Old
(Last edited by fuss132; 19th July 2012 at 07:01 PM.)
#4  
fuss132's Avatar
Recognized Developer - OP
Thanks Meter 5005
Posts: 1,469
Join Date: Dec 2010
Location: Augsburg

 
DONATE TO ME
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/lerninggi...cal_repository. Click on fork at the right:



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:

Quote:
cd whereeveryyouwantit
git clone git@github.com:<b>yourusernamehere</...repository.git
Now we "fix the bug" and do some changes to your local files.

Quote:
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

Quote:
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 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

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:

Quote:
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


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

The workaround for it would be:

just execute this line:

Quote:
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):

Quote:
// be in the main directory of your sources //
gedit build.sh
copy all lines from https://github.com/teamhacksung/buil...msung/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
The Following 16 Users Say Thank You to fuss132 For This Useful Post: [ Click to Expand ]
 
fuss132
Old
(Last edited by fuss132; 28th August 2012 at 10:46 AM.)
#5  
fuss132's Avatar
Recognized Developer - OP
Thanks Meter 5005
Posts: 1,469
Join Date: Dec 2010
Location: Augsburg

 
DONATE TO ME
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:

Quote:
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.

Quote:
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
The Following 18 Users Say Thank You to fuss132 For This Useful Post: [ Click to Expand ]
 
fuss132
Old
#6  
fuss132's Avatar
Recognized Developer - OP
Thanks Meter 5005
Posts: 1,469
Join Date: Dec 2010
Location: Augsburg

 
DONATE TO ME
First page of the thread!
The Following 6 Users Say Thank You to fuss132 For This Useful Post: [ Click to Expand ]
 
fuss132
Old
#7  
fuss132's Avatar
Recognized Developer - OP
Thanks Meter 5005
Posts: 1,469
Join Date: Dec 2010
Location: Augsburg

 
DONATE TO ME
This post also...
The Following 6 Users Say Thank You to fuss132 For This Useful Post: [ Click to Expand ]
 
fuss132
Old
#8  
fuss132's Avatar
Recognized Developer - OP
Thanks Meter 5005
Posts: 1,469
Join Date: Dec 2010
Location: Augsburg

 
DONATE TO ME
3 left if my math education not failed
The Following 6 Users Say Thank You to fuss132 For This Useful Post: [ Click to Expand ]
 
fuss132
Old
#9  
fuss132's Avatar
Recognized Developer - OP
Thanks Meter 5005
Posts: 1,469
Join Date: Dec 2010
Location: Augsburg

 
DONATE TO ME
Oh no, it was just one... hmm thats why I want to became a computer scientist not a mathematician ^^
The Following 5 Users Say Thank You to fuss132 For This Useful Post: [ Click to Expand ]
 
rcade2005
Old
#10  
rcade2005's Avatar
Senior Member
Thanks Meter 228
Posts: 498
Join Date: Apr 2012
Location: Chennai
Angry newsworthy thread

@fuss

Submitted as newsworthy thread . Guys pls do the same if its useful to u guys . First to comment n ur thread

The Following 2 Users Say Thank You to rcade2005 For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes