3

Android Platform has an utility class that's used to take android screenshot . I copied "ScreenCap.cpp" in to JNI folder then build via NDK but failed. The NDK compiler didn't find needed libraries:

#include <binder/IMemory.h>
#include <gui/SurfaceComposerClient.h>

#include <SkImageEncoder.h>
#include <SkBitmap.h>
#include <SkData.h>
#include <SkStream.h>

Here is error log:

jni/ScreenCap.cpp:28:28: fatal error: SkImageEncoder.h: No such file or directory

compilation terminated.

Please tell me how to fix this.

BTW, Is there any solution to capture entire android screen programmatically? I need to capture it at least 10 times per second.

Thanks.

Nguyen Minh Binh
  • 23,891
  • 30
  • 115
  • 165

2 Answers2

1

This question is quite old but I'll try to help just in case.

The problem is that SkImageEncoder.h is not part from NDK but from system's libskia library (not available in the NDK) and, then, should be build together with full system's build process.

If you want this application to run in single device, e.g. you personal device, you should be able to create a working binary by modifying your Android.mk file:

include $(CLEAR_VARS)
LOCAL_MODULE := system_libskia
LOCAL_SRC_FILES := PATH_TO_LIBSKIA/libskia.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_C_INCLUDES := PATH_TO_SKIA_INCLUDE_FOLDER

LOCAL_SHARED_LIBRARIES := system_libskia

You can obtain your device's libskia.so by using running:

adb pull /system/lib/libskia.so

Another possible, but ugly, workaround would be loading libskia.so through dlopen and, then, read all needed symbols from it. This would work for any device as long as symbol's signature remains the same.

Hope this helps.

jcm
  • 2,568
  • 14
  • 18
0

You forgot to include your SkImageEncoder.h into your Local_C_Include. Add this line into your Android.mk file

LOCAL_C_INCLUDES := PATH_TO_SKImageEncoder_HEADER
Infinity
  • 3,695
  • 2
  • 27
  • 35
  • I did it. But it still failed. Is there any tutorial how to build custom native library on JNI? – Nguyen Minh Binh Sep 26 '12 at 09:04
  • Post the error and I will try to help you further. I learned lots of NDK stuffs through googling and the samples they provided inside the NDK package. Yes, it's a big headache when you first learning it haha – Infinity Sep 26 '12 at 09:09
  • I share the JNI folder at my dropbox at https://dl.dropbox.com/u/15261504/jni.zip. I have pull necessary libraries but I can not build it. Please take a look. – Nguyen Minh Binh Sep 26 '12 at 10:16