As an android cainiao, after more than a week of experimentation, we finally succeeded in compiling the android source code and SDK in Linux and developing applications in eclipse.
Although this result is very simple, but the process of small and medium problems and small errors constantly, any error can make the entire work unable to proceed, making people crazy. Therefore, I would like to summarize some experiences and experiences in this process.
A. Download the android source code
Google can find many articles about downloading the android source code. Here I will refer to a complete article I think:
1. install some environments
Sudo apt-Get install build-essential
Sudo apt-Get install make
Sudo apt-Get install gcc
Sudo apt-Get install g ++
Sudo apt-Get install libc6-dev
Sudo apt-Get Install patch
Sudo apt-Get install texinfo
Sudo apt-Get install libncurses-Dev
Sudo apt-Get install Git-core GnuPG
Sudo apt-Get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl
Sudo apt-Get install ncurses-Dev
Sudo apt-Get install zlib1g-dev
Sudo apt-Get install valgrind
Sudo apt-Get install python2.5
Install the Java environment
Sudo apt-Get install sun-java6-jre sun-java6-plugin sun-java6-fonts sun-java6-jdk
Note:
The official document says that if you can use sun-java6-jdk problems, you have to use sun-java5-jdk. Tests show that if only make (make does not include make
SDK), with the sun-java6-jdk is no problem. The Make SDK has problems. Strictly speaking
If a problem occurs with the doc, The javadoc version required is 1.5.
Therefore, we 'd better install the sun-java6-jdk after installing the sun-java5-jdk, or
Install sun-java5-jdk only. Here, both sun-java6-jdkand sun-java5-jdkare installed, and only javadoc.1.gz and
Javadoc. Because only these two are used by the make SDK. In this case, except that the javadoc tool uses version 1.5, all other tools use version 1.6:
Sudo apt-Get install sun-java5-jdk
Modify the link of javadoc
CD/etc/alternatives
Sudo RM javadoc.1.gz
Sudo ln-S/usr/lib/JVM/Java-1.5.0-sun/man/Man1/javadoc.1.gz javadoc.1.gz
Sudo RM javadoc
Sudo ln-S/usr/lib/JVM/Java-1.5.0-sun/bin/javadoc
2. Set Environment Variables
Vim ~ /. Bashrc
Add or integrate the PATH variable in. bashrc as follows:
# Java program development/running environment variables
Java_home =/usr/lib/JVM/Java-6-sun
Jre_home =$ {java_home}/JRE
Export android_java_home = $ java_home
Export classpath =. :$ {java_home}/lib: $ jre_home/lib: $ classpath
Export java_path =$ {java_home}/bin: $ {jre_home}/bin
Export java_home;
Export jre_home;
Export classpath;
Home_bin = ~ /Bin/
Export path =$ {path }:$ {java_path }:$ {jre_path }:: {home_bin };
# Echo $ path;
Finally, synchronize these changes:
Source ~ /. Bashrc
3. initialize the version Library
If you want to take down all the sourcecodes in the latest version of the current Android main line, we need repo help.
First create a directory, such ~ /Android. Use the repo init command after entering the file.
Repo init-u git: // android.git.kernel.org/platform/manifest.git
This process will last for a long time (at least you can have a good sleep). The specific time depends on the network conditions.
Finally, you will see a prompt such as repo initialized in/Android, indicating that the local version library has been initialized and contains the latest sourcecode.
If you want to use a branch instead of the Code on the main line, you need to use the-B parameter to specify the branch name, for example:
Repo init-u git: // android.git.kernel.org/platform/manifest.git-B cupcake
This
The branch captured in is cupcake. Most of the articles compiled on the Internet are for cupcake branch, which is andoird.
Version 1.5, but I did not input the following parameters before, so that the following code is the code on the main line and Android
Version 2.1. There are some differences in the directory structure between the two. As a result, when I encounter an error following the instructions on the internet, I do not know the reason for the different versions or other reasons. So it's strange why
In this chapter, we talk about cupcake, rather than the source code compilation of the main line.
B. Compile the source code
If it is cupcake, the following error occurs when you make it directly:
1. Frameworks/policies/base/policyconfig. mk: 22: *** no module
Defined for the given product_policy (Android. policy_phone). Stop. Error.
Solution:
In row 89th of build/tools/findleaves. Sh,
Find "$ {@: 0: $ nargs}" $ findargs-type F-name "$ FILENAME"-print |
Change to find "$ {@: 1: $ nargs-1}" $ findargs-type F-name "$ FILENAME"-print |
2. Frameworks/base/tools/aidl/ast. cpp: 10: Error: 'fprintf' was not declared
In this scope Error
Solution:
Download gcc-4.3 and G ++-4.3
Apt-Get install gcc-4.3 g ++-4.3
Because ubuntu 9.10 comes with GCC 4.4, You need to download GCC 4.3 again, and finally set the GCC soft connection to GCC 4.3.
Enter/usr/bin
CD/usr/bin
Create a soft connection
Ln-s gcc-4.3 gcc
Ln-s g ++-4.3g ++
Then go to the android directory and execute make.
The main line code does not have this problem
C. Compile ADT
If you want to use eclipse to develop Android applications, it is best to install ADT so that you can create an android project under eclipse.
- Generate ADT eclipse plugins
|
$ development/tools/eclipse/scripts/build_server.sh ~/adt/ |
We recommend that you set the environment variable of eclipse_home before use, otherwise you will think that eclipse is not installed and then download it for you.
Note that I have been stuck here and cannot compile it all the time. At the beginning, the system will prompt that any jar of eclipse cannot be found, so fail. This is mainly because
When eclipse_home is set incorrectly to the environment variable. The previously installed eclipse is only captured from the new force. It seems that the directory where eclipse is located cannot be found, and the result is set.
A folder named eclipse is used as the environment variable. Therefore, I went directly to the eclipse official website and thought this would work. The result is an eclipse
Galileo eventually prompts that eclipse cannot find any file. In the end, there is no way to simply delete eclipse, and let the program go to eclipse and find
Eclipse Ganymede. Here I would like to solemnly explain that we should download Jee's ganymade, instead of Java
Ganymade.
The method is the same when the main line Code compiles ADT, but noThe development/tools/eclipse directory is in the bin/SDK/eclipse directory.
D. Compile the SDK
Make SDK.
E. Install ADT
ADT installation is very simple, and there are a lot of introductions on the Internet. It should be noted that after the ADT is installed and a new Android project is created, a bunch of errors are always reported when building Android-related projects, which are caused by errors similar to "W/resourcetype (2888): Unable to get buffer of resource asset file
"This error occurs. The solution is to overwrite the resource. ARSC in Android. Jar. The other statement on the internet is build.
Enter make in the SDK
Product-SDK, or change frameworks/base/tools/include/asset/h
Change 1*1024*1024 to 2*1024*1024. I have tried it, but it does not work ..
Note: This process is really depressing, because I have encountered many common problems, and I have also encountered some uncommon problems. Sometimes it is difficult to find a solution on Google, the most hateful thing is that many websites are still blocked, and they only need to go through the wall. So I want to write such a summary to record it and hope to provide some help to people with similar problems.