24

I have a problem when compiling my app, which is inspired from bitmap-plasma. I was calling

    if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
    LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
    return;
}

if (info.format != ANDROID_BITMAP_FORMAT_RGB_565) {
    LOGE("Bitmap format is not RGB_565 !");
    return;
}

if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
    LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
}

       /*****code here***********/
AndroidBitmap_unlockPixels(env, bitmap);

I have included android/bitmap.h in my source file. I am using android-ndk-r5b and sdk-9 on ubuntu 10.10.

I am getting an error

 /home/user5432/workspace/bitmapproj/obj/local/armeabi/objs-debug/mybitmap.o : In function Java_com_example_plasma_PlasmaView_renderPlasma
"undefined reference to AndroidBitmap_getInfo"
"undefined reference to AndroidBitmap_lockPixels"
"undefined reference to AndroidBitmap_unlockPixels"

The problem is with debug code. But what is the problem? Can anybody has an answer?

NoAIUser
  • 3,966
  • 6
  • 34
  • 52

3 Answers3

42

After a brief research I got to know that I need to add

`LOCAL_LDFLAGS += -ljnigraphics` 

in Android.mk file.

grebulon
  • 7,697
  • 5
  • 42
  • 66
NoAIUser
  • 3,966
  • 6
  • 34
  • 52
  • where did you get it from ? is there a list of such libraries that we can get in order to fix such problems with other unknown functions ? – android developer Jan 15 '13 at 22:54
  • Just look in android-ndk-*/platforms/android-*/arch-*/usr/lib and you will find wich libraries you can link to. – florentbuisson Feb 15 '13 at 10:22
  • Note that this line needs to come before any occurrences of include $(BUILD_SHARED_LIBRARY) in your Android.mk file. Almost makes me cry to think how long it took me to stumble upon that... – iforce2d Oct 16 '13 at 08:02
  • thanks. 007 to the rescue ! I was also using an example (gles2) and took the bitmap part from bitmap-plasma. From now on i've stored a mental note to also #include Android.mk files ! ;) – Larphoid Sep 08 '14 at 17:25
25

I have solved by adding the line "-ljnigraphics" in the file "CMakeList.txt":

"target_link_libraries( # Specifies the target library.
                       native-lib
                       -ljnigraphics

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )
Asaber
  • 384
  • 3
  • 8
7

If using Android Studio, you will need to add the library to the gradle.build file as well.

android {
    ...

    defaultConfig {
        ...

        ndk {
            ldLibs = ["android", "jnigraphics", <other ndk libraries you might need>]
            moduleName "webcam"
        }
    }
}

It seems that gradle ignores the Android.mk file for ndk dependencies. See undefined reference to `__android_log_print', particularly Stephen Kaiser's comment to the selected answer and BoredT's answer.

Community
  • 1
  • 1
SilverCorvus
  • 2,956
  • 1
  • 15
  • 26