wysaid / android-gpuimage-plus

Android Image & Camera Filters Based on OpenGL.
MIT License
1.81k stars 475 forks source link

How to import the library into an existing project? #172

Closed vxhviet closed 7 years ago

vxhviet commented 7 years ago

Sorry for bothering you @wysaid but I'm a still unfamiliar with the NDK so i don't know how to use your library in my current project. I've tried to read previous issues on this matter but they're all in Chinese which I don't understand.

I'm trying to figure out how to use this library in my project by importing the library as a module and this contains all the ffmpeg, opencv and facetracker bit which I don't need. I wonder if i can just delete the ffmpeg, faceTracker and opencv folder in the jni folder? Or I can just delete the whole jni folder and copy your prebuilt libCGE.so and libCGEExt.so into the libs folder?

Thank you so much for your time.

wysaid commented 7 years ago

Just delete the whole jni folder. And leave the libs/armeabi-v7a for use.

vxhviet commented 7 years ago

Thank you for your prompt response. I have:

java.lang.UnsatisfiedLinkError: dlopen failed: library "libffmpeg.so" not found
                  at java.lang.Runtime.loadLibrary(Runtime.java:372)
                  at java.lang.System.loadLibrary(System.java:1076)
                  at org.wysaid.nativePort.NativeLibraryLoader.load(NativeLibraryLoader.java:19)
                  at org.wysaid.nativePort.CGEImageHandler.<clinit>(CGEImageHandler.java:16)
                  at org.wysaid.view.ImageGLSurfaceView.onSurfaceCreated(ImageGLSurfaceView.java:246)
                  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1503)
                  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

is ffmpeg still involved in some way?

wysaid commented 7 years ago

If you don't want any feature of ffmpeg(such as video recording) You should compile the jni part just use

cd /path/of/jni export NDK=/path/of/your/ndk $NDK/ndk-build

vxhviet commented 7 years ago

Sorry, I think I need your help again. After trying to compile with your suggestion I got this error:

$ /media/sf_VirtualBoxSharedFolder/android-ndk-r15b-linux-x86_64/android-ndk-r15b/ndk-build 
Android NDK: android-9 is unsupported. Using minimum supported version android-14.    
Android NDK: WARNING: APP_PLATFORM android-14 is higher than android:minSdkVersion 1 in /media/sf_VirtualBoxSharedFolder/library/src/main/AndroidManifest.xml. NDK binaries will *not* be comptible with devices older than android-14. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.    
/media/sf_VirtualBoxSharedFolder/android-ndk-r15b-linux-x86_64/android-ndk-r15b/build/core/build-binary.mk:688: Android NDK: Module CGEExt depends on undefined modules: ffmpeg    
/media/sf_VirtualBoxSharedFolder/android-ndk-r15b-linux-x86_64/android-ndk-r15b/build/core/build-binary.mk:701: *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)    .  Stop

So I fix this by putting the below into the library's AndroidManifest.xm:

<uses-sdk
    android:minSdkVersion="18"
    android:targetSdkVersion="22"/>

and got stuck with this error:

/media/sf_VirtualBoxSharedFolder/android-ndk-r15b-linux-x86_64/android-ndk-r15b/ndk-build 
Android NDK: android-9 is unsupported. Using minimum supported version android-14.    
/media/sf_VirtualBoxSharedFolder/android-ndk-r15b-linux-x86_64/android-ndk-r15b/build/core/build-binary.mk:688: Android NDK: Module CGEExt depends on undefined modules: ffmpeg    
/media/sf_VirtualBoxSharedFolder/android-ndk-r15b-linux-x86_64/android-ndk-r15b/build/core/build-binary.mk:701: *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)    .  Stop.
wysaid commented 7 years ago

Change this line to APP_PLATFORM := android-14

vxhviet commented 7 years ago

The app platform version is a non issue as if I read correctly, the NDK automatically using the minimum android-14 for compilation.

What I got stuck is the Android NDK: Module CGEExt depends on undefined modules: ffmpeg so i guess there must be some change to the Android.mk.

wysaid commented 7 years ago

Please try again with the latest code.

vxhviet commented 7 years ago

I've compiled successfully and imported it into my project. After some initial it seems to work fine.

Thank you so much for your time.

vxhviet commented 7 years ago

Hi I just want to add a little instruction for Window users as it can be a little it un-straightforward for the building process. After some failing attempt to build with cygwin, I've come to the Linux via Virtual Box route which could be tedious and time consuming. When in fact we can invoking the ndk-build.cmd the same way in Window, the trick is to remember to include that little .cmd file extension, so:

cd your_path_to\android-gpuimage-plus-master\library\src\main\jni
your_path_to_ndk\ndk-bundle\ndk-build.cmd
wysaid commented 7 years ago

Thanks, can you make a PR for that?

ChuXo commented 7 years ago

I´ve checked out the latest version but this issue seems to persist on Windows 10

What am I missing?

vxhviet commented 7 years ago

I've compiled mine on Window 10, no issue. Make sure there's no space in the path to either the jni or ndk. Space in Window path sucks.

ChuXo commented 7 years ago

There are no spaces in any path.

I've fixed any Application.mk with the correct platform (APP_PLATFORM := android-14) and fixed Android.mk in jni/FaceTracker/jni/ (LOCAL_SHARED_LIBRARIES := CGE instead of opencv CGE) like in source/source.mk seems to fix the problem: "Module FaceTracker depends on undefined modules: opencv" but I still get this Error:

[armeabi] Prebuilt       : libffmpeg.so <= jni/ffmpeg/armeabi/
[armeabi] SharedLibrary  : libCGE.so
[armeabi] Install        : libCGE.so => libs/armeabi/libCGE.so
[armeabi] Compile++ thumb: CGEExt <= cgeNativeLibrary.cpp
error: error opening 'C:/Users/MrX/Documents/MEGA/Projects/workspace/appbuilderprojects/AugmentedShaker/gpuimageplus/src/main/obj/local/armeabi/objs/CGEExt/C_/Users/MrX/Documents/MEGA/Projects/workspace/appbuilderprojects/AugmentedShaker/gpuimageplus/src/main/jni/source/__/interface/cgeNativeLibrary.o.d': No such file or directory
1 error generated.
make: *** [C:/Users/MrX/Documents/MEGA/Projects/workspace/appbuilderprojects/AugmentedShaker/gpuimageplus/src/main/obj/local/armeabi/objs/CGEExt/C_/Users/MrX/Documents/MEGA/Projects/workspace/appbuilderprojects/AugmentedShaker/gpuimageplus/src/main/jni/source/__/interface/cgeNativeLibrary.o] Error 1

Compiled with MINGW64 "bash buildJNI" on Windows 10 Any suggestions to fix this issue?

vxhviet commented 7 years ago

It can be compiled directly using Windows command prompt. Just follow my instruction, it literally only 2 lines.

If you insist on using the Linux file system for some reason then the simplest way is building in Linux, either via virtual machine or dual boot.

ChuXo commented 7 years ago

Same Error with Windows command prompt. Would be fine to get that working on Windows... but for now I'll try on linux.

ChuXo commented 7 years ago

Tried the current Version with Ubuntu 11.10 and android-ndk-r15c gives the same Error:

make: *** [/home/ubuntu/Desktop/obj/local/armeabi/objs/CGE//home/ubuntu/Desktop/jni/cge/common/cgeCommonDefine.o] Error 127

and an additional Error:

[armeabi] Compile++ thumb: CGE <= cgeCommonDefine.cpp make: /home/ubuntu/Documents/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86/bin/clang++: Command not found

Any solution on this? Sorry but I'm really new to compiling native libs.

And if I do not change the following line in facetracker/jni/Android.mk:

old: LOCAL_SHARED_LIBRARIES := opencv CGE

new: LOCAL_SHARED_LIBRARIES := CGE

There is still the Error: android-ndk-r15c/build/core/build-binary.mk:688: Android NDK: Module FaceTracker depends on undefined modules: opencv

I think this should get fixed, or i'm wrong? Thank you Guys in advance.

vxhviet commented 7 years ago

If you just want the cge module (no ffmpeg, face recognition) I can build it for you.

wysaid commented 7 years ago

@ChuXo Do you cd to the jni folder?

ChuXo commented 7 years ago

Yes I do. Tried again only the cge module, tried with ndk version r13b, setting up the ndk correctly, all with no success, same error. I'm at my wit's end. I only want to recompile using a different custom filter. I can not figure out the problem. It triggers successfully the ndk build but it failed every times with the errors above.

Would be awesome if you could provide me a link to an uploaded compiled version with this custom filter as filter 1 (in jni/source/customFilter_N.cpp):

static CGEConstString s_fsh1 = CGE_SHADER_STRING_PRECISION_M
(
 varying vec2 textureCoordinate;
 uniform sampler2D inputImageTexture;

 void main()
{
   lowp vec3 tc = vec3(1.0, 0.0, 0.0);
   lowp vec3 pixcol = texture2D(inputImageTexture, textureCoordinate).rgb;
   lowp vec3 colors[3];
   colors[0] = vec3(0.0, 0.0, 1.0);
   colors[1] = vec3(1.0, 1.0, 0.0);
   colors[2] = vec3(1.0, 0.0, 0.0);
   mediump float lum = (pixcol.r + pixcol.g + pixcol.b) / 3.0;
   int ix = (lum < 0.5)? 0:1;
   tc = mix(colors[ix], colors[ix + 1], (lum - float(ix) * 0.5) / 0.5);

   gl_FragColor = vec4(tc, 1.0);
}
 );

bool CustomFilter_1::init()
{
    return m_program.initWithShaderStrings(g_vshDefaultWithoutTexCoord, s_fsh1);
}
vxhviet commented 7 years ago

It would be a while before I reach my office.

Would you please try re download the library again, try to build it as the instructions without including the custom filter to see if the error still persist?

vxhviet commented 7 years ago

Never mind, here you go: https://github.com/vxhviet/public_file_share/blob/master/libs.zip?raw=true

ChuXo commented 7 years ago

Really thank you. After hours of reasearch and endless attempts (using different ubuntu versions and more) I could successfully compile it back again on Windows with MINGW64. I absolutly dont know why! The only thing I changed was to place the jni folder outside the project.

AanalShah commented 5 years ago

Never mind, here you go: https://github.com/vxhviet/public_file_share/blob/master/libs.zip?raw=true

you are awesome

AanalShah commented 5 years ago

Never mind, here you go: https://github.com/vxhviet/public_file_share/blob/master/libs.zip?raw=true

hello please help me to comiple .so file for architecture x86_64