*
作者:左少华
转载请注明出处:http://blog.csdn.net/shaohuazuo/article/details/46495747
*
android应用开发环境搭建
- Java JDK安装和配置.
- Android NDK 下载安装配置.
- Android ADT 下载安装配置.
- Android SDK 下载.
- Android Studio 安装配置.
## Oracle JDK 下载安装配置 ##
- JDK6下载地址:
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html - JDK7下载地址:
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html - JDK8下载地址:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html - 百度网盘链接地址如下:
http://pan.baidu.com/s/1sjNtIax
Ubuntu14.10下安装JDK并配置多个版本切换
- JDK1.6安装:
使用update-alternatives工具来创建链接文件.
sudo update-alternatives –install “/usr/bin/java” “java” “usr/lib/jvm/jdk6/jdk1.6.0_43/bin/java” 1 - 其他同上.最后的结果如下.update-alternatives会创建如下两个链接文件如下:
[email protected]:/usr/bin$ ls -l |grep jalrwxrwxrwx 1 root root 21 Dec 5 2014 jar -> /etc/alternatives/jarlrwxrwxrwx 1 root root 22 Mar 30 09:59 java -> /etc/alternatives/javalrwxrwxrwx 1 root root 23 Dec 5 2014 javac -> /etc/alternatives/javaclrwxrwxrwx 1 root root 25 Dec 5 2014 javadoc -> /etc/alternatives/javadoclrwxrwxrwx 1 root root 23 Dec 22 17:04 javah -> /etc/alternatives/javahlrwxrwxrwx 1 root root 23 Apr 29 07:20 javap -> /etc/alternatives/javaplrwxrwxrwx 1 root root 24 Jun 16 00:35 javaws -> /etc/alternatives/javaws
zshh@HP:/etc/alternatives$ ls -l |grep javalrwxrwxrwx 1 root root 38 Jun 16 00:31 jar -> /usr/lib/jvm/java6/jdk1.6.0_43/bin/jarlrwxrwxrwx 1 root root 39 Jun 15 00:43 java -> /usr/lib/jvm/java6/jdk1.6.0_43/bin/javalrwxrwxrwx 1 root root 40 Jun 15 23:54 javac -> /usr/lib/jvm/java6/jdk1.6.0_43/bin/javaclrwxrwxrwx 1 root root 42 Jun 15 00:47 javadoc -> /usr/lib/jvm/java6/jdk1.6.0_43/bin/javadoclrwxrwxrwx 1 root root 40 Jun 15 00:48 javah -> /usr/lib/jvm/java6/jdk1.6.0_43/bin/javahlrwxrwxrwx 1 root root 40 Jun 16 00:27 javap -> /usr/lib/jvm/java6/jdk1.6.0_43/bin/javaplrwxrwxrwx 1 root root 41 Jun 16 00:38 javaws -> /usr/lib/jvm/java6/jdk1.6.0_43/bin/javaws
上面每个链接要确保正确,否则执行命令的时候提示没有安装这个软件.
JDK1.7安装: 安装过程和jdk完全一样.
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java7/jdk1.7.0_80/bin/java" 2 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java7/jdk1.7.0_80/bin/javac" 2sudo update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/java7/jdk1.7.0_80/bin/jar" 2sudo update-alternatives --install "/usr/bin/javap" "javap" "/usr/lib/jvm/java7/jdk1.7.0_80/bin/javap" 2sudo update-alternatives --install "/usr/bin/javadoc" "javadoc" "/usr/lib/jvm/java7/jdk1.7.0_80/bin/javadoc" 2sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/java7/jdk1.7.0_80/bin/javaws" 2
安装成功后文件如下:
[email protected]:/usr/bin$ ls -l |grep jalrwxrwxrwx 1 root root 21 Dec 5 2014 jar -> /etc/alternatives/jarlrwxrwxrwx 1 root root 22 Mar 30 09:59 java -> /etc/alternatives/javalrwxrwxrwx 1 root root 23 Dec 5 2014 javac -> /etc/alternatives/javaclrwxrwxrwx 1 root root 25 Dec 5 2014 javadoc -> /etc/alternatives/javadoclrwxrwxrwx 1 root root 23 Dec 22 17:04 javah -> /etc/alternatives/javahlrwxrwxrwx 1 root root 23 Apr 29 07:20 javap -> /etc/alternatives/javaplrwxrwxrwx 1 root root 24 Jun 16 00:35 javaws -> /etc/alternatives/javaws
zshh@HP:/etc/alternatives$ ls -l |grep javalrwxrwxrwx 1 root root 38 Jun 16 00:54 jar -> /usr/lib/jvm/java7/jdk1.7.0_80/bin/jarlrwxrwxrwx 1 root root 39 Jun 16 00:51 java -> /usr/lib/jvm/java7/jdk1.7.0_80/bin/javalrwxrwxrwx 1 root root 40 Jun 16 00:47 javac -> /usr/lib/jvm/java7/jdk1.7.0_80/bin/javaclrwxrwxrwx 1 root root 42 Jun 16 00:55 javadoc -> /usr/lib/jvm/java7/jdk1.7.0_80/bin/javadoclrwxrwxrwx 1 root root 40 Jun 15 00:48 javah -> /usr/lib/jvm/java6/jdk1.6.0_43/bin/javahlrwxrwxrwx 1 root root 40 Jun 16 00:55 javap -> /usr/lib/jvm/java7/jdk1.7.0_80/bin/javaplrwxrwxrwx 1 root root 41 Jun 16 00:56 javaws -> /usr/lib/jvm/java7/jdk1.7.0_80/bin/javaws
切换JDK版本
通过一下方法来zshh@HP:~/Desktop/android-studio/bin$ sudo update-alternatives --config java[sudo] password for zshh: There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status------------------------------------------------------------ 0 /usr/lib/jvm/java7/jdk1.7.0_80/bin/java 2 auto mode 1 /usr/lib/jvm/java6/jdk1.6.0_43/bin/java 1 manual mode* 2 /usr/lib/jvm/java7/jdk1.7.0_80/bin/java 2 manual modePress enter to keep the current choice[*], or type selection number: 1
Android NDK 下载安装配置
官方下载地址:
http://dl.google.com/android/ndk/android-ndk64-r10-linux-x86.tar.bz2
http://dl.google.com/android/ndk/android-ndk64-r10-linux-x86_64.tar.bz2百度网盘NDK下载地址:
http://pan.baidu.com/s/1eQm21sI
NDK是什么
- NDK:Native Development Kit
- Android NDK是一个让开发人员在Android应用中嵌入使用本地代码编写的组件的工具集。
- Android应用运行在Dalvik虚拟机中。NDK允许开发人员使用本地代码语言(例如C和C++)实现应用的部分功能。这样以代码重用的形式能够给某类应用提供方便,而且在某些情况下能提高运行速度(音视频播放)
NDK提供什么
- 将C和C++代码编译成库的工具集
- 将本地库嵌入到应用包(.apk)中并发布在Android设备上的方法(.so库文件调用)
- 一套本地系统头文件和库,这些文件和库将在Android1.5以后的版本中被支持。使用native activies的应用必须运行在Android2.3及以上版本。
为什么使用NDK
- 代码的保护,由于apk的java层代码很容易被反编译,而C/C++库反汇难度较大。
- 在NDK中调用第三方C/C++库,因为大部分的开源库都是用C/C++代码编写的。
- 便于移植,用C/C++写得库可以方便在其他的嵌入式平台上再次使用。
安装NDK
- 我需要安装ndk-r9,和ndk-r10两个版本. 在/usr/lib创建两个目录
zshh@HP:/usr/lib$ mkdir ndk/ndk-r9 -pzshh@HP:/usr/lib$ mkdir ndk/ndk-r10 -p
- 将下载好的NDK版本cp到两个目录下.
zshh@HP:/usr/lib$ sudo cp /media/zshh/My\ Passport/ubuntu系统备份/NDK备份/android-ndk-r9d-linux-x86.tar.bz2 ./zshh@HP:/usr/lib/ndk/ndk-r10$ sudo cp /media/zshh/My\ Passport/ubuntu系统备份/NDK备份/android-ndk64-r10-linux-x86_64.tar.bz2 ./
- 安装r9版本ndk.
[email protected]:/usr/lib/ndk/ndk-r9$ tar -xvf android-ndk-r9d-linux-x86.tar.bz2 //解压[email protected]:/usr/lib/ndk/ndk-r9$ cd android-ndk-r9d/ //进入目录[email protected]:/usr/lib/ndk/ndk-r9/android-ndk-r9d$ pwd //查看当前路径/usr/lib/ndk/ndk-r9/android-ndk-r9d
- 配置NDK环境变量方法一:
//分析profile文件如何配置NDK环境变量:# The default umask is now handled by pam_umask.# See pam_umask(8) and /etc/login.defs.if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset ifi//ubuntu启动的时候它会读取profile.d/*sh;文件执行内容.//所有我们只需要写一个android-ndk.sh放/etc/profile.d目录下就ok了.内如如下:export ANDROID_NDK="/usr/lib/ndk/ndk-r9/android-ndk-r9d"export PATH="${PATH}:${ANDROID_NDK}"
- 配置NDK环境变量方法二:
[email protected]:/etc/profile.d$ vim ~/.bashrc //在行文件末尾加上你的ndk路径.使用":"分割两个不同的环境变量.export PATH=/usr/lib/ndk/ndk-r9/android-ndk-r9d:$PATH
- 验证安装是否成功.
zshh@HP:/usr/lib/ndk/ndk-r9/android-ndk-r9d/samples/hello-jni/jni$ ndk-build[armeabi-v7a] Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver[armeabi-v7a] Gdbsetup : libs/armeabi-v7a/gdb.setup[armeabi] Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver[armeabi] Gdbsetup : libs/armeabi/gdb.setup[x86] Gdbserver : [x86-4.6] libs/x86/gdbserver[x86] Gdbsetup : libs/x86/gdb.setup[mips] Gdbserver : [mipsel-linux-android-4.6] libs/mips/gdbserver[mips] Gdbsetup : libs/mips/gdb.setup[armeabi-v7a] Compile thumb : hello-jni <= hello-jni.c[armeabi-v7a] SharedLibrary : libhello-jni.so[armeabi-v7a] Install : libhello-jni.so => libs/armeabi-v7a/libhello-jni.so[armeabi] Compile thumb : hello-jni <= hello-jni.c[armeabi] SharedLibrary : libhello-jni.so[armeabi] Install : libhello-jni.so => libs/armeabi/libhello-jni.so[x86] Compile : hello-jni <= hello-jni.c[x86] SharedLibrary : libhello-jni.so[x86] Install : libhello-jni.so => libs/x86/libhello-jni.so[mips] Compile : hello-jni <= hello-jni.c[mips] SharedLibrary : libhello-jni.so[mips] Install : libhello-jni.so => libs/mips/libhello-jni.so
Android Studio下载配置安装.
百度网盘下载地址
http://pan.baidu.com/s/1dDnQpK9安装
//解压这个studio包.[email protected]:~$ tar -xvf /home/zshh/Desktop/android-studio-ide-141.1890965-linux.zip //进入android-studio的bin目录下.[email protected]:~$ cd android-studio/bin//修改文件idea.properties[email protected]:~/android-studio/bin$ vim idea.properties//在文件的末尾加上如下一行disable.android.first.run=true//执行命令启动即可.[email protected]:~/android-studio/bin$ ./studio.sh
- 使用教程
http://www.android-studio.org/index.php/docs/guide