Type 'AndroidBitmapInfo' could not be resolved - android

I'm a newbie of Android NDK. I want to try create fast blur effect to bitmap and I found a NDK solution from here: Fast Bitmap Blur For Android SDK answered by #zeh
after I did my configuration, I am not able to run the project and It said "Type 'AndroidBitmapInfo' could not be resolved" in the *.c file.
Could you guys tell me how to fix this problem?
Here is my Android.mk
LOCAL_PATH := $(call my-dir)
# Create BitmapUtils library
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog -ljnigraphics -landroid
LOCAL_MODULE := bitmaputils
LOCAL_SRC_FILES := bitmaputils.c
LOCAL_CFLAGS = -ffast-math -O3 -funroll-loops
include $(BUILD_SHARED_LIBRARY)
Thank you

Just in case: have you correctly included the bitmap header?
#include <android/bitmap.h>

Add the following line to your Application.mk
APP_PLATFORM := android-8
In case you don't use Application.mk, run ndk-build as follows:
ndk-build APP_PLATFORM=android-8

according to ndk samples\bitmap-plasma\jni, you'd better double check mk file, and header file.
Application.mk
# The ARMv7 is significanly faster due to the use of the hardware FPU
APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-8
----------------------------------------------------------------
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := plasma
LOCAL_SRC_FILES := plasma.c
LOCAL_LDLIBS := -lm -llog -ljnigraphics
include $(BUILD_SHARED_LIBRARY)
--------------------------------------------------------
plasma.c
#include <jni.h>
#include <time.h>
#include <android/log.h>
#include <android/bitmap.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

The configuration of CDT indexer needs to enable "Index unused headers ..."
To get there: Project->Properties->C/C++ General->Indexer.
Than rebuild the project
If still this appears than repeat this again.It will be gone :)

Related

linking libmedia_jni.so coudn't find the header android_media_MediaCodec.h

I'm trying to link libmedia_jni.so in my android project so that I could access android_media_MediaCodec.h, but It fails to find the header.
my .cpp:
#include <jni.h>
#include <media/android_media_MediaCodec.h>
and Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := AndroidMediaCodec
LOCAL_SRC_FILES := AndroidMediaCodec.cpp
LOCAL_SHARED_LIBRARY := libmedia_jni
include $(BUILD_SHARED_LIBRARY)
I just want to link the library, because I don't have the whole framework. Is that even possible?

NDK - include error

I need your help because it drives me crazy. What cause my error?
The error is
"jni/algorithm.cpp:4:33: fatal error: opencv2/core/core.hpp: No such file or directory #include <opencv2/core/core.hpp>
^ compilation terminated. make: *** [obj/local/arm64-v8a/objs/algorithm/algorithm.o] Error 1"
My algorithm.cpp is:
#include <jni.h>
#include <string.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
using namespace std;
using namespace cv;
extern "C"
{
JNIEXPORT jlong JNICALL Java_com_example_hematoma_MainActivity_fce(JNIEnv *env, jobject obj, jlong matimage)
{
Mat *jni_image = (Mat*) matimage;
return (jlong)jni_image;
}
}
My Android.mk is:
LOCAL_PATH := $(call my-dir)
include /home/nemesis/adt-bundle-linux-x86_64-20140702/OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk
include $(CLEAR_VARS)
LOCAL_MODULE := algorithm
LOCAL_SRC_FILES := algorithm.cpp
LOCAL_C_INCLUDE := /home/nemesis/adt-bundle-linux-x86_64-20140702/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/core.hpp
LOCAL_C_INCLUDE += /home/nemesis/adt-bundle-linux-x86_64-20140702/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/
include $(BUILD_SHARED_LIBRARY)
The error occurs when ndk try to build .so
Thanks in advance.
LOCAL_C_INCLUDE := /home/nemesis/adt-bundle-linux-x86_64-20140702/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2
should be
LOCAL_C_INCLUDES := /home/nemesis/adt-bundle-linux-x86_64-20140702/OpenCV-2.4.10-android-sdk/sdk/native/jni/include
ie, it is plural and should point to the location from which the following is a relative path:
#include <opencv2/core/core.hpp>
I solved my problem by add LOCAL_LDLIBS += -llog -ldl to "Android.mk"
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include C:/.../OpenCV-3.1.0-android-sdk/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := Testappcv
LOCAL_SRC_FILES := Testappcv.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
And added "Application.mk" file to jni folder
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-8
So, I tried to change in Project properties C/C++ Build -> Build command from ${NDKROOT}/ndk-build to ${NDKROOT}/ndk-build.cmd and it solved all my include libs errors. weird

Android.mk adding LOCAL_CPPFLAGS doesn't work

My source file can not include some header, because of local flag is not defined.
SSS.cpp:
#include <jni.h>
//This code is not defined:
#ifdef WORD
#include "Word.h"
#endif
//...rest of code
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := word
LOCAL_CPPFLAGS := -DWORD
LOCAL_SRC_FILES := SSS.cpp
include $(BUILD_SHARED_LIBRARY)
And one more moment, project build was successful, but I can not run it because of lots of errors in source file (Eclipse c++ editor still can not see my header).
Probably not -WORD but -DWORD ?
-D defines a macro to be used by the preprocessor.
And what this
-std=c++11
belongs to?

Headers with Android NDK

I'm trying to compilate my own library with the Android NDK But I've got some problems.
Here is my Android.mk file:
# Define vars for library that will be build statically.
include $(CLEAR_VARS)
LOCAL_MODULE := MyLib
LOCAL_SRC_FILES := ../../../src/mylib/utils/Timer.cpp
LOCAL_C_INCLUDES := ../../../src/mylib/
# Optional compiler flags.
LOCAL_LDLIBS = -lz -lm
LOCAL_LDLIBS := -llog
LOCAL_CPPFLAGS := -std=c++0x
include $(BUILD_SHARED_LIBRARY)
When I build my project with "ndk-build" I've got the following error :
Clean: mylib [armeabi]
Clean: stlport_shared [armeabi]
Clean: stlport_static [armeabi]
Compile++ thumb : mylib <= Timer.cpp
jni/../../../src/mylib/utils/Timer.cpp:1:34: fatal error: mylib/utils/Timer.hpp: No such file or directory
compilation terminated.
For information, I'm including the .hpp like that :
#include <mylib/utils/Timer.hpp>
I don't know why headers aren't found, my library working in Xcode and eclipse.
Thanks for your time!
Edit: Here is my project's architecture to understand my problem: http://i.imgur.com/aiah6zH.jpg
I'm trying to indicate where is located my ".hpp" files in the Android.mk file.
Your LOCAL_C_INCLUDES should include the ../../../src/ or ../../../inc directory in order for you to use #include <mylib/utils/Timer.hpp> i.e:
LOCAL_C_INCLUDES := ../../../src/
Why don't you put your C and C++ headers and source files inside the jni/ directory of the Android project, near the Android.mk file?
See: What is the difference between #include <filename> and #include "filename"?
Also this is incorrect, because the second LOCAL_LDLIBS overrides the previous LOCAL_LDLIBS directive in the current module :
LOCAL_LDLIBS = -lz -lm
LOCAL_LDLIBS := -llog
If you want to append to a make directive use:
LOCAL_LDLIBS := -lz -lm
LOCAL_LDLIBS += -llog
or LOCAL_LDLIBS := -lz -lm -llog
EDIT:
Using the following Android.mk it seems to work if you run ndk-build from the Android/jni directory.
LOCAL_PATH := $(call my-dir)
# first lib, which will be built statically
#
include $(CLEAR_VARS)
LOCAL_MODULE := MyLib
LOCAL_C_INCLUDES := ../../../inc/
LOCAL_SRC_FILES := ../../../src/mylib/utils/Timer.cpp
include $(BUILD_STATIC_LIBRARY)
# second lib, which will depend on and include the first one
#
include $(CLEAR_VARS)
LOCAL_MODULE := MyNativeFinalSharedLib
LOCAL_LDLIBS := -lz -lm -llog
LOCAL_CPPFLAGS := -std=c++0x
LOCAL_STATIC_LIBRARIES := MyLib
include $(BUILD_SHARED_LIBRARY)
Also you forgot to put LOCAL_PATH := (call my-dir) on the first line and some other missing make directives.
An Android.mk file must begin with the definition of the LOCAL_PATH
variable. It is used to locate source files in the development tree.
In this example, the macro function 'my-dir', provided by the build
system, is used to return the path of the current directory (i.e. the
directory containing the Android.mk file itself).
(from android-ndk-r8d/docs/ANDROID-MK.html)
It's highly recommended to have your Android.mk file define $(LOCAL_PATH). In your case, the best choice would probably be
LOCAL_PATH := $(call my-dir)/../../../../src
Now you can simply write
LOCAL_SRC_FILES := mylib/utils/Timer.cpp
But for the includes, the path should be defined as relative from current, i.e. MyProject/build/Android directory. In your case, it seems, the correct path would be
LOCAL_C_INCLUDES := ../../../inc
This when you specify mylib in the #include statement:
#include <mylib/utils/Timer.hpp>

android ndk undefined reference to a method

Hi Sorry for the long post I am trying to compile some static classes namely jsmn.c,json.c and buf.c which are part of the jsmn json library I downloaded from https://github.com/alisdair/jsmn-example/downloads.
I am compiling two STATIC_LIBRARIES lib1 and json_librrary.lib1 has native code which is dependent on json_library.Then I am making two libraries into a shared library containing
gnustl_static AND lib1
My folder structure is as follows
jni/lib1/ANdroid.mk
include $(CLEAR_VARS)
LOCAL_MODULE := json_library
LOCAL_SRC_FILES := /3rdParty/jsmn/json_library.a
LOCAL_SRC_FILES := /3rdParty/jsmn/jsmn.c /3rdParty/jsmn/buf.c /3rdParty/jsmn/log.c /3rdParty/jsmn/json.c
LOCAL_C_INCLUDES := /3rdParty/jsmn/jsmn.h /3rdParty/jsmn/buf.h /3rdParty/jsmn/log.h /3rdParty/jsmn/json.h
# Optional compiler flags.
LOCAL_LDLIBS = -lz -lm
LOCAL_CFLAGS = -Wall -pedantic -std=c99 -g
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
# Module Name
LOCAL_MODULE := lib1
LOCAL_STATIC_LIBRARIES := json_library
........
.......
......
include $(BUILD_STATIC_LIBRARY)
jni/Android.mk
# Here we give our module name
LOCAL_MODULE := lib2
# list the static modules included here!!!
LOCAL_STATIC_LIBRARIES := gnustl_static lib1
....
include $(BUILD_SHARED_LIBRARY)
jni/Application.mk
APP_MODULES := lib2
# Optimization for release
APP_OPTM := release
#Targets
APP_ABI := armeabi-v7a armeabi
So inside the lib1 I have class which calls a method from the json library named json_tokenise
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <jsmn/jsmn.h>
#include <jsmn/json.h>
#include <jsmn/buf.h>
jsmntok_t *tokens=json_tokenise((char *)data);
typedef enum {
START,
WRAPPER,
MESSAGE,
ROUTE,
OBJECT,
ARRAY,
SKIP,
STOP
}parse_state;
I am getting the following error
undefined reference to `json_tokenise(char*)'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/lib2.so] Error 1
**** Build Finished ****
When I have a look inside [obj/local/armeabi-v7a/ I can see
libjson_library.a liblib1.a libgnustl_static.a are getting generated for the armabi-v7 and it fails to generate lib2 because of the error.
Please help or guide me where I am going wrong I have spent two days on this and I am new to NDK.
You should fix your jni/lib1/Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := json_library
LOCAL_SRC_FILES := 3rdParty/jsmn/jsmn.c 3rdParty/jsmn/buf.c 3rdParty/jsmn/log.c 3rdParty/jsmn/json.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/3rdParty/jsmn
# Optional compiler flags.
LOCAL_LDLIBS = -lz -lm
LOCAL_CFLAGS = -Wall -pedantic -std=c99 -g
include $(BUILD_STATIC_LIBRARY)
If you still have problems after this, please run ndk-build with parameter V=1 on command line and post the full output of this build and full content of all your Android.mk files.
I faced similar problem. The json_library.a should be included in prebuild static library module. And that should be compiled for the desired platform.
include $(CLEAR_VARS)
LOCAL_MODULE := json_core
LOCAL_SRC_FILES := /3rdParty/jsmn/json_library.a
include $(PREBUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := json_library
LOCAL_SRC_FILES := /3rdParty/jsmn/jsmn.c /3rdParty/jsmn/buf.c /3rdParty/jsmn/log.c /3rdParty/jsmn/json.c
There is no need to include each file separately.
LOCAL_C_INCLUDES := /3rdParty/jsmn/
Finally, it is needed to specify that json_library module is dependent on json_core (prebuilt library) .
LOCAL_STATIC_LIBRARIES := json_core
# Optional compiler flags.
LOCAL_LDLIBS = -lz -lm
LOCAL_CFLAGS = -Wall -pedantic -std=c99 -g
include $(BUILD_STATIC_LIBRARY)
In this way the linker knows where to find all the definitions of methods for each module.

Categories

Resources