有人可以向我解释如何在ndk项目中用C ++编写的正确链接外部库吗?
我尝试使用此视频中描述的SDL库:https://www.youtube.com/watch?v=BSBISI0sCqo&t=306s但是当我尝试执行终端中的一个命令时会出现问题:
F:/编程/ Android的/独立/应用程序/ SRC /主/ CPP> C:/ Users / Danijel / AppData / Local / Android / sdk / ndk-bundle / ndk-build NDK_LIBS_OUT = .. / jniLibs
此调用导致错误:
Android NDK:未设置APP_PLATFORM。默认为最小支持版本android- 14。 Android NDK:你的APP_BUILD_SCRIPT指向一个未知文件:F:/Programming/Android/Indie/app/src/main/cpp/jni/Android.mk C:/用户/海伦芬/应用程序数据/本地/安卓/ SDK / NDK束/建造//../构建/核心/附加申请 ication.mk:101:*** Android NDK:正在中止.......停止。
所以,我知道实际的路径包含cpp文件夹(我无法重命名为jni),而不是jni,但是当我尝试在gradle中设置路径时,会发生同样的事情。
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} )
答案 0 :(得分:0)
C:/Users/Danijel/AppData/Local/Android/sdk/ndk-bundle/build//../build/core/add-appl ication.mk:101: *** Android NDK: Aborting... . Stop.
add-appl ication.mk