Android开发从零开始,搭建交叉编译环境

1.     Requirements

1.1  Hardware

1.1.1 CPU: Intel 2.5G I5 x64;

1.1.2 Memory: 16G DDR3;

1.1.3 Disk: 30GB;

1.1.4 Internet connected;

1.2 Software

1.2.1OS: Ubuntu 12.04(64 bit);

1.2.2Java JDK 6;

1.2.3Eclipse;

1.2.4ADT;

1.2.5CDT;

1.2.6Android SDK;

1.2.7Android NDK;

1.2.8Linux Source;

1.2.9Android Source.

2. Initializinga Build Environment

   Attention: Demonstration is in Ubuntu 12.04(32bit).

2.1 Installingthe JDK

The Sun JDK is no longer in Ubuntu's mainpackage repository. In order to download it, you need to add the appropriaterepository and indicate to the system which JDK should be used.

Inputthe following command in the Terminal:

$ sudo gedit /etc/apt/sources.list

Add:

$ deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse

Inputin terminal:

$ sudo add-apt-repository "debhttp://archive.canonical.com/ lucid partner"

$ sudo apt-get update

$ sudo apt-get install sun-java6-jdk

2.2 Installingthe Android SDK

Downloadthe SDK from Web Browser:

http://developer.android.com/sdk/index.html

Choosethe adt-bundle-linux-x86-20130219.zip.


Inputin the terminal:

$ sudo mkdir ~/sdk

Copythe adt-bundle-linux-x86-20130219.zipto the /root/sdk and extract the zip.

Enterthe folder /root/sdk/adt-bundle-linux-x86-20130219/sdk/tools.



Doubleclick the script file android.


It willshow the Android SDK Manager. Choosethe package with ticks.


Thenclick the Install XX packages buttonon the right. It will start download the required packages.

Afterthe installation, add the SDK tools to PATHEnvironment Variable.

Inputin the terminal:

       $ gedit/etc/profile

Inputin the “profile”

       $ exportANDROID_SDK_PATH=/root/sdk/adt-bundle-linux-x86-20130219/sdk

       $ export PATH=.:$ANDROID_SDK_PATH/platform-tools:$PATH

Saveand close the profile.

Inputin the terminal:

       $ source/etc/profile

2.2 Installingthe Eclipse

Withthe download of adt-bundle-linux-x86-20130219.zip,we can find the Eclipse in the /root/sdk/adt-bundle-linux-x86-20130219/eclipse.


Doubleclick the eclipse can run it.

2.2.1Installing the ADT online

AndroidDevelopment Tools (ADT) is a plugin for the Eclipse IDEthat is designed to give you a powerful, integrated environment in which tobuild Android applications.        

ADTextends the capabilities of Eclipse to let you quickly set up new Androidprojects, create an application UI, add packages based on the Android Framework API, debug yourapplications using the Android SDK tools, and even export signed (or unsigned).apk files in order to distribute your application.

Run theeclipse and click the help>Install NewSoftware.

Then clickthe Add button.


Input the Name ADT.

Input the Locationhttps://dl-ssl.google.com/android/eclipse.

Click OK. Then it will show the choice for installation.


Click Select All and Next.

2.2.2Installing the NDK

The NDKis a toolset that allows you to implement parts of your app using native-codelanguages such as C and C++. For certain types of apps, this can be helpful soyou can reuse existing code libraries written in these languages, but most appsdo not need the Android NDK.

Downloadthe NDK from Web Browser:

http://developer.android.com/sdk/ndk/index.html

Choosethe android-ndk-r8e-linux-x86.tar.bz2.


Inputin the terminal:

$ sudo mkdir ~/ndk

Copythe android-ndk-r8e-linux-x86.tar.bz2to the /root/sdk and extract the zip.

Inputin the terminal:

$tar –xvf android-ndk-r8e-linux-x86.tar.bz2

Finally,add the NDK folder to PATH EnvironmentVariable.

2.2.3 Installing the CDT

       TheCDT Project provides a fully functional C and C++ Integrated DevelopmentEnvironment based on the Eclipse platform. Features include: support forproject creation and managed build for various toolchains, standard make build,source navigation, various source knowledge tools, such as type hierarchy, callgraph, include browser, macro definition browser, code editor with syntaxhighlighting, folding and hyperlink navigation, source code refactoring andcode generation, visual debugging tools, including memory, registers, anddisassembly viewers.

       Theinstallation of CDT is the same as ADT.

But theLocation of CDT is:

http://download.eclipse.org/tools/cdt/releases/indigo

2.3Installing the Cross Compiling Environment

       TheCPU X86 is using the CISC, while the ARM processor is RISO. Therefore, thecross compiling environment should be installed.

TheCodeSourcery is an good choice for the cross compiling. It can be download fromthe following website.

http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/

Choosethe ARM Processor GNU/Linux release.


It willneed your personal information. Finally, system will send you an Email with thedownload URL.


Click the Download Sourcery CodeBench Lite 2012.09-64.



Choose the IA32 GNU/Linux Installer.


Afterdownload, enter the folder in terminal and use the following command:

       $ ln –s/lib/i386-linux-gnu/libc.so.6 /lib

$ dpkg-reconfigure dash

ChooseNO.


$ sh arm-2012.09-64-arm-none-linux-gnueabi.bin


Add theCodeSourvery to PATH.

Inputin the terminal:

       $ gedit/etc/profile

Inputin the profile.

           $export PATH=.:$/root/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_LIinux/bin:$PATH

Saveand close the profile.

Inputin the terminal:

       $ source/etc/profile

3. Test thefirst cross compiling environment

Programa simple first.c file.

#include<stdio.h>

int main()

{

              printf(“Hello world\n”);

              return 0;

}

Inputin the terminal:

       $ arm-none-linux-gnueabi-gcc–static –o first first.c

$ adb push first /data/local

$ adb shell

$ cd /data/local

$ ./first

  • Android Development Environment.pdf

    770.97 KB, 下载次数: 207

  • 原文作者:siriux

    原文链接:http://forum.cubietech.com/forum.php?mod=viewthread&tid=430


你可能感兴趣的:(android,cubieboard,交叉编译环境)