Android NDK include problems - android

I am currently reading the book "Beginning Android C++ Game Development" and after I import the source code, the headers do not work properly. It says that they are "unresolved inclusions" and cannot access them. Here is the source code for the top part:
#include <jni.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <android/sensor.h>
#include <android/log.h>
#include <android_native_app_glue.h>
If I manually key in the location, I can access the include files (I would have to type in the full address for each header file in the above code); and I have gone to properties, Paths and Symbols, and included them (they were automatically included). Here is a copy of my Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hellodroid
LOCAL_SRC_FILES := main.cpp
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Thanks for any help in advance.

Never Mind, I got it to work. I would suggest that instead of importing the source code to create the original project; create your own project and the settings using the book's steps. Then just cut and paste the main.cpp or hellodroid.cpp files into the project. Do not import the whole project or else the code probably will show errors.

Related

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?

Can't include NDK header files

i wrote a simple C++ Programm using NDK, and it works fine.
Now I want to add the following header file for using logging functions:
android\log.h
My Android.mk look like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS:= -llog
LOCAL_MODULE := ndkmodulea
LOCAL_SRC_FILES := ndkmodulea.cpp
include $(BUILD_SHARED_LIBRARY)
My .cpp file starts like this:
#include <jni.h>
#include <string.h>
#include <android\log.h>
if i try to run ndk-build (via terminal) inside the android project folder,
I'll get following error message:
Compile++ thumb : ndkmodulea <= ndkmodulea.cpp
jni/ndkmodulea.cpp:4:25: fatal error: android\log.h: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi/objs/ndkmodulea/ndkmodulea.o] Error 1
Can somebody help or teach me how to correctly include such header files?
Many thanks in advance!
Use forward slashes in #include paths:
#include <android/log.h>

Type 'AndroidBitmapInfo' could not be resolved

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 :)

Running ffmpeg as library in android

I've got a simple task to do. I need to merge set of pictures into a video using ffmpeg working in android environment.
After over a week fighting with different tutorials and examples explaining how to run compile ffmpeg I have, let's say, middle success. I've finally compiled ffmpeg for android.
I followed this example:
https://github.com/appunite/AndroidFFmpeg
which worked best for me.
As a result of building ffmpeg a have following directory structure:
[Project]/jni/ffmpeg-build/armeabi-v7a/libffmpeg.so
[Project]/jni/ffmpeg-build/armeabi/libffmpeg.so
[Project]/jni/ffmpeg-build/mips/libffmpeg.so
[Project]/jni/ffmpeg-build/x86/libffmpeg.so
I also followed the ndk examples so I have running c code from java:
#include <string.h>
#include <jni.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <android/log.h>
#include <stdlib.h>
#include <stdbool.h>
bool initted = false;
static JavaVM *sVm;
jstring Java_com_example_hellojni_HelloJni_stringFromJNI(JNIEnv* env, jobject thiz) {
char **argv;
char *cmd;
int argc;
// cmd = "ffmpeg -version";
// argv = parsedargs(cmd, &argc);
// ffmpeg(argc, argv);
return (*env)->NewStringUTF(env, "Hello from JNI !");
}
My question is how to run function from ffmpeg from my "hello-jni" c-file. I've read I need to write a wrapper over ffmpeg which my hello-jni is intended to be.
Here is my Android.mk which probably is importat part to achieve my goal, but honestly I don't understand some lines set in this file. Or simply I don't know how to make things work.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg-prebuilt
LOCAL_SRC_FILES := ffmpeg-build/$(TARGET_ARCH_ABI)/libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := ffmpeg-build/$(TARGET_ARCH_ABI)/include
LOCAL_EXPORT_LDLIBS := ffmpeg-build/$(TARGET_ARCH_ABI)/libffmpeg.so
LOCAL_PRELINK_MODULE := true
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_ALLOW_UNDEFINED_SYMBOLS=true
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ffmpeg-build/$(TARGET_ARCH_ABI)/include
LOCAL_SHARED_LIBRARY := ffmpeg-prebuilt
#LOCAL_CFLAGS += -g -Iffmpeg-prebuilt -Ihello-jni -Wno-deprecated-declarations
#LOCAL_LDLIBS += -llog -lz -landroid ffmpeg-build/$(TARGET_ARCH_ABI)/libffmpeg.so
include $(BUILD_SHARED_LIBRARY)
One more thing. I've found an example how to wrap ffmpeg's main function. It'd be the easiest way to use ffmpeg for me sinse I don't know ffmpeg's api and I hope it's possible to run ffmpeg this way:
Can FFmpeg be used as a library, instead of a standalone program?
To sum up, I think my problems are due to completely lack of c/c++ knowledge at all, especially how to use run any function from .so library.
I hope someone can help me :).
https://github.com/halfninja/android-ffmpeg-x264/blob/master/Project/jni/videokit/uk_co_halfninja_videokit_Videokit.c
Look at the 'JNI_Call...' in the link above. That is how to call the wrapper for 'ffmpeg.main()' from android.
https://github.com/halfninja/android-ffmpeg-x264/blob/master/Project/jni/videokit/ffmpeg.c
use link above and find 'main()' at the very end. This is example of very slightly altered version of ffmpeg.c (logger altered for java/android ndk).
If you study these samples , you should get feeling for how to wrapper ffmpeg.main() in one of the other projects if you want to use it. The logger issue is moot at this point so the more modern [android-ffmpeg] projects on git can just make ffmpeg.c out of the box and use it with JNI. The only thing u may still have to change is the 'exit()' at the very end of main().

android external/stlport include in Android.mk build not successfull

I m trying to build an app with android-froyo source in which I am using skia and stl templates,
I have included
MY_INCLUDES=external/zlib external/jpeg external/freetype/include \
frameworks/base/core/jni/android/graphics external/skia/include/core \
external/libpng external/expat/lib <b>external/stlport/stlport</b>
libstlport_cflags := -D_GNU_SOURCE
libstlport_cppflags := -fuse-cxa-atexit
LOCAL_CPPFLAGS := $(libstlport_cppflags)
include $(BUILD_STATIC_LIBRARY)
I get the following error when i try to build the android source with this app, which i kept at packages/apps:
external/stlport/stlport/stl/_new.h:47:50: error: libstdc++/include/new: No such file or directory
Please guide me to rectify this issue.
Thanks
Mohit
As I understand the file which cannot be found by preprocessor is located in bionic folder.
I had the same issue and I solved it by adding the following line:
LOCAL_C_INCLUDES += bionic
I haven't tried this with Android 2.2 but I'm using Android Kitkat (4.4).
To get the stlport library working with our project we included it in our project's Android.mk as so:
include external/stlport/libstlport.mk
This is assuming that on Froyo, there is a libstlport.mk file to include in your build process. In 4.4, there is also a Android.mk file but that builds other code as well and builds stlport as a static library (which is not what we wanted).
You may need to also add the include directory as well, something like: external/stlport/stlport.
cpp
#include <stdio.h>
// The code
// The set of definitions and includes for STLPort
// They used defined() instead of #ifdef.
#define _STLP_HAS_INCLUDE_NEXT 1
#define _STLP_USE_MALLOC 1
#define _STLP_USE_NO_IOSTREAMS 1
#include <stl/config/_android.h>
#include <map>
#include <string>
int main(void)
{
std::string a = "abc";
printf("%s",a.c_str());
return 0;
}
Android.mk
# A simple test for the minimal standard C++ library
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := test-libstl.cpp
LOCAL_C_INCLUDES += sources/cxx-stl/stlport/stlport
LOCAL_SHARED_LIBRARIES += libstlport
LOCAL_MODULE := test-libstl
include $(BUILD_EXECUTABLE)

Categories

Resources