gpt4 book ai didi

android - java.lang.IllegalArgumentException : Unable to load native library 异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:26:28 26 4
gpt4 key购买 nike

我在我的项目 (Native Activity) 中使用纯原生 NDK。当我在 Android.mk 文件中使用我的 .so 添加预构建静态库时,它工作正常。但是当我尝试链接 Prebuilt 共享库时,它显示以下异常:

03-27 16:42:09.982: E/AndroidRuntime(1275): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.irrlicht.example/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app-lib/com.irrlicht.example-1/libHelloWorldMobile.so

这是我的 Android.mk 文件:

....

include $(CLEAR_VARS)
LOCAL_C_INCLUDES := /Users/karthi/Android/openal-soft-master/jni/OpenAL/include
LOCAL_MODULE := openal
LOCAL_SRC_FILES := /Users/karthi/Android/openal-soft-master/libs/armeabi/libopenal.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := HelloWorldMobile

LOCAL_CFLAGS := -D_IRR_ANDROID_PLATFORM_ -pipe -fno-exceptions -fno-rtti -fstrict-aliasing

LOCAL_C_INCLUDES := -I ../../include -I /Users/karthi/Android/openal-soft-master/jni/OpenAL/include

LOCAL_SRC_FILES := main.cpp android_tools.cpp game.cpp

LOCAL_LDLIBS := -lEGL -llog -lGLESv1_CM -lGLESv2 -lz -landroid

LOCAL_SHARED_LIBRARIES := openal

include $(BUILD_SHARED_LIBRARY)

在我的 AndroidManifest.xml 中:

<activity android:name="android.app.NativeActivity"
android:label="HelloWorldMobile"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:clearTaskOnLaunch="true">
<meta-data android:name="android.app.lib_name" android:value="HelloWorldMobile" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />

最后在 Application.mk 中:

APP_PLATFORM := android-18
APP_MODULES := HelloWorldMobile
APP_STL := stlport_static

我也试过将最后一行替换为,

APP_STL := stlport_shared

我还应该如何将预构建的共享库链接到我的 native 库?我在这里错过了什么?任何帮助将不胜感激。

编辑:

03-28 11:57:51.469: D/dalvikvm(824): Debugger has detached; object registry had 1 entries
03-28 11:57:51.479: W/dalvikvm(836): PR_CAPBSET_DROP 1 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.479: W/dalvikvm(836): PR_CAPBSET_DROP 2 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.479: W/dalvikvm(836): PR_CAPBSET_DROP 3 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.479: W/dalvikvm(836): PR_CAPBSET_DROP 4 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.489: W/dalvikvm(836): PR_CAPBSET_DROP 5 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.489: W/dalvikvm(836): PR_CAPBSET_DROP 6 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.489: W/dalvikvm(836): PR_CAPBSET_DROP 7 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.489: W/dalvikvm(836): PR_CAPBSET_DROP 8 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.489: W/dalvikvm(836): PR_CAPBSET_DROP 9 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.489: W/dalvikvm(836): PR_CAPBSET_DROP 10 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.489: W/dalvikvm(836): PR_CAPBSET_DROP 11 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.489: W/dalvikvm(836): PR_CAPBSET_DROP 12 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.489: W/dalvikvm(836): PR_CAPBSET_DROP 13 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.489: W/dalvikvm(836): PR_CAPBSET_DROP 14 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.499: W/dalvikvm(836): PR_CAPBSET_DROP 15 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.499: W/dalvikvm(836): PR_CAPBSET_DROP 16 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.499: W/dalvikvm(836): PR_CAPBSET_DROP 17 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.499: W/dalvikvm(836): PR_CAPBSET_DROP 18 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.499: W/dalvikvm(836): PR_CAPBSET_DROP 19 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.499: W/dalvikvm(836): PR_CAPBSET_DROP 20 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.499: W/dalvikvm(836): PR_CAPBSET_DROP 21 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.499: W/dalvikvm(836): PR_CAPBSET_DROP 22 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.499: W/dalvikvm(836): PR_CAPBSET_DROP 23 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.509: W/dalvikvm(836): PR_CAPBSET_DROP 24 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.509: W/dalvikvm(836): PR_CAPBSET_DROP 25 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.519: W/dalvikvm(836): PR_CAPBSET_DROP 26 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.519: W/dalvikvm(836): PR_CAPBSET_DROP 27 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.519: W/dalvikvm(836): PR_CAPBSET_DROP 28 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.519: W/dalvikvm(836): PR_CAPBSET_DROP 29 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.519: W/dalvikvm(836): PR_CAPBSET_DROP 30 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.529: W/dalvikvm(836): PR_CAPBSET_DROP 31 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.529: W/dalvikvm(836): PR_CAPBSET_DROP 32 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.529: W/dalvikvm(836): PR_CAPBSET_DROP 33 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
03-28 11:57:51.529: D/dalvikvm(836): Not late-enabling CheckJNI (already on)
03-28 11:57:51.539: I/ActivityManager(275): Start proc com.irrlicht.example for activity com.irrlicht.example/android.app.NativeActivity: pid=836 uid=10061 gids={50061, 1015, 1028}
03-28 11:57:51.929: I/ActivityManager(275): Config changes=1480 {1.0 310mcc260mnc en_US ldltr sw320dp w533dp h294dp 240dpi nrml long land finger qwerty/v/v -nav/h s.7}
03-28 11:57:51.954: I/InputReader(275): Reconfiguring input devices. changes=0x00000004
03-28 11:57:51.954: I/InputReader(275): Device reconfigured: id=0, name='qwerty2', size 480x800, orientation 1, mode 1, display id 0
03-28 11:57:51.969: I/InputReader(275): Reconfiguring input devices. changes=0x00000004
03-28 11:57:51.969: I/InputReader(275): Device reconfigured: id=0, name='qwerty2', size 480x800, orientation 1, mode 1, display id 0
03-28 11:57:52.529: D/dalvikvm(524): GC_FOR_ALLOC freed 9228K, 70% free 4038K/13380K, paused 192ms, total 216ms
03-28 11:57:52.569: I/dalvikvm-heap(524): Grow heap (frag case) to 10.166MB for 6410576-byte allocation
03-28 11:57:52.690: D/dalvikvm(524): GC_FOR_ALLOC freed 11K, 24% free 10287K/13380K, paused 118ms, total 118ms
03-28 11:57:52.699: D/AndroidRuntime(836): Shutting down VM
03-28 11:57:52.709: W/dalvikvm(836): threadid=1: thread exiting with uncaught exception (group=0x41465700)
03-28 11:57:52.739: E/AndroidRuntime(836): FATAL EXCEPTION: main
03-28 11:57:52.739: E/AndroidRuntime(836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.irrlicht.example/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app-lib/com.irrlicht.example-1/libHelloWorldMobile.so
03-28 11:57:52.739: E/AndroidRuntime(836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
03-28 11:57:52.739: E/AndroidRuntime(836): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
03-28 11:57:52.739: E/AndroidRuntime(836): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-28 11:57:52.739: E/AndroidRuntime(836): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-28 11:57:52.739: E/AndroidRuntime(836): at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 11:57:52.739: E/AndroidRuntime(836): at android.os.Looper.loop(Looper.java:137)
03-28 11:57:52.739: E/AndroidRuntime(836): at android.app.ActivityThread.main(ActivityThread.java:5103)
03-28 11:57:52.739: E/AndroidRuntime(836): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 11:57:52.739: E/AndroidRuntime(836): at java.lang.reflect.Method.invoke(Method.java:525)
03-28 11:57:52.739: E/AndroidRuntime(836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-28 11:57:52.739: E/AndroidRuntime(836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-28 11:57:52.739: E/AndroidRuntime(836): at dalvik.system.NativeStart.main(Native Method)
03-28 11:57:52.739: E/AndroidRuntime(836): Caused by: java.lang.IllegalArgumentException: Unable to load native library: /data/app-lib/com.irrlicht.example-1/libHelloWorldMobile.so
03-28 11:57:52.739: E/AndroidRuntime(836): at android.app.NativeActivity.onCreate(NativeActivity.java:184)
03-28 11:57:52.739: E/AndroidRuntime(836): at android.app.Activity.performCreate(Activity.java:5133)
03-28 11:57:52.739: E/AndroidRuntime(836): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-28 11:57:52.739: E/AndroidRuntime(836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
03-28 11:57:52.739: E/AndroidRuntime(836): ... 11 more
03-28 11:57:52.779: W/ActivityManager(275): Force finishing activity com.irrlicht.example/android.app.NativeActivity

最佳答案

我已经通过创建 Native Activity 的子类并加载共享库来解决这个问题,如下所示:

package com.irrlicht.example;

public class MyActivity extends android.app.NativeActivity {

static {
System.loadLibrary("HelloWorldMobile");
System.loadLibrary("openal");
}
}

在 AndroidManfest.xml 中,我包含了 MyActivity 而不是 android.app.NativeActivity。从 here 获得此解决方案.但是有没有办法不用java类就可以完全解决这个问题呢?

关于android - java.lang.IllegalArgumentException : Unable to load native library 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22686900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com