在Windows中使用C++连接外部库的Android工作室

问题描述:

有人可以向我解释如何在ndk项目中用C++编写正确的外部库链接?在Windows中使用C++连接外部库的Android工作室

我试图使用SDL库在该视频描述:https://www.youtube.com/watch?v=BSBISI0sCqo&t=306s但是当我尝试执行在终端中的一个命令出现问题:

F:/编程/安卓/独立/应用/ SRC /主/ CPP> C:/用户/达尼耶尔/应用程序数据/本地/ Android设备/ SDK/NDK束/ NDK建造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:/ Users/Danijel/AppData/Local/Android/sdk/ndk-bundle/build //../ build/core/add-appl ication.mk:101:*** Android NDK:Aborting ...。停止。

所以,我知道实际路径包含cpp文件夹(我不能重命名为jni),而不是jni,但是当我尝试在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}) 

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

+0

那么,这是终端产生的。刚才我在相应的文件夹中检查了该文件,并且其名称不包含任何空格。我不知道为什么Android工作室认为Android.mk不存在时位于jni文件夹中。 –