![](/img/trans.png)
[英]Jython UnsatisfiedLinkError on native method invocation in shared library
[英]Error loading existing shared library (.so) on Android app (unsatisfiedlinkerror native method not found)
這是我的情況:
-)我有一個由ndk-build生成的共享庫libpsp.so。 該庫使用大約30個.c文件生成。
使用的Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_MODULE := psp
LOCAL_SRC_FILES := (My .c files)
include $(BUILD_SHARED_LIBRARY)
-)ndk-build自動將libpsp.so放在目錄/ libs / armeabi中
-)在我的Java代碼上,我有:
private native int calculateCoefficient(double w, double v_st_e_prev, double c_l);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
**//Loads successfully
System.loadLibrary("psp");**
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
TextView lv = (TextView)findViewById(R.id.textView);
**//Returns an error: unsatisfiedlinkerror native method not found
lv.setText(Integer.toString(calculateCoefficient(1,1,1)));**
}
-)用於構建共享庫的.c文件之一具有帶有簽名的calculateCoefficient方法:
sint32_t calculateCoefficient(double_t w, double_t v_st_e_prev, double_t *c_l);
因此,如果.so庫中存在computeCoefficient方法,為什么Android無法找到它? 我剛剛開始與NDK合作,很抱歉,如果我錯過了明顯的事情,但是我已經進行了一些研究,但我找不到答案。
UPDATE1:我無權訪問實際的代碼,該庫是由其他人生成的,我所擁有的只是帶有方法簽名的.h文件。 因此,我無法編輯用於創建該庫的.c文件。
您的簽名是錯誤的。 它必須是JNIEXPORT int JNICALL Java_classname_methodname(JNIENV * env,jobject obj,...)其中...是您實際要傳遞的參數。 指針無法傳遞,如果您想要一個數組,則使用jdoublearray,如果您只想通過引用傳遞double,則需要傳遞一個包含double的類,並在對象上設置該字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.