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 "deb http://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:
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.
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:
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:
 
 
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.
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
Choose NO.

 

$ 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

 

转载于:https://www.cnblogs.com/swads/archive/2013/06/06/3122626.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值