Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get my .so libraries copied to the Android device?

To sum it up in one line: Not all of my libs/armeabi/*.so files are copied to the device when I run my application. I'll try to explain.

Directory Structure

I'm trying to get ffmpeg onto Android and therefore have the following structure for the NDK:

jni
├── Android.mk
├── bambuser_ffmpeg
│   ├── Android.mk
│   ├── libavcodec.so
│   ├── libavcore.so
│   ├── libavdevice.so
│   ├── libavfilter.so
│   ├── libavformat.so
│   ├── libavutil.so
│   └── libswscale.so
└── video
    ├── Android.mk
    ├── at_ac_univie_gameclient_video_VideoGLSurfaceView.c
    ├── at_ac_univie_gameclient_video_VideoGLSurfaceView.h
    └── at_ac_univie_gameclient_video_VideoGLSurfaceView_GLRenderer.h

Android.mk files

The Android.mk file within bambuser_ffmpeg says:

include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavcodec
LOCAL_SRC_FILES := libavcodec.so
include $(PREBUILT_SHARED_LIBRARY)
# and so on, for all of the above .so files

The second `Android.mk file has the following:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := ffmpeg
LOCAL_STATIC_LIBRARIES := bambuser-libavcodec bambuser-libavcore bambuser-libavdevice bambuser-libavfilter bambuser-libavformat bambuser-libavutil bambuser-libswscale
LOCAL_SRC_FILES := at_ac_univie_gameclient_video_VideoGLSurfaceView.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../bambuser_ffmpeg/
LOCAL_LDLIBS    := -L$(LOCAL_PATH)/../bambuser_ffmpeg -lavcodec -lavcore -lavdevice -lavfilter -lavformat -lavutil -lswscale -llog -lz -lGLESv1_CM

include $(BUILD_SHARED_LIBRARY)

Output

So, when I run ./ndk-build, I receive this output. Looks fine, does it?

Prebuilt       : libavcodec.so <= jni/bambuser_ffmpeg/
Install        : libavcodec.so => libs/armeabi/libavcodec.so
Prebuilt       : libavcore.so <= jni/bambuser_ffmpeg/
Install        : libavcore.so => libs/armeabi/libavcore.so
Prebuilt       : libavdevice.so <= jni/bambuser_ffmpeg/
Install        : libavdevice.so => libs/armeabi/libavdevice.so
Prebuilt       : libavfilter.so <= jni/bambuser_ffmpeg/
Install        : libavfilter.so => libs/armeabi/libavfilter.so
Prebuilt       : libavformat.so <= jni/bambuser_ffmpeg/
Install        : libavformat.so => libs/armeabi/libavformat.so
Prebuilt       : libavutil.so <= jni/bambuser_ffmpeg/
Install        : libavutil.so => libs/armeabi/libavutil.so
Prebuilt       : libswscale.so <= jni/bambuser_ffmpeg/
Install        : libswscale.so => libs/armeabi/libswscale.so
Install        : libffmpeg.so => libs/armeabi/libffmpeg.so

Problem

When I run my Android application, it will try to load libffmpeg.so. Of course, my local libs directory contains all libraries needed, as they were built/copied before:

libs
└── armeabi
    ├── libavcodec.so
    ├── libavcore.so
    ├── libavdevice.so
    ├── libavfilter.so
    ├── libavformat.so
    ├── libavutil.so
    ├── libffmpeg.so
    └── libswscale.so

However, on the device itself, there's only my libffmpeg.so file. It resides in at.ac.univie.gameclient/lib/libffmpeg.so and was copied there automatically. Where are the other .so files and how do I get them to the device?

Also, just manually copying them there is not my desired solution, obviously.

like image 781
slhck Avatar asked May 13 '11 15:05

slhck


1 Answers

Are you absolutely sure that all your libraries are there before uploading the app. Yes i saw you wrote that they are there but when you build the jni project it deletes all your existing files in libs dir. So refresh before you upload it just to double check.

like image 83
Mojo Risin Avatar answered Nov 07 '22 13:11

Mojo Risin