查看: 1706|回复: 0

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

[复制链接]

该用户从未签到

发表于 2014-8-21 11:48:42 | 显示全部楼层 |阅读模式
分享到:
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:
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:
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-toolsPATH
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
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/binPATH
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




770.97 KB, 下载次数: 207
原文作者:siriux
原文链接:http://forum.cubietech.com/forum.php?mod=viewthread&tid=430


回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /5 下一条

手机版|小黑屋|与非网

GMT+8, 2024-12-22 20:30 , Processed in 0.120087 second(s), 15 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.