Ошибка синхронизации библиотеки PN532 с приложением AndroidAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Ошибка синхронизации библиотеки PN532 с приложением Android

Сообщение Anonymous »

Этот вопрос связан с моим предыдущим вопросом. Я создал CMakeList.txt, а также Native-lib.cpp и загрузил их в свое приложение для Android
, чтобы синхронизировать nfclib для Android, загруженный с githubВот мой CMakeList.txt:
# Minimum version of CMake required
cmake_minimum_required(VERSION 3.18.1)

# Project name
project(nfc_app)

# Specify the library to be built as a shared library
add_library(
# Name of the library to be built (native JNI library)
nfc_native_lib # This should be a logical name for the library

# Build as a shared library
SHARED

# Add your native source files here
src/main/cpp/native-lib.cpp # Ensure this is the correct path
)

# Set the path to the libnfc header files (should point to headers, not .so)
include_directories(
${CMAKE_SOURCE_DIR}/src/main/jniLibs/libnfc.so/libnfc/pn532.h # Path to libnfc headers (.h files)
)

# Find the libnfc library
find_library(
libnfc-lib # Variable to store the result of the find
nfc # Name of the library (libnfc.so is what will be searched)
PATHS ${CMAKE_SOURCE_DIR}/src/main/jniLibs/armeabi-v7a # Path where .so file is located
)

# Set path to additional libraries if required (for example, if libnfc is in a custom directory)
# You can adjust this path as per your project structure
link_directories(${CMAKE_SOURCE_DIR}/src/main/jniLibs/arm64-v8a)

# Link the native library with libnfc and any other necessary libraries (e.g., log for logging)
target_link_libraries(
nfc_native_lib # The JNI library you're building (same name as in add_library)
${libnfc-lib} # Link libnfc (found using find_library)
log # Optional: Android NDK logging library
)

а вот мой родной-lib.cpp:
#include
#include // Include libnfc headers

JNIEXPORT jstring extern "C" JNICALL
Java_com_example_nfc_app_MainActivity_readNFC(JNIEnv *env, jobject thiz)
// Use libnfc functions here
nfc_device *device = NULL; // Declare the NFC device pointe

// Initialize libnfc, interact with the NFC reader (PN532), etc.
nfc_context *context;
nfc_init(&context);

if (context == NULL) {
return env->NewStringUTF("Failed to initialize libnfc");
}

// Open the NFC device
device = nfc_open(context, NULL); // NULL means using the first available device
if (device == NULL) {
nfc_exit(context);
return env->NewStringUTF("Failed to open NFC device");
}

но при синхронизации файлов Gradle с проектом все равно выскакивает ошибка:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.


Подробнее здесь: https://stackoverflow.com/questions/790 ... ion-failed
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»