Adding external .h files to NDK project in Windows - android

I have added ndk plugin in Eclipse.
I have imported a NDK project in Eclipse.
But projects requires external .h file from the system, so I have added that folder where .h files files resides by
right click on project-> c/C++ General->Paths and symbols->then click on
include and then click add and given path of that folder
also checked all configurations and all languages.
still when I build the project from Command prompt by moving to path where my project is , then ndk-build I am getting for .h file no such file or directory error.
How can I resolve this issue??
Please help...

Please refer to documentation of LOCAL_C_INCLUDES variable

what you did to add the reference the external headers was only for eclipse, so it correctly resolves all the symbols and files references.
You also need to properly add a reference to these .h inside your ndk configuration files, ie inside Android.mk.
Use LOCAL_C_INCLUDES := path/to/headers in your module, like in this sample Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := main.c
LOCAL_MODULE := mymodule
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../includes
include $(BUILD_SHARED_LIBRARY)
If your .h files are part of a prebuilt module your own module depends on, use LOCAL_EXPORT_C_INCLUDES inside the prebuilt module instead of LOCAL_C_INCLUDES inside yours.

Related

android.mk sdl building errors

I've looked around at some questions about writing android.mk files and the "make: * No rule to make target .c needed by .o"** they all center around typos which I don't think that I have.
This is an SDL project that builds fine with my CMake build scripts but I just can't get android.mk to work for me.
Here's the project setup in cmake
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(blp)
#set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
FIND_PACKAGE(SDL2 REQUIRED)
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR})
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/core_math")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/utils/time_utils")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/utils/resource_utils")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/ren_opengl")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/core_engine")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/components/renderable2d")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/glm/vec3.hpp")
FIND_PACKAGE(SDL2 REQUIRED)
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR})
FIND_PACKAGE(SDL2_IMAGE)
INCLUDE_DIRECTORIES(${SDL2_IMAGE_INCLUDE_DIR})
ADD_SUBDIRECTORY(source)
ADD_SUBDIRECTORY(project)
SET(SRC_FILES main.c)
SET(EXTERNAL_TARGET_LIBS ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY})
SET(COMPONENTS renderable2d)
SET(INTERNAL_TARGET_LIBS core_math time_utils resource_utils ren_opengl)
SET(TARGET_LIBS ${INTERNAL_TARGET_LIBS} ${EXTERNAL_TARGET_LIBS} ${COMPONENTS})
FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin/resources/)
the project subfolder is where I can create different projects and reuse the source dynamic libs that I create.
inside the source, you can see I have a bunch of dynamic libs that are created. At the end there's the dynamic libs and one .h and .c class that imports all of them, then I import that one .h file inside my project to use the libs.
Now onto my android.mk file, it's not very complete yet but this is where I am running into trouble.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := main
SDL_PATH := ../SDL
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/utils/time_utils/
# Add your application source files here...
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
utils/time_utils.c \
//removing the above line, core_engine.c throws an import error
//adding the above line I get the error listed at the bottom
core_engine/core_engine.c \
project.c
LOCAL_SHARED_LIBRARIES := SDL2
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog
include $(BUILD_SHARED_LIBRARY)
make: *** No rule to make target `/Users/blubee/SDL/android-project/jni/src/time_utils/time_utils.c', needed by `/Users/blubee/SDL/android-project/obj/local/armeabi/objs/main/time_utils/time_utils.o'. Stop.
each lib is under it's own folder int he project source tree like this
source/components/renderable2d/renderable2d.c /.h
source/core_engine/core_engine.c /.h
source/core_math/mat4_scalar/mat4_scalar.c /.h
source/core_math/vec3_scalar/vec3_scalar.c /.h
source/..
etc...
It could be a build oder or the order in which I am defining the sources files in the android.mk folder, I am not sure. Any suggestions? I also made sure that there's no typos or extra spaces in my environment variables or the source file for the android.mk
It seems that android.mk is a lot more sensitive to header include order more so than cmake.
I simplified my project just to a main.c with a #include "SDL.h" and that builds just fine.
I will go from there and learn android.mk, while it's similar to cmake it's a lot more picky.

Android.mk relative or absolute paths?

I'm trying to build a project using the android ndk (on Windows), and I'm having some issues specifically with the source files (LOCAL_SRC_FILES in the Android.mk)
I'm trying to use relative paths to a parent folder such as
LOCAL_SRC_FILES := ../../../src/main.cpp
And when running ndk_build.cmd, it outputs the following error:
Compile++ thumb : GTP <= main.cpp
The system cannot find the file specified.
make: *** [obj/local/armeabi/objs/GTP/__/__/__/src/.o] Error 1
So I tried using absolute paths:
LOCAL_SRC_FILES := D:/Path/To/src/main.cpp
Unfortunately this doesn't work because the : causes issues on windows
Is there any way I can specify source files in a relative directory (or absolute)? The reason I am asking is because I want to avoid making a symbolic link to the src folder if possible.
According to ndk documentation it is recommended to use relative paths and the following macro (Android.mk uses syntax of make files):
LOCAL_PATH := $(call my-dir)
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).
So you can replace your LOCAL_SRC_FILES with something similar to:
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../../src/main.cpp
The easiest way to work with source files spread across many directories, is to compile separate static libraries for each directory or group of directories. In NDK, these libraries are called "modules". For each module, you specify LOCAL_SRC_PATH in Android.mk. LOCAL_SRC_FILES are relative to this path. The caveat is that LOCAL_C_INCLUDES etc. are relative to project root directory (usually, the one above the jni directory).
You can have many Android.mk files in your project, but you can build many modules with single Android.mk.
Try this:
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := YOUR_SRC_IN_LIB_JNI

How to build two ".so" files in Android

My question is:
I have used ndk to develop some functions, when built, it created a .so file in libs/armeabi. Now I needed to add another .so file from others. I only copied the .so to my dir libs/armeabi, then built it. The .so file was missing and I only had mine.
I do not kown why it happens. Should I need to config my Android.mk file, or any else?
This happens because the libs folder is cleaned when you run the ndk-build!
Edit your Android.mk and add this:
include $(CLEAR_VARS)
LOCAL_MODULE := MYOTHERSO-prebuilt
LOCAL_SRC_FILES := [relative path to your other .so]/lib[change to your lib name].so
LOCAL_EXPORT_C_INCLUDES := [relative path to your other .so include files]
include $(PREBUILT_SHARED_LIBRARY)
You should store the .so file on another path (not on libs/armeabi folder) in order to reference it from your Android.mk. During ndk-build it will be copied to libs/armeabi folder.

how to include external jar in android app for android custom build

I am trying to build a custom rom using android custom build project. I want to add one android application to it in which there is one external jar. But whenever I run 'mm' (i.e make) in /package/apps/myApp it gives error 41 in which it is not able to recognize classes and functions from that external jar. Although eclipse is recognizing that jar and app is running perfect in eclipse but 'mm' is not able to compile it. What should i do?
Any help is greatly appreciated.
Refer to the Android.mk file inside the Calculator app. It uses external jars.
I am also pasting a sample mk file that i used for my own app. You can use it:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_TAGS := tests
LOCAL_STATIC_JAVA_LIBRARIES := libguava libgcm android-support-v4
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SDK_VERSION := current
LOCAL_PACKAGE_NAME := SampleApp
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libguava:guava-11.0.jar libgcm:gcm.jar
include $(BUILD_MULTI_PREBUILT)
include $(call all-makefiles-under,$(LOCAL_PATH)
libguava and libgcm are just two namespaces(You can use your own names) for the two jars:guava-11.0.jar and gcm.jar(I have used these jars in my project) respectively. I have kept the jars inside the project folder. If you have kept the jars inside libs folder use libguava:libs/guava-11.0.jar.Also, don't use mm. Use make, but don't do make clean before it else it will remove the entire build directory and start from scratch(take a lot of time) Please accept as solution if it works....Thanks

Use External Jar in application android

I am having a library in vendor/xxx/libs/frameworks. I want to use that library in a separate application located at packages/apps/. when I am calling the classes of the library I am getting ClassNotFoundException. So should I declare this jar in my application makefile or manifest file. If yes How can I do that?
Here is make file of the jars
LOCAL_PATH := $(call my-dir)
# ============================================================
include $(CLEAR_VARS)
LOCAL_MODULE := xxx_core.jar
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
==== permissions ========================
include $(CLEAR_VARS)
LOCAL_MODULE := xxx_core.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
============================================================
You haven't mentioned if you added the jar to the buildpath of the app. To do this, right click on the project > Build Path > Add external Archives.
If this doesn't resolve this, then you should have a look at this tread: Android ClassNotFoundException
I hope this helps.
Follow this step to include the jar file in android application. It will be helpfull to you.
put your jar file in the lib folder.
Now right click on the jar file.
go to Build Path and then Configure build path..
A dialog box open now.
Click on the Add JARs.. Button.
Now select the jar file which you want to add in your app from the project list opened.
Now Click On OK.
your jar file is added in your application
If you haven't figured this out already, the build command you're looking for is:
LOCAL_STATIC_JAVA_LIBRARIES := android-common <YOUR-FRAMEWORK>
Assuming that your makefile in frameworks has a directive like
LOCAL_MODULE:= <YOUR-FRAMEWORK>
Good luck, I've found the Android build system to be a giant undocumented mess - but then they probably intended it to be that way
Use <uses-library> in application's manifest to make a reference to this .jar.

Categories

Resources