8

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.

Community
  • 1
  • 1
Brad
  • 10,015
  • 17
  • 54
  • 77

3 Answers3

11

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
Michael
  • 1,505
  • 14
  • 26
1

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.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
0

Try this:

LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := YOUR_SRC_IN_LIB_JNI
user1755546
  • 1,049
  • 2
  • 13
  • 27