1

Can someone explain to me how to properly link external library in written in C++ in ndk project?

I'm trying to use SDL library as described in this video : https://www.youtube.com/watch?v=BSBISI0sCqo&t=306s but problem occurs when i try to execute one of the commands in the terminal:

F:/Programming/Android/Indie/app/src/main/cpp> C:/Users/Danijel/AppData/Local/Android/sdk/ndk-bundle/ndk-build NDK_LIBS_OUT=../jniLibs

this call results in error:

Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android- 14. Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: F:/Programming/Android/Indie/app/src/main/cpp/jni/Android.mk C:/Users/Danijel/AppData/Local/Android/sdk/ndk-bundle/build//../build/core/add-appl ication.mk:101: *** Android NDK: Aborting... . Stop.

So, I know that the actual path contains cpp folder(which I cannot rename to jni), not jni, but same thing happens when i try to set the path in gradle.

folder structure

Android.mk :

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := app
LOCAL_CFLAGS    := -Wall -Wextra
LOCAL_SRC_FILES := BoardManager.cpp GameEnvironment.cpp GameObject.cpp Player.cpp Renderer.cpp ShaderManager.cpp Utility.cpp TextureManager.cpp
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
include $(BUILD_SHARED_LIBRARY)

Application.mk :

APP_PLATFORM=android-14
APP_ABI := armeabi-v7a
APP_STL := gnustl_static

CMakeLists.txt :

# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.

if (${ANDROID_PLATFORM_LEVEL} LESS 12)
  message(FATAL_ERROR "OpenGL 2 is not supported before API level 11 (currently using ${ANDROID_PLATFORM_LEVEL}).")
  return()
elseif (${ANDROID_PLATFORM_LEVEL} LESS 18)
  add_definitions("-DDYNAMIC_ES3")
  set(OPENGL_LIB GLESv2)
else ()
  set(OPENGL_LIB GLESv3)
endif (${ANDROID_PLATFORM_LEVEL} LESS 11)

include_directories(src/main/cpp/)

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             # Associated headers in the same location as their source
             # file are automatically included.
             src/main/cpp/native-lib.cpp
             src/main/cpp/BoardManager.cpp
             src/main/cpp/GameEnvironment.cpp
             src/main/cpp/GameObject.cpp
             src/main/cpp/Player.cpp
             src/main/cpp/Renderer.cpp
             src/main/cpp/ShaderManager.cpp
             src/main/cpp/Utility.cpp
             src/main/cpp/TextureManager.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                       native-lib
                       ${OPENGL_LIB}
                       EGL
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

1 Answers1

0
C:/Users/Danijel/AppData/Local/Android/sdk/ndk-bundle/build//../build/core/add-appl ication.mk:101: *** Android NDK: Aborting... . Stop.

there is a space in add-appl ication.mk

pleft
  • 7,567
  • 2
  • 21
  • 45
  • Well, that is what terminal generated. A moment ago I checked that file in corresponding folder and its name does not contain any whitespaces. I'm not sure why android studio thinks that Android.mk is located in jni folder when it doesnt exist. – Danijel Pavlek Oct 05 '17 at 18:17