How to link native libraries to Gradle

Viewed 69

I am trying to build an android version of my program written in C/C++ and SDL2 library, according to this link.

using this command I created the gradle project:

./androidbuild.sh org.libsdl.testgles ../test/testgles.c

and according to tutorial I needed to build the project using this command:

./gradlew installDebug

But the gradle build task fails and it throws me this Error:

home/yolo/Workstation/Android/SDL/build/com.yolo.test/app/jni/src/main.cpp:2:10: fatal error: 'SDL2/SDL.h' file not found   
#include <SDL2/SDL.h>   
         ^~~~~~~~~~~~   
1 error generated.  
make: *** [/home/yolo/Android/Sdk/ndk/21.4.7075529/build/core/build-binary.mk:478: /home/yolo/Workstation/Android/SDL/build/com.yolo.test/app/build/intermediates/cxx/Debug/5d2wq3g4/obj/local/armeabi-v7a/objs-debug/main/main.o] Error 1

Caused by: com.android.ide.common.process.BuildCommandException: Build command failed.  
Error while executing process /home/yolo/Android/Sdk/ndk/21.4.7075529/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/yolo/Workstation/Android/SDL/build/com.yolo.test/app/jni/Android.mk NDK_APPLICATION_MK=/home/yolo/Workstation/Android/SDL/build/com.yolo.test/app/jni/Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 NDK_OUT=/home/yolo/Workstation/Android/SDL/build/com.yolo.test/app/build/intermediates/cxx/Debug/5d2wq3g4/obj NDK_LIBS_OUT=/home/yolo/Workstation/Android/SDL/build/com.yolo.test/app/build/intermediates/cxx/Debug/5d2wq3g4/lib APP_PLATFORM=android-16 SDL2 main}  
make: Nothing to be done for 'SDL2'.    
[armeabi-v7a] Compile++ thumb: main <= main.cpp

It looks like that Gradle is not linked to SDL libraries therefore it thinks they are not installed.

You can see the full scan here.

UPDATE

This is the content of /app/jni/src/Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := main

SDL_PATH := ../SDL

LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include

# Add your application source files here...
LOCAL_SRC_FILES :=  main.cpp

LOCAL_SHARED_LIBRARIES := SDL2

LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -lOpenSLES -llog -landroid

include $(BUILD_SHARED_LIBRARY)
0 Answers
Related