Android StudioでC言語のライブラリをインポートしたく、サンプルを作って試していますが、コンパイル時にUnsatisfiedLinkErrorが出ます。
java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String com.example.sampleApp.MainActivity.stringFromJNI() (tried Java_com_example_sampleApp_MainActivity_stringFromJNI and Java_com_example_sampleApp_MainActivity_stringFromJNI__)
MainActivity.javaの中身は以下のように書きました。
static { System.loadLibrary("hello"); } public native String stringFromJNI(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = new TextView(this); tv.setText(stringFromJNI()); setContentView(tv); }
Android.mkは以下のように書きました。
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello LOCAL_SRC_FILES := hello-jni.c include $(BUILD_SHARED_LIBRARY)
C言語を書いたhello-jni.cはこんな感じです。
jstring Java_com_example_sampleApp_MainActivity_stringFromJNI( JNIEnv* env, jobject thiz ) { #if defined(__arm__) #if defined(__ARM_ARCH_7A__) #if defined(__ARM_NEON__) #if defined(__ARM_PCS_VFP) #define ABI "armeabi-v7a/NEON (hard-float)" #else #define ABI "armeabi-v7a/NEON" #endif #else #if defined(__ARM_PCS_VFP) #define ABI "armeabi-v7a (hard-float)" #else #define ABI "armeabi-v7a" #endif #endif #else #define ABI "armeabi" #endif #elif defined(__i386__) #define ABI "x86" #elif defined(__x86_64__) #define ABI "x86_64" #elif defined(__mips64) /* mips64el-* toolchain defines __mips__ too */ #define ABI "mips64" #elif defined(__mips__) #define ABI "mips" #elif defined(__aarch64__) #define ABI "arm64-v8a" #else #define ABI "unknown" #endif return (*env)->NewStringUTF(env, "Hello from JNI ! Compiled with ABI " ABI "."); }
どのようにすれば、Android StudioでC言語のライブラリを使えるようになるでしょうか?
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/05/11 05:46