Этот вопрос связан с моим предыдущим вопросом. Я создал 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
Ошибка синхронизации библиотеки PN532 с приложением Android ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1729068723
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.
Подробнее здесь: [url]https://stackoverflow.com/questions/79092379/pn532-library-synchronization-with-android-application-failed[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия