It was my mistake, I refactored the class that called the native methods and moved it into a different package, that is why the method could not be found. After I put it in the original package, everything worked again.
On Wednesday, May 28, 2014 4:03:54 PM UTC-7, Carlos Vinueza wrote: > > Hello, > > I have an Android NDK project which builds and runs fine with Android.mk > files, it consists of my native code (one C file) built as a shared > library, this code has a dependency to a third party static library (.a > file). > > Right now I am trying to migrate it to Gradle. My current configuration is > as follows: > > *Static library Android.mk that is under the /static_libs folder* > > > > LOCAL_PATH := $(call my-dir) > > include $(CLEAR_VARS) > > LOCAL_MODULE := opus > LOCAL_SRC_FILES := lib/libopus.a > LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include > > include $(PREBUILT_STATIC_LIBRARY) > > *Main module Android.mk file: (under the usual jni/ folder)* > > > > LOCAL_PATH := $(call my-dir) > $(call import-add-path,$(LOCAL_PATH)/../static_libs) > > include $(CLEAR_VARS) > > LOCAL_MODULE:=opus_jni > > LOCAL_SRC_FILES:= opus_jni.c > > LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -ldl > LOCAL_WHOLE_STATIC_LIBRARIES := opus > include $(BUILD_SHARED_LIBRARY) > > $(call import-module,opus) > > When I run ndk-build on the main module the only output is one file > *libopus_jni.so* that is the only one used to build the final APK. > > Now on Gradle, the only thing I want to do for now is create an APK with > this same prebuilt shared library and the same code, so I copied my > generated library into *jniLibs/* folder *(I know as of 0.7 Gradle > already supports JNI libraries if the files are put here)*. The project > builds and the final APK does contain the .so file inside the libs/ > folder. *(I verified by unzipping the generated APK)* > > The problem is that when I try to use any of the native methods I get the > following error: > > > > 05-28 14:57:53.393 3370-3370/com.opusgradle.app D/OB-OpusCodec﹕ > testPcmToOpus() > 05-28 14:57:53.393 3370-3370/com.opusgradle.app D/dalvikvm﹕ Trying to > load lib /data/app-lib/com.opusgradle.app-2/libopus_jni.so 0x42630b18 > 05-28 14:57:53.393 3370-3370/com.opusgradle.app D/dalvikvm﹕ Added > shared lib /data/app-lib/com.opusgradle.app-2/libopus_jni.so 0x42630b18 > 05-28 14:57:53.393 3370-3370/com.opusgradle.app D/OB-OpusCodec﹕ Trying > to initialize... > 05-28 14:57:53.393 3370-3370/com.opusgradle.app W/dalvikvm﹕ No > implementation found for native > Lcom/opusgradle/app/OpusCodec;.initOpusEncoder:(II)V > 05-28 14:57:53.393 3370-3370/com.opusgradle.app D/AndroidRuntime﹕ > Shutting down VM > 05-28 14:57:53.393 3370-3370/com.opusgradle.app W/dalvikvm﹕ > threadid=1: thread exiting with uncaught exception (group=0x415e0ba8) > 05-28 14:57:53.393 3370-3370/com.opusgradle.app E/AndroidRuntime﹕ > FATAL EXCEPTION: main > Process: com.opusgradle.app, PID: 3370 > java.lang.UnsatisfiedLinkError: Native method not found: > com.opusgradle.app.OpusCodec.initOpusEncoder:(II)V > at com.opusgradle.app.OpusCodec.initOpusEncoder(Native Method) > at com.opusgradle.app.OpusCodec.(OpusCodec.java:23) > at > com.opusgradle.app.MainActivity.testPcmToOpus(MainActivity.java:78) > at > com.opusgradle.app.MainActivity.access$000(MainActivity.java:22) > at com.opusgradle.<span class="pln" > > ... -- You received this message because you are subscribed to the Google Groups "adt-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
