我有一个在 android ndk 中编译的简单本机函数。在 IntentActivity 中调用函数没问题,但是当我使用 IntentService 时,无法调用该函数。这是我的代码:
public class PlayerService extends IntentService {
public PlayerService() {
super("myservice");
}
@Override
protected void onHandleIntent(Intent workIntent) {
createEngine();
}
public static native void createEngine();
static {
System.loadLibrary("native-audio-jni");
}
}
我得到了错误;
10-22 09:46:01.709: E/AndroidRuntime(5445): FATAL EXCEPTION: IntentService[myservice]
10-22 09:46:01.709: E/AndroidRuntime(5445): java.lang.UnsatisfiedLinkError: Native method not found: com.xxxxxx.playerdemo.PlayerService.createEngine:()V
10-22 09:46:01.709: E/AndroidRuntime(5445): at com.ngochoang.playerdemo.PlayerService.createEngine(Native Method)
10-22 09:46:01.709: E/AndroidRuntime(5445): at com.ngochoang.playerdemo.PlayerService.onHandleIntent(PlayerService.java:21)
10-22 09:46:01.709: E/AndroidRuntime(5445): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
10-22 09:46:01.709: E/AndroidRuntime(5445): at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 09:46:01.709: E/AndroidRuntime(5445): at android.os.Looper.loop(Looper.java:137)
10-22 09:46:01.709: E/AndroidRuntime(5445): at android.os.HandlerThread.run(HandlerThread.java:60)
谢谢