您的位置:首页 > 移动开发 > Android开发

Android Studio ndk第一次使用

2015-03-06 13:49 423 查看
**

1。安装Ndk并配置环境变量:

系统环境:Ubuntukylin 14.04 ,32位系统

ndk下载32地址:http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86.bin

ndk下载64位地址:http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin

官方文档给出的以下安装提示(进在Linux下进行的尝试):

On Linux and Mac OS X (Darwin):

Download the appropriate package from this page.

Open a terminal window.

Go to the directory to which you downloaded the package.

Run chmod a+x on the downloaded package.

其实就是使用Ctrl+Alt+T组合键打开terminal,使用如下命令进行下载:

$:mkdir android
$:cd android
android$:wget http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86.bin android$:chmod a+x android-ndk-r10c-darwin-x86.bin
android$:./android-ndk-r10c-darwin-x86.bin


文件夹android-ndk-r10d就是Ndk的目录文件!

接下来需要配置环境变量:

$:gedit .bashrc


添加如下内容:

export NDK=/home/xff/android/android-ndk-r10d
export PATH=${PATH}:$NDK `


然后使用命令:

$:source .bashrc


使用命令检查配置:

~$ ndk-build -v
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu


2。Ndk使用示例

Android开发工具:Android Studio 1.0

系统环境:Ubuntukylin14.04

Java环境:JDk1.7

打开Android Stidio工具:

导入Ndk文件下的示例Demo,代码所在目录:~android/android-ndk-r10d/samples/hello-jni

如图:



左边是工程目录,右边文件是local.properties的内容,需要在里面添加:

ndk.dir=/home/xff/android/android-ndk-r10d


然后运行hello-jni工程即可编译成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: