我很清楚关于这个主题的无数问题,但我是Android开发的新手,我无法找到任何与我的问题如此接近的问题来解决我的问题。 回顾一下:
.a
文件手动添加到我的项目中。我使用了原生的ndk-build
编译器。这是我的Android.mk
文件:
LOCAL_PATH := $(call my-dir)
### include libos as a prebuilt lib ###
include $(CLEAR_VARS)
LOCAL_MODULE := lib_OS
LOCAL_MODULE_FILENAME := lib_OS_static
LOCAL_SRC_FILES := libs/armeabi-v7a/lib_OS.a
include $(PREBUILT_STATIC_LIBRARY)
### build your ndk lib ###
include $(CLEAR_VARS)
LOCAL_MODULE := hello
LOCAL_SRC_FILES := main.cpp
LOCAL_CPPFLAGS := -D__ANDROID__
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
/home/alecive/Dev/src/lib_OS/include \
/home/alecive/Dev/build-arm/generated_include \
# /home/alecive/Dev/android-ndk-r10e/platforms/android-21/arch-x86_64/usr/include
LOCAL_STATIC_LIBRARIES := lib_OS
LOCAL_STATIC_LIBRARIES += stlport
include $(BUILD_STATIC_LIBRARY)
这是我的Application.mk
APP_ABI := armeabi-v7a
APP_STL := stlport_static
APP_MODULES := lib_OS
APP_MODULES += hello
应用程序编译正确,一切正常。在我称之为本机功能的那一刻,通过向我扔下以下内容,它变得疯狂:
Process: com.alecive.yarpdroid, PID: 9811
java.lang.UnsatisfiedLinkError: Native method not found: com.alecive.yarpdroid.MainActivity.hello:()Ljava/lang/String;
据我所知,人们常常会将要放入C
代码的函数名称弄乱,所以这里是我MainActivity.java
的片段:
package com.alecive.ydroid;
...
static{
System.loadLibrary("hello");
}
public native String hello();
以下是名为.h
的{{1}}:
com_alecive_ydroid_MainActivity.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
#include <string.h>
/* Header for class com_alecive_ydroid_MainActivity_hello */
extern "C" {
JNIEXPORT jstring JNICALL
Java_com_alecive_ydroid_MainActivity_hello(JNIEnv *env, jobject obj);
}
:
main.cpp
由于我真的不明白命名这个函数的正确方法是什么,我认为它们没问题,但我真的不知道。在此先感谢您的帮助!