我在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"
}
}
# 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} )
#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());
}
static {
System.loadLibrary("avdevice");
System.loadLibrary("avformat");
System.loadLibrary("native-lib");
}
TextView tv = findViewById(R.id.sample_text);
tv.setText(stringFromJNI());
**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} )
它甚至在定义库(native-lib
目标和${log-lib}
library变量)之前就引用它们。这肯定会导致CMake发出错误。您应该取消对CMake文件其余部分的注释,并将导入的库目标链接到现有的target_link_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} )
我需要为一个Android arm64-v8a设备构建一个Qt应用程序。 这些设备应该能够运行QtCreator支持的armv7a二进制文件(请参见arm64-v8a是否与ARMEABI-V7a兼容?)。但是我在arm64-v8a上的应用程序在armeabi-v7a上工作时遇到了故障,所以我想直接为arm64-v8a构建应用程序并再次测试。 经过一些搜索,我最终尝试使用以下命令配置Qt(qt-ev
对于我的Android应用程序,我现在使用的是ABI“x86”和“armeabi”。armeabi用于所有ARM设备,包括armv7a和ARM64-V8A。
我正在尝试使用bazel为android for arm64-v8a构建libtensorflow_cc.so体系结构 需求 我试图为android for arm64-v8a架构构建'libtensorflow_cc.so'。我需要它在运行时通过C++在Android NDK中创建和训练一个模型文件。我能够在桌面上使用C++并借助'libtensorflow_cc.so'生成 bazel bui
我有一个库,我用它为我的旧Android系统构建。今天我正在构建新的架构,我在gradle中进行了正确的配置,并且我解压了我的apk,我可以在中找到我的库。我没有这个库的源代码,所以我使用了以前为构建的源代码。但我得到的错误如下: <代码>2020-11-17 20:56:23.039 130 83-13556/?w/system.err:java.lang.unsatistifiedLinkEr
我正在使用Maven3.3.9,并使用Eclipse在Spring工具套件中创建了一个Maven Web项目。 最近我读了一个关于用maven项目配置JPA的教程。 显示JPA配置的教程 我使用Eclipselink2.5成功配置了数据库连接 我面临的问题是,在单击ok之后,使用项目方面属性配置JPA2.1。persistence.xml是在src/main/java的META-INF下自动创建的
我试图改变我的应用程序,以支持32位和64位,但当我改变build.gradle这样。 但当我对其进行分级时,错误将显示如下 错误: 在DefaultConfig_Decorated{name=main,dimension=null,minSdkVersion=DefaultApiVersion{mApiLevel=15,mCodename='null'},targetSdkVersion=Def