Heyho。我有与此人相同的错误消息: “Android NDK app failed to load library” 而我现在试图将这些答案转移到我的情况上几个小时,但它不起作用。 有人能帮我吗? 这是这个开源项目,我想尝试让它在我的模拟器上运行。 https://github.com/itskewpie/FreeRDP-android
FreeRDPActivity.java
package net.itskewpie.freerdp;
import android.app.Activity;
import android.os.Bundle;
public class FreeRDPActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
static {
System.loadLibrary("freerdp");
}
}
freerdp.c
#include <jni.h>
#include <stdio.h>
#include <freerdp/freerdp.h>
jstring Java_net_itskewpie_freerdp_FreeRDPActivity_test(JNIEnv* env, jobject thiz )
{
android_main();
return (*env)->NewStringUTF(env, "HELLO");
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
MY_LIBS_PATH=freerdp-1.0-nevo/libs/armeabi-v7a
LOCAL_MODULE := freerdp-utils
LOCAL_SRC_FILES := $(MY_LIBS_PATH)/libfreerdp-utils.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/freerdp-1.0-nevo/include
include $(PREBUILT_STATIC_LIBRARY)
...
错误讯息:
FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
java.lang.Class.newInstanceImpl(Native Method)
java.lang.Class.newInstance(Class.java:1319)
android.app.Instrumentation.newActivity(Instrumentation.java:1054)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
android.app.ActivityThread.access$600(ActivityThread.java:141)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:5041)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
dalvik.system.NativeStart.main(Native Method)
java.lang.UnsatisfiedLinkError: Couldn't load freerdp from loader dalvik.system.PathClassLoader[dexPath=/data/app/net.itskewpie.freerdp-2.apk,libraryPath=/data/app-lib/net.itskewpie.freerdp-2]: findLibrary returned null
java.lang.Runtime.loadLibrary(Runtime.java:365)
java.lang.System.loadLibrary(System.java:535)
net.itskewpie.freerdp.FreeRDPActivity.<clinit>(FreeRDPActivity.java:16)
... 15 more
答案 0 :(得分:1)
尝试这个开源项目:
答案 1 :(得分:0)
你是否完全像在github项目中那样复制Android.mk?您是否也复制了相关的图书馆?
#
## libfreerdp.so
#
include $(CLEAR_VARS)
LOCAL_MODULE := freerdp
LOCAL_SRC_FILES := freerdp.c
LOCAL_ARM_MODE := arm
NDK_TOOLCHAIN_ROOT=/opt/android-toolchain
LOCAL_STATIC_LIBRARIES := freerdp-utils
LOCAL_STATIC_LIBRARIES += freerdp-locale
LOCAL_STATIC_LIBRARIES += freerdp-crypto
LOCAL_STATIC_LIBRARIES += freerdp-sspi
LOCAL_STATIC_LIBRARIES += freerdp-codec
LOCAL_STATIC_LIBRARIES += freerdp-core
LOCAL_STATIC_LIBRARIES += freerdp-cache
LOCAL_STATIC_LIBRARIES += freerdp-gdi
LOCAL_STATIC_LIBRARIES += freerdp-rail
LOCAL_STATIC_LIBRARIES += freerdp-channels
LOCAL_STATIC_LIBRARIES += rdpsnd_alsa
LOCAL_STATIC_LIBRARIES += cliprdr
LOCAL_STATIC_LIBRARIES += rdpsnd
LOCAL_STATIC_LIBRARIES += freerdp_android
在Java方面,看起来你应该按照适当的顺序加载其他库:
static {
System.loadLibrary("freerdp-utils");
System.loadLibrary("freerdp-codec");
System.loadLibrary("freerdp-gdi");
System.loadLibrary("freerdp-core");
System.loadLibrary("freerdp-rail");
System.loadLibrary("freerdp-chche");
System.loadLibrary("freerdp-crypto");
System.loadLibrary("freerdp-sspi");
System.loadLibrary("freerdp-channels");
System.loadLibrary("rdpsnd_alsa");
System.loadLibrary("cliprdr");
System.loadLibrary("rdpsnd");
System.loadLibrary("freerdp_android");
System.loadLibrary("freerdp");
}