Android Studio | CPP file errors error: undefined reference to 'AndroidBitmap_unlockPixels' In bitmap library

♀尐吖头ヾ 提交于 2021-02-08 07:33:32

问题


I'm trying to use AndroidJniBitmapOperations library. But I'm a Junior Dev, with no knowledge in the NDK, JNI world.

I succeed to resolve a few errors like 'UnsatisfiedLinkError', but Now I'm getting a new one when I trying to build:

error: undefined reference to 'AndroidBitmap_unlockPixels'

Also I get a few errors inside the CPP file:

1."Incorrect type for parameter 'prarmeterName', which should have type 'jint'.

2."Add extern 'C'"

But I don't sure if the last 2 are important.

Help me to update this library, because its important and talked in SO several times, like: here.

The link for the library it self: https://github.com/AndroidDeveloperLB/AndroidJniBitmapOperations

All what I have done until now is: https://github.com/LiorA1/MyRevApp


回答1:


You need to link the library that provides that API. In https://github.com/LiorA1/MyRevApp/blob/master/app/src/main/cpp/CMakeLists.txt, copy the code that you have for the logging library like so:

find_library(log-lib log)
find_library(jnigraphics-lib jnigraphics)
target_link_libraries(JniBitmapOperationsLibrary ${log-lib} ${jnigraphics-lib})

Although I think the template code is actually overly complicated here and you can simplify to just:

target_link_libraries(JniBitmapOperationsLibrary -llog -ljnigraphics)

Untested though.

As for how you can figure out which library you need to use for each Android API, I find the easiest way is to search for it on cs.android.com. For this one, I searched for AndroidBitmap_unlockPixels file:.*\.map\.txt (every NDK API is enumerated in a *.map.txt file). You can also use this page, but the code search is authoritative and makes it easier to look up an individual function rather than just "bitmap", in this case.



来源:https://stackoverflow.com/questions/61807285/android-studio-cpp-file-errors-error-undefined-reference-to-androidbitmap-un

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!