Discussion:
Android Studio project with library module using prebuilt so
AppDeveloper
2018-01-02 02:13:34 UTC
Permalink
My android project was built using eclipse, now i want to change to use
Android Studio 3.0.1.
The new android studio project basically okey and can run on the phone, but
when the source code use the native function, it will crash.

The project stucture is like this:

Project
-app
-MyLibray (Library module) (Which will use the C++ source code
with ffmpeg library)

On the Library module, it will use NDK to build some C++ source code
(Render.cpp) to use ffmpeg library. And the prebuilt is using ndk-build
script, and the compile is fine, but when the source code on MyLibrary call
the C++ function, it crash with:
java.lang.UnsatisfiedLinkError:
dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/
...... /system/lib]]] couldn't find "libRender.so"

I have tried to solve it for 2 days, but still has no solution...

The build.gradle on the library module is like that

ndk {
moduleName = "Render"
abiFilters "armeabi", "armeabi-v7a"
}

externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}

The Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := avformat
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavformat.a
LOCAL_SRC_FILES := lib/libavformat.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avcodec
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavcodec.a
LOCAL_SRC_FILES := lib/libavcodec.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avdevice
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavdevice.a
LOCAL_SRC_FILES := lib/libavdevice.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avfilter
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavfilter.a
LOCAL_SRC_FILES := lib/libavfilter.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avutil
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavutil.a
LOCAL_SRC_FILES := lib/libavutil.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := swscale
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libswscale.a
LOCAL_SRC_FILES := lib/libswscale.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := swresample
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libswresample.a
LOCAL_SRC_FILES := lib/libswresample.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := Render
LOCAL_SRC_FILES := Render.cpp
LOCAL_STATIC_LIBRARIES := avformat avcodec avdevice avfilter avutil swscale
swresample
LOCAL_LDLIBS := -lm -lz -llog -lGLESv1_CM
LOCAL_ALLOW_UNDEFINED_SYMBOLS := false
include $(BUILD_SHARED_LIBRARY)

The java file to use it

public class NativeInterface {
// Native functions
static {
System.loadLibrary("Render");
}

public static native int nativeVersion();
}

When i call nativeVersion on MyLibrary, then it crash with
java.lang.UnsatisfiedLinkError, But it is okey on ecsplise project.

When i unzip the aar file output on the library module, it has

aar\MyLibrary-debug\jni\armeabi\libRender.so
aar\MyLibrary-debug\jni\armeabi-v7a\libRender.so
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/6d8ee0a1-43a2-43ad-99ec-0c8235987403%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alex Cohn
2018-01-07 11:26:25 UTC
Permalink
First of all, check that if you unzip the APK file, you have libRender.so
(Android Studio provides a handy menu "Analyze APK
" under Build).
The question is how you defined dependency your app on MyLibrary in
*build.gradle*.

BR,
Alex
Post by AppDeveloper
My android project was built using eclipse, now i want to change to use
Android Studio 3.0.1.
The new android studio project basically okey and can run on the phone,
but when the source code use the native function, it will crash.
Project
-app
-MyLibray (Library module) (Which will use the C++ source code
with ffmpeg library)
On the Library module, it will use NDK to build some C++ source code
(Render.cpp) to use ffmpeg library. And the prebuilt is using ndk-build
script, and the compile is fine, but when the source code on MyLibrary call
dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/
...... /system/lib]]] couldn't find "libRender.so"
I have tried to solve it for 2 days, but still has no solution...
The build.gradle on the library module is like that
ndk {
moduleName = "Render"
abiFilters "armeabi", "armeabi-v7a"
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
The Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := avformat
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavformat.a
LOCAL_SRC_FILES := lib/libavformat.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avcodec
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavcodec.a
LOCAL_SRC_FILES := lib/libavcodec.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avdevice
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavdevice.a
LOCAL_SRC_FILES := lib/libavdevice.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avfilter
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavfilter.a
LOCAL_SRC_FILES := lib/libavfilter.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avutil
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libavutil.a
LOCAL_SRC_FILES := lib/libavutil.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := swscale
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libswscale.a
LOCAL_SRC_FILES := lib/libswscale.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := swresample
#LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libswresample.a
LOCAL_SRC_FILES := lib/libswresample.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := Render
LOCAL_SRC_FILES := Render.cpp
LOCAL_STATIC_LIBRARIES := avformat avcodec avdevice avfilter avutil
swscale swresample
LOCAL_LDLIBS := -lm -lz -llog -lGLESv1_CM
LOCAL_ALLOW_UNDEFINED_SYMBOLS := false
include $(BUILD_SHARED_LIBRARY)
The java file to use it
public class NativeInterface {
// Native functions
static {
System.loadLibrary("Render");
}
public static native int nativeVersion();
}
When i call nativeVersion on MyLibrary, then it crash with
java.lang.UnsatisfiedLinkError, But it is okey on ecsplise project.
When i unzip the aar file output on the library module, it has
aar\MyLibrary-debug\jni\armeabi\libRender.so
aar\MyLibrary-debug\jni\armeabi-v7a\libRender.so
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/193e3292-225e-4195-a2fc-4a1a54c11319%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...