[General Questions and Answers] IET_DEMO:
Hi, I am trying to recompile the screencap executable to tweak the code for my needs.

Unfortunetaly, I get some compilation error when i compile the code

I am compiling with ndk-build from android-ndk-r9

Here is the log:

lafd@lafd-OptiPlex-3010:~/Development/Hello_Screencap-2$ /home/lafd/Development/android-ndk-r9/ndk-build

Android NDK: WARNING: APP_PLATFORM android-18 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml

Compile++ thumb : Hello-Sreencap-2 <= Hello_Screencap-2.cpp

Executable : Hello-Sreencap-2

/home/lafd/Development/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/Hello-Sreencap-2/Hello_Screencap-2.o: in function main:jni/Hello_Screencap-2.cpp:36: error: undefined reference to 'android::ScreenshotClient::ScreenshotClient()'

/home/lafd/Development/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/Hello-Sreencap-2/Hello_Screencap-2.o: in function main:jni/Hello_Screencap-2.cpp:41: error: undefined reference to 'android::SurfaceComposerClient::getBuiltInDisplay(int)'

/home/lafd/Development/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/Hello-Sreencap-2/Hello_Screencap-2.o: in function main:jni/Hello_Screencap-2.cpp:41: error: undefined reference to 'android::ScreenshotClient::update(android::sp<android::IBinder> const&)'

/home/lafd/Development/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/Hello-Sreencap-2/Hello_Screencap-2.o: in function main:jni/utils/StrongPointer.h:149: error: undefined reference to 'android::RefBase::decStrong(void const*) const'

/home/lafd/Development/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/Hello-Sreencap-2/Hello_Screencap-2.o: in function main:jni/Hello_Screencap-2.cpp:44: error: undefined reference to 'android::ScreenshotClient::getWidth() const'

/home/lafd/Development/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/Hello-Sreencap-2/Hello_Screencap-2.o: in function main:jni/Hello_Screencap-2.cpp:45: error: undefined reference to 'android::ScreenshotClient::getHeight() const'

/home/lafd/Development/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/Hello-Sreencap-2/Hello_Screencap-2.o: in function main:jni/Hello_Screencap-2.cpp:46: error: undefined reference to 'android::ScreenshotClient::getFormat() const'

/home/lafd/Development/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/Hello-Sreencap-2/Hello_Screencap-2.o: in function main:jni/Hello_Screencap-2.cpp:47: error: undefined reference to 'android::ScreenshotClient::getSize() const'

/home/lafd/Development/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/Hello-Sreencap-2/Hello_Screencap-2.o: in function main:jni/Hello_Screencap-2.cpp:54: error: undefined reference to 'android::ScreenshotClient::~ScreenshotClient()'

collect2: ld returned 1 exit status

make: *** [obj/local/armeabi/Hello-Sreencap-2] Error 1

Well it seems that every calls that needs the android namespace can't be referenced.

But, SurfaceComposerClient is included which defines the android namespace

Here is the c++ code snippet:

#include <utils/RefBase.h>

#include <binder/IBinder.h>

#include <binder/MemoryHeapBase.h>

#include <gui/ISurfaceComposer.h>

#include <gui/SurfaceComposerClient.h>

#include <dlfcn.h>

#include <errno.h>

#include <unistd.h>

#include <stdio.h>

#include <fcntl.h>

#include <linux/fb.h>

#include <sys/ioctl.h>

#include <sys/mman.h>

using namespace android;

static void do_save(const char *filename, const void *buf, size_t size)

{

int out = open(filename, O_RDWR|O_CREAT, 0666);

int len = write(out, buf, size);

printf("Wrote %d bytes to out.\n", len);

close(out);

}

int main (int ac, char **av)

{

ScreenshotClient ssc;

const void *pixels;

size_t size;

int buffer_index;

if(ssc.update( android::SurfaceComposerClient::getBuiltInDisplay( android::ISurfaceComposer::eDisplayIdMain)) != NO_ERROR )

{

//printf("Captured: w=%d, h=%d, format=%d\n");

ssc.getWidth();

ssc.getHeight();

ssc.getFormat();

size = ssc.getSize();

do_save(av[1], pixels, size);

}

else

{

printf(" screen shot client Captured Failed");

}

return 0;

}

And The Android.mk

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SHARED_LIBRARIES := \

libcutils \

libutils \

libbinder \

libskia \

libui \

libgui

LOCAL_SRC_FILES:= \

Hello_Screencap-2.cpp

LOCAL_MODULE:= Hello-Sreencap-2

LOCAL_MODULE_TAGS := optional

LOCAL_C_INCLUDES += \

external/skia/include/core \

external/skia/include/effects \

external/skia/include/images \

external/skia/src/ports \

external/skia/src/core \

external/skia/include/utils \

include $(BUILD_EXECUTABLE)

When I compile the screencap from cyanogenmod, the compilation works but when the executable runs it shows an error about CANNOT LINK EXECUTABLE cannot locate symbol Zn7androidscreenshotclient...

If you need more don't hesitate