我该如何解决这个致命异常?

发布于 2024-10-31 06:54:40 字数 3130 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

慕巷 2024-11-07 06:54:40

我也有同样的问题,我想通了。导致我陷入困境的事情是在“项目属性”->“项目属性”中。 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'

绮筵 2024-11-07 06:54:40

我遇到了这个问题。事实证明,当我安装 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

旧人哭 2024-11-07 06:54:40

我通过执行以下操作在 Eclipse 中解决了这个问题:

  1. 右键单击项目名称并选择“属性”
  2. 在“C/C++ Build”中选择“构建器部分”,然后在“构建器”组中将以下内容放入“构建命令”文本框:

    bash“_cygwin_home_\home\android-ndk-r6b\ndk-build”

    • 将“_cygwin_home_”替换为您的 cygwin 实际路径,
    • 我将 ndk 文件夹放在 cygwin 安装文件夹的主文件夹中(如您所见)。

我希望这对你有帮助。

I tackled this in Eclipse by doing the following:

  1. Right click on the project name and choose "properties"
  2. 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"

    • replace "_cygwin_home_" with your actual path to cygwin,
    • I place the ndk folder inside the home folder in the cygwin installtion folder(as you can see).

I hope this help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文