Linux下Android开发环境搭建指南

By LongLuo

一、Java

1
2
sudo apt-get update
sudo apt-get install openjdk-8-jdk openjdk-8-jre

通过which java找到java安装路径

添加环境变量

1
sudo vim ~/.bashrc

在文件末尾加入下列内容:

1
2
3
4
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${PATH}:${JAVA_HOME}/bin

二、Android

2.1 SDK

2.2 NDK

https://developer.android.google.cn/training/articles/perf-jni?hl=zh_cn

Linux下Android NDK

下载NDK版本:

https://developer.android.google.cn/ndk/downloads/

最新LTS版本(r21e):

下载Linux x86_64版本:

解压之后:

要想使用Android NDK,还需要进行环境变量的配置:

sudo vim ~/.bashrc

在文件末尾添加以下内容:

1
2
export ANDROID_NDK=/NDK Folder Path
export PATH=${PATH}:$NDK

其中文件夹路径要精确到解压后的最高层路径,例如:

1
2
export ANDROID_NDK=/mnt/e/Android/Linux/android-ndk-r21e
export PATH=$PATH:$ANDROID_NDK

保存文件并使之生效:

1
source ~/.bashrc

Android NDK的安装验证:

安装并配置完成Android NDK之后,需要进行安装验证,以确认正确安装并配置:

1
2
3
4
5
6
7
8
9
10
11
12
luolong@LAPTOP-BTCQ8FL5:~$ ndk-build
fcntl(): Operation not supported
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/mnt/e/Android/Linux/android-ndk-r21e/build/core/build-local.mk:151: *** Android NDK: Aborting . Stop.
luolong@LAPTOP-BTCQ8FL5:~$ ndk-build -version
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

只要不是command not found,ndk-build命令不存在,就表明Android NDK安装并配置成功。