android NDK build issue - android

when I tried the NDK build command here is the error i got
D:\AndroidWorkSpace\cppTestProj>D:\android-ndk-r8b-windows\android-ndk-r8b\ndk-b
uild.cmd
Android NDK: WARNING: Unsupported source file extensions in jni/Android.mk for m
odule cppTestProj
Android NDK: LOCAL_SRC_FILES :=
"Compile++ thumb : cppTestProj <= maintestapp.cpp
jni/maintestapp.cpp:1:19: fatal error: iostream: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi/objs/cppTestProj/maintestapp.o] Error 1
The JNI folder has the following files:
maintestapp.cpp
Test_array_type.cpp
Test_array_type.h
Could u pls let me know the issue. Im not using Cygwin for the same. Am I missing any files?
Here is the make file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cppTestProj
LOCAL_SRC_FILES := LOCAL_SRC_FILES := maintestapp.cpp \
Test_array_type.cpp
include $(BUILD_SHARED_LIBRARY)
here is the cpp file
#include<iostream>
#include"Test_array_type.h"
#include<stdio.h>
#include<conio.h>
using namespace std;
int main()
{
Test_array_type test_array;
Test_array_type *ptest_array1;
test_array.AddToList(10);
test_array.AddToList(20);
test_array.AddToList("Basha");
test_array.PrintList();
ptest_array1 = test_array.clonelist();
test_array.DeleteFromList(3);
test_array.AddToList(10);
test_array.AddToList(20);
test_array.AddToList(30);
test_array.AddToList(40);
test_array.AddToList(true);
test_array.AddToList("Java Beon APP");
test_array.PrintList();
ptest_array1->PrintList();
getch();
return true;
}

you should not run the 'ndk-build' command from your projects jni folder. To execute the Android.mk file run ndk-bild command within your root directory of project.
Your Android.mk should be look like this
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cppTestProj
LOCAL_SRC_FILES := maintestapp.cpp \
Test_array_type.cpp
include $(BUILD_SHARED_LIBRARY)
Then run your ndk-build command
You can see this link for sample Android.mk file
Update:
static {
System.loadLibrary("hello-jni");
}
for more information please refer HelloJni.java file of sample project.
Thanks

you need to add LOCAL_C_INCLUDES and include your visual C++ include folders, since you are obviuosly working with it.

Related

Compile .c library Eclipse for Android error

I'm using Eclipse for Windows, Android SDK and Android NDK (I'm sure that all paths are set correclty).
I'm looking for compiling a .c library locatad in jni folder, but some error occur. This library depends on external .so libraries, these are my Makefile, Android.mk and library:
jni folder.
Android.mk :
LOCAL_PATH := $(call my-dir)
#---------------------------------------------------------------
include $(CLEAR_VARS)
LOCAL_MODULE := pdbeatdetection
LOCAL_C_INCLUDES := $(LOCAL_PATH)\C:\PROGRAMMING\pd-0.45-4\src
LOCAL_CFLAGS := -DPD
LOCAL_SRC_FILES := pdbeatdetection.c
LOCAL_LDLIBS := -L$(LOCAL_PATH)\C:\PROGRAMMING\PdCore\libs\armeabi\ -lpdnative
include $(BUILD_SHARED_LIBRARY)
Makefile :
all:
C:\PROGRAMMING\android-ndk-r10d\ndk-build.cmd
mkdir ../tmp
cp ..\libs\armeabi\libpdBeatDetection.so ..\tmp\pdbeatdetection.pd_linux
cd ..\tmp && zip externals.zip *.pd_linux && mv externals.zip ..\res\raw
rm -rf ..\tmp
I followed some tutorials, but I'm not still able to solve this issue.
Could you please give me suggestions to compile the library, avoiding the following error?
ERROR:
Description Resource Path Location Type
make.exe: *** [obj/local/armeabi/libpdbeatdetection.so] Error 1 Discoteque C/C++ Problem
Thank you!
If your code depends on an external .so file, you should declare it properly using the PREBUILT_SHARED_LIBRARY macro, like so:
LOCAL_PATH := $(call my-dir)
#dependency
include $(CLEAR_VARS)
LOCAL_MODULE := pdnative
LOCAL_SRC_FILES := C:/PROGRAMMING/PdCore/libs/$(TARGET_ARCH_ABI)/libpdnative.so
LOCAL_EXPORT_C_INCLUDES := C:/PROGRAMMING/pd-0.45-4/src
include $(PREBUILT_SHARED_LIBRARY)
#your module
include $(CLEAR_VARS)
LOCAL_MODULE := pdbeatdetection
LOCAL_SRC_FILES := pdbeatdetection.c
LOCAL_CFLAGS := -DPD
include $(BUILD_SHARED_LIBRARY)
If that's not enough to solve your issue, give us the error reported by calling ndk-build.cmd directly.

Android NDK - Additional Include Directories

I am using the Android NDK to build a shared library. I have include a snippet from my Android.mk file that is causing me a few issues.
LOCAL_PATH := $(call my-dir)
..#other module here
..#other module here
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)
My spatialite.c file includes some header files that are located in a folder that is external to the application project folder. I have included that folder in LOCAL_C_INCLUDES as shown above, but on running ndk-build, it still cannot locate these includes. What is the correct way of allowing the ndk-build command to identify where these includes are located. Any help will be greatly appreaciated.
UPDATE:
I wanted to add that spatialite itself need not be visible to the Java layer. I will thereafter be building another module which uses spatialite. I am not sure if this makes a difference to the way I declare the module on the Android.mk file.
The compiler output is shown below:
jni/spatialite.c:102:20: fatal error: geos_c.h: No such file or directory
#include
The .h file that is being imported in spatialite.c is located at C:/projects/externalappsdk/include. The spatialite.c and Android.mk are located at C:/mobile/myandroidproject/jni/
The include directive within my spatialite.c file is shown below:
#ifndef OMIT_GEOS /* including GEOS */
#include <geos_c.h>
#endif
ANSWER:
I managed to get this working using help from the answers provided by Chris which I have accepted. However, I had to make one change to the Android.mk file as is shown below:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_C_INCLUDES := ../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)
Note, that the LOCAL_C_INCLUDES goes two levels back instead of three.
Without a
LOCAL_PATH := $(call my-dir)
At the top of the Android.mk, I was unable to build a replica of your project as described, however the error was different than your report - without that directive the compiler was searching for the C source files in an NDK system directory rather in the jni/ folder.
$ cd mobile/myandroidproject/jni
$ ndk-build
Compile thumb : spatialite <= spatialite.c
SharedLibrary : libspatialite.so
Install : libspatialite.so => libs/armeabi/libspatialite.so
File: ./mobile/myandroidproject/jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)
File: ./mobile/myandroidproject/jni/spatialite.c
#include <geos_c.h>
File: ./mobile/myandroidproject/jni/sqlite3.c
//empty file
File: ./projects/externalappsdk/include/geos_c.h
//empty file
At minimum you should add the LOCAL_PATH line to your Android.mk
If that does not solve the problem, then please update your question with any differences between your project structure and my recreation of it.
Use LOCAL_EXPORT_C_INCLUDE_DIRS instead of LOCAL_C_INCLUDES

Not able to build Android NDK project fatal error: android/configuration.h: No such file or directory compilation terminated

I am building a complete native app in using Android NDK, when I try to build the app I am getting the following error:
D:/Softwares/android-ndk-r9c/sources/android/native_app_glue/android_native_app_glue.h:25:35: fatal error: android/configuration.h: No such file or directory compilation terminated.
I am not getting why this error is coming. I have created an Android.mk file with following content
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mynativeactivity
LOCAL_SRC_FILES := Log.cpp Main.cpp EventLoop.cpp
LOCAL_LDLIBS := -llog -landroid
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Also, in the project properties I have added following Paths & Symbols
D:/Softwares/android-ndk-r9c/platforms/android-9/arch-arm/usr/include
D:/Softwares/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.8/include
D:/Softwares/android-ndk-r9c/sources/android/native_app_glue
Can anyone suggest what am I doing wrong ?
LOCAL_LDLIBS := -landroid is the problem.
The system is expecting the configuration.h file, as simple as that.
Why do you mean by project properties ? in eclipse ? .
ndk-build would not pick your ecplise project properties.
Please add Application.mk file and mention the APP_PLATFORM := android-9 ( not sure if it should solve the problem).Otherwise , add the include path LOCAL_C_INCLUDES in your android.mk file.

Eclipse can't include opencv2 header files

I've created an Android Application Project in Eclipse Juno, and after I've added native support to this project (Android Tools -> Add Native Support). So Eclipse has added in the project automatically a jni directory, within which a .cpp file and the file Android.mk.
Then I've build the project, without errors.
In order to use opencv for android libraries (2.4.5), I've added the path to the 'include' directory of these libraries in the project (Properties -> C/C++ General -> Path And Symbols -> Include Diretories). I've also set in the Eclipse Preferences -> NDK the correct path to the ndk directory in my pc, to make possible to execute ndk-build when I build the projects.
But, if i try to include in the .cpp file:
#include <opencv2/opencv.hpp>
The console show me this result:
12:24:25 **** Build of configuration Default for project ProvaVideoCapture ****
"C:\\Users\\Micaela\\Desktop\\Android\\android-ndk-r8e\\ndk-build.cmd" all
"Compile++ thumb : jniVideoCapture <= jniVideoCapture.cpp
jni/jniVideoCapture.cpp:4:30: fatal error: opencv2/opencv.hpp: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs/jniVideoCapture/jniVideoCapture.o] Error 1
12:24:26 Build Finished (took 282ms)
My Android.mk file is:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := jniVideoCapture
LOCAL_SRC_FILES := jniVideoCapture.cpp
include $(BUILD_SHARED_LIBRARY)
The Application.mk file that I've added manually (it has not been automatically added by Eclipse) is:
APP_ABI := all
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_PLATFORM := android-9
I don't know how to solve this problem, or what I've done wrong.
Could you help me?
Add path like below to your Android.mk file and check
include E:/OpenCV-2.3.1/share/OpenCV/OpenCV.mk
Sample Android.mk for reference
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE:=STATIC
OPENCV_INSTALL_MODULES:=on
include E:/OpenCV-2.3.1/share/OpenCV/OpenCV.mk
include $(OPENCV_MK_PATH)
LOCAL_MODULE := firstcv
LOCAL_SRC_FILES := first.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)

ndk-build can't find files under jni directory

I have a very simple test project. Basically one native c file under jni (jni is
under the root of the project, in the same directory as 'src' 'res' etc). The make
file is the basically the simplest:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native
LOCAL_SRC_FILES := native.c
include $(BUILD_SHARED_LIBRARY)
Error message is: make: * No rule to make target ` '/native.c'. needed by...
Obviously ndk-build was trying to find the file under root. If I copy the file
to the root '/' or if I specify the full path of 'native.c' in the make file,
then things are ok.
I also tried to output $LOCAL_PATH by $(warning, '$(LOCAL_PATH)') and found no problem.
Create Android.mk with the following content:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native
LOCAL_SRC_FILES := native.c
include $(BUILD_SHARED_LIBRARY)
Put native.c in the same folder where your Android.mk is.
Run ndk-build
You will have the output as follows:
D:\12314\jni>ndk-build
"Compile thumb : native <= native.c
SharedLibrary : libnative.so
Install : libnative.so => libs/armeabi/libnative.so

Categories

Resources