您的位置:首页 > 编程语言 > Java开发

Eclipse导入NDK例子工程

2016-05-30 09:09 489 查看

Eclipse导入NDK例子工程

前言

前几天,想导出NDK的例子,有的是编译不过,有的是运行时报错,查了资料,才知道是IDE环境配置有问题.

操作步骤记录

试验环境

Win7X64 + android-ndk-r10e



导入

拿android-ndk-r10e自带的hello-jni为例









解决导入后的错误

导入后,出现错误

[2016-05-30 07:35:34 - HelloJni] Unable to resolve target 'android-3'






在真机上运行报错

`java.lang.UnsatisfiedLinkError: Couldn't load hello-jni from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.hellojni-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.hellojni-1, /vendor/lib, /system/lib]]]: findLibrary returned null`


设置NDK路径





工程中加入android-NDK本地支持





报错,说没有找到Cygwin

`[2016-05-30 07:56:10 - Unable to launch cygpath. Is Cygwin on the path?] java.io.IOException: Cannot run program "cygpath": CreateProcess error=2, 系统找不到指定的文件。`








可以看到, ARM版的libhello-jni.so已经生成了.

但是有编译错误



这说明工程中的.h路径不对

#include <string.h>
#include <jni.h>


在ndk目录中找到arm版的正确包含路径,填入eclipse



关掉eclipse, 再打开eclipse, 再重新编译一次

编译报错



是清单文件报错了

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellojni"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="3" />
<application android:label="@string/app_name"
android:debuggable="true">
<activity android:name=".HelloJni"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>


修改成

去掉android:debuggable=”true”

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellojni"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="3" />
<application android:label="@string/app_name">
<activity android:name=".HelloJni"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>


关掉eclipse, 再打开eclipse, 再重新编译一次

现在在真机上可以运行了



虽然程序可以正常运行,但是可以看到Console有报错提示.

[2016-05-30 08:49:11 - Unable to launch cygpath. Is Cygwin on the path?] java.io.IOException: Cannot run program "cygpath": CreateProcess error=2, 系统找不到指定的文件。


NDK高版本不需要Cygwin, 让他报错去吧.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: