C++ app\src\main\cpp\CMakeLists.txt:C/C++;调试| arm64-v8a:配置失败
我复制了C++ app\src\main\cpp\CMakeLists.txt:C/C++;调试| arm64-v8a:配置失败,c++,cmake,android-ndk,java-native-interface,android-ffmpeg,C++,Cmake,Android Ndk,Java Native Interface,Android Ffmpeg,我复制了jnilibs文件夹下必要的.so文件,并使用jni接口在android ndk项目中配置了以下文件。在运行项目时,它抛出一个错误,如下所示 格雷德尔先生 defaultConfig{ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { c
jnilibs
文件夹下必要的.so文件,并使用jni接口在android ndk项目中配置了以下文件。在运行项目时,它抛出一个错误,如下所示
格雷德尔先生
defaultConfig{
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
abiFilters 'arm64-v8a'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
这是我的CMakeLists.txt
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
cmake_minimum_required(VERSION 3.4.1)
# Sets the minimum version of CMake required to build the native library.
#Import header file
include_directories(src/main/jniLibs/include)
#Declare the import file to change the directory variable ARM_DIR, which uses the relative directory with the system, because using the relative path does not seem to work
set(ARM_DIR C:/Users/Username/AndroidStudioProjectsFolder/ExamplAppName/app/src/main/jniLibs)
#Add an example of so library.
add_library(avdevice
SHARED
IMPORTED)
set_target_properties(avdevice
PROPERTIES IMPORTED_LOCATION
${ARM_DIR}/arm64-v8a/libavdevice.so)
#Adding other so libraries in the same format as above
#Link library
target_link_libraries(
native-lib
avdevice
avformat
${log-lib} )
# 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 them for you.
# Gradle automatically packages shared libraries with your APK.
#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).
# native-lib.cpp )
#
## Searches for a specified prebuilt library and stores the path as a
## variable. Because CMake includes system libraries 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 this
## build script, prebuilt third-party libraries, or system libraries.
#
#target_link_libraries( # Specifies the target library.
# native-lib
#
# # Links the target library to the log library
# # included in the NDK.
# ${log-lib} )
它的native-lib.cpp文件位于cpp/
目录下:
#include <jni.h>
#include <string>
extern "C"
{
#include "libavformat/avformat.h"
}
extern "C" JNIEXPORT jstring JNICALL
Java_com_examples_examplappname_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
av_register_all();
return env->NewStringUTF(hello.c_str());
}
错误:
**Starting Gradle Daemon...
Gradle Daemon started in 4 s 270 ms
KotlinDslScriptsParameter(correlationId=22803889351800, scriptFiles=[]) => StandardKotlinDslScriptsModel(scripts=[], commonModel=CommonKotlinDslScriptModel(classPath=[], sourcePath=[], implicitImports=[]), dehydratedScriptModels={}) - took 0.128 secs
app\src\main\cpp\CMakeLists.txt : C/C++ debug|arm64-v8a : Configuration failed.
app\src\main\cpp\CMakeLists.txt : C/C++ debug|arm64-v8a : CMake Error at app\src\main\cpp\CMakeLists.txt:21 (target_link_libraries):
Cannot specify link libraries for target "native-lib" which is not built by
this project
app\src\main\cpp\CMakeLists.txt : C/C++ debug|arm64-v8a : Configuration failed.
executing external native build for cmake
app\src\main\cpp\CMakeLists.txt
CONFIGURE SUCCESSFUL in 3m 33s**
此处的明显问题涉及CMake文件中的行:
target_link_libraries(
native-lib
avdevice
avformat
${log-lib} )
它甚至在定义库之前就引用了库(本机库目标和库变量${log lib})。这肯定会导致CMake发出错误。您应该取消对CMake文件其余部分的注释,并将导入的库目标链接到现有target\u link\u libraries()
调用中的native lib
:
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).
native-lib.cpp )
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 )
target_link_libraries( # Specifies the target library.
native-lib
# Link your imported library targets here also.
avdevice
avformat
# Links the target library to the log library
# included in the NDK.
${log-lib} )
此处的明显问题涉及CMake文件中的行:
target_link_libraries(
native-lib
avdevice
avformat
${log-lib} )
它甚至在定义库之前就引用了库(本机库目标和库变量${log lib})。这肯定会导致CMake发出错误。您应该取消对CMake文件其余部分的注释,并将导入的库目标链接到现有target\u link\u libraries()
调用中的native lib
:
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).
native-lib.cpp )
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 )
target_link_libraries( # Specifies the target library.
native-lib
# Link your imported library targets here also.
avdevice
avformat
# Links the target library to the log library
# included in the NDK.
${log-lib} )
请将完整的CMake输出添加到问题帖子中。“配置失败”部分表示CMake配置过程中的早期失败,但您尚未显示与此失败相关的错误消息…更新了我的错误请将完整的CMake输出添加到问题帖子中。“配置失败”部分表示CMake配置过程中的早期失败,但您尚未显示与此失败相关的错误消息…更新了我的错误