2013-10-12 127 views
0

首先抱歉我的英語不好。我只是要閱讀本地應用程序編程。 我做了這個教程:mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step /。Android NDK unsatisfiedlinkerror

Eclipse沒有帶來錯誤代碼或其他東西,但是當我在手機上啓動應用程序時,我收到錯誤消息「應用程序意外退出」。

在日誌中我得到以下錯誤信息:

10-12 15:14:34.400: D/mytag(1435): vor LiberyLoad 
10-12 15:14:34.400: D/dalvikvm(1435): Trying to load lib /data/data/com.example.nativeappc/lib/libndkfoo.so 0x4051d5e0 
10-12 15:14:34.405: D/dalvikvm(1435): Added shared lib /data/data/com.example.nativeappc/lib/libndkfoo.so 0x4051d5e0 
10-12 15:14:34.405: D/dalvikvm(1435): No JNI_OnLoad found in /data/data/com.example.nativeappc/lib/libndkfoo.so 0x4051d5e0, skipping init 
10-12 15:14:34.405: D/mytag(1435): nach LiberyLoad 
10-12 15:14:34.485: D/dalvikvm(1435): GC_EXTERNAL_ALLOC freed 45K, 50% free 2709K/5379K, external 0K/0K, paused 67ms 
10-12 15:14:34.505: W/dalvikvm(1435): No implementation found for native Lcom/example/nativeappc/MainActivity;.invokeNativeFunction()Ljava/lang/String; 
10-12 15:14:34.505: D/AndroidRuntime(1435): Shutting down VM 
10-12 15:14:34.505: W/dalvikvm(1435): threadid=1: thread exiting with uncaught exception (group=0x4001e578) 
10-12 15:14:34.505: E/AndroidRuntime(1435): FATAL EXCEPTION: main 
10-12 15:14:34.505: E/AndroidRuntime(1435): java.lang.UnsatisfiedLinkError: invokeNativeFunction 
10-12 15:14:34.505: E/AndroidRuntime(1435): at com.example.nativeappc.MainActivity.invokeNativeFunction(Native Method) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at com.example.nativeappc.MainActivity.onCreate(MainActivity.java:35) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at android.os.Handler.dispatchMessage(Handler.java:99) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at android.os.Looper.loop(Looper.java:130) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at android.app.ActivityThread.main(ActivityThread.java:3691) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at java.lang.reflect.Method.invokeNative(Native Method) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at java.lang.reflect.Method.invoke(Method.java:507) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 
10-12 15:14:34.505: E/AndroidRuntime(1435): at dalvik.system.NativeStart.main(Native Method) 

我的代碼文件看起來是這樣的:

MainActivity:

package com.example.nativeappc; 

import android.os.Bundle; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.util.Log; 
import android.view.Menu; 

public class MainActivity extends Activity 
{ 
    static 
    { 
     Log.d("mytag", "vor LiberyLoad"); 
     System.loadLibrary("ndkfoo"); 
     Log.d("mytag", "nach LiberyLoad"); 
    } 

    private native String invokeNativeFunction(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     // this is where we call the native code 
     String hello = invokeNativeFunction(); 
     Log.d("mytag", "vor ALERT"); 
     new AlertDialog.Builder(this).setMessage(hello).show(); 
     Log.d("mytag", "nach ALERT"); 
    } 
} 

Android.mk

LOCAL_PATH := $(call my-dir) 

include $(CLEAR_VARS) 

# Here we give our module name and source file(s) 
LOCAL_MODULE := ndkfoo 
LOCAL_SRC_FILES := ndkfoo.c 

include $(BUILD_SHARED_LIBRARY) 

ndkfoo.c:

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

JNIEXPORT jstring com_example_nativeapp_c_mainactivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) 
{ 
    return (*env)->NewStringUTF(env, "Hello from native code!"); 
} 

也會生成「.so」文件。 我已經使用了過去兩天的Google搜索,但無法解決。 希望你能幫助我。

回答

3
com_example_nativeapp_c_mainactivity_invokeNativeFunction 

應該是

com_example_nativeappc_MainActivity_invokeNativeFunction 

可替代地,使用顯式登記。

如果您還沒有,請務必閱讀JNI Tips頁面。

相關問題