我该如何解决这个致命异常?
我正在使用 NDK 将我的 C/C++ 代码移植到 Android 游戏中,但我在入门时遇到了困难。
我已经从developer.android.com下载了NDK-r5b并安装了Cygwin。
我什至无法运行 NDK 示例中提供的 Hello-jni 程序。
当我运行时:
$ cd /cygdrive/c/android/android-ndk-r5b/samples/hello-jni
$ ndk-build
我收到错误:您正在使用非 Cygwin 兼容的 Make 程序
。
我尝试安装 GNUMake 3.81 但问题仍然存在。
我尝试通过Eclipse IDE在NDK中运行HELLO-JNI
示例程序。 Android AVD 上存在强制关闭,logcat 显示异常如下:
04-08 12:32:11.609: ERROR/AndroidRuntime(274): FATAL EXCEPTION: main
04-08 12:32:11.609: ERROR/AndroidRuntime(274):
java.lang.ExceptionInInitializerError
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.Class.newInstanceImpl(Native Method)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.Class.newInstance(Class.java:1429)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2577)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2679)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.os.Handler.dispatchMessage(Handler.java:99)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.os.Looper.loop(Looper.java:123)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.main(ActivityThread.java:4627)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.reflect.Method.invokeNative(Native Method)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.reflect.Method.invoke(Method.java:521)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
dalvik.system.NativeStart.main(Native Method)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): Caused by:
java.lang.UnsatisfiedLinkError: Library hello-jni not found
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.Runtime.loadLibrary(Runtime.java:461)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.System.loadLibrary(System.java:557)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
com.example.hellojni.HelloJni.<clinit>(HelloJni.java:67)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): ... 15 more
04-08 12:32:11.678: WARN/ActivityManager(59): Force finishing
activity com.example.hellojni/.HelloJni
04-08 12:32:12.340: WARN/ActivityManager(59): Activity pause timeout
for HistoryRecord{44f925c8 com.example.hellojni/.HelloJni}
我怎样才能使其工作?
I am porting my C/C++ code into an Android Game using the NDK, but I'm having trouble getting started.
I have downloaded the NDK-r5b from developer.android.com and I have installed Cygwin.
I am not even able to run the Hello-jni
program provided within the NDK samples.
When I run:
$ cd /cygdrive/c/android/android-ndk-r5b/samples/hello-jni
$ ndk-build
I get an ERROR: You are using a non-Cygwin compatible Make program
.
I tried installing GNUMake 3.81 but the problem persists.
I tried to run the HELLO-JNI
sample program in the NDK through Eclipse IDE. There is a force close on the Android AVD, and logcat was showing an exception as follows:
04-08 12:32:11.609: ERROR/AndroidRuntime(274): FATAL EXCEPTION: main
04-08 12:32:11.609: ERROR/AndroidRuntime(274):
java.lang.ExceptionInInitializerError
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.Class.newInstanceImpl(Native Method)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.Class.newInstance(Class.java:1429)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2577)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2679)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.os.Handler.dispatchMessage(Handler.java:99)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.os.Looper.loop(Looper.java:123)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.main(ActivityThread.java:4627)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.reflect.Method.invokeNative(Native Method)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.reflect.Method.invoke(Method.java:521)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
dalvik.system.NativeStart.main(Native Method)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): Caused by:
java.lang.UnsatisfiedLinkError: Library hello-jni not found
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.Runtime.loadLibrary(Runtime.java:461)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.System.loadLibrary(System.java:557)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
com.example.hellojni.HelloJni.<clinit>(HelloJni.java:67)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): ... 15 more
04-08 12:32:11.678: WARN/ActivityManager(59): Force finishing
activity com.example.hellojni/.HelloJni
04-08 12:32:12.340: WARN/ActivityManager(59): Activity pause timeout
for HistoryRecord{44f925c8 com.example.hellojni/.HelloJni}
How can I make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也有同样的问题,我想通了。导致我陷入困境的事情是在“项目属性”->“项目属性”中。 C/C++ 构建 ->构建命令:设置为“bash ndk-build”而不是“bash C:\android-ndk-r6\ndk-build”
I had this same issue and I figured it out. The thing that was causing it to mess up for me was in Project Properties -> C/C++ Build -> Build command: was set to 'bash ndk-build' instead of 'bash C:\android-ndk-r6\ndk-build'
我遇到了这个问题。事实证明,当我安装 Cygwin 时,GNU 工具链并未安装,并且 make 是从我的构建机器上安装的另一个 SDK 中获取的。修复方法是重新安装 Cygwin 并检查 Gnu 工具是否已安装。 (我认为Cygwin设置中的标题是“Devel”。默认不安装,更改为“install”)。华泰
I had this problem. It turned out that the GNU tool chain was not installed when I installed Cygwin, and make was being picked up from another SDK installed on my build machine. The fix was to reinstall Cygwin and check that the Gnu tools were installed. (I think the heading is 'Devel' in the Cygwin setup. The default is not to install, change to 'install'). HTH
我通过执行以下操作在 Eclipse 中解决了这个问题:
在“C/C++ Build”中选择“构建器部分”,然后在“构建器”组中将以下内容放入“构建命令”文本框:
bash“_cygwin_home_\home\android-ndk-r6b\ndk-build”
我希望这对你有帮助。
I tackled this in Eclipse by doing the following:
In the "C/C++ Build" choose "builder section" then in the "builder" group put the following in the "build command" textbox:
bash "_cygwin_home_\home\android-ndk-r6b\ndk-build"
I hope this help you.