Wan Ammar
Wan Ammar

Reputation: 23

PN532 Library Synchronization with Android Application Failed

This question is a related to my previous question. I have made a CMakeList.txt and also native-lib.cpp and upload it in my Android application to synchronize the nfclib for android that was downloaded from the github

Here is my 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
)

and here is my native-lib.cpp:

#include <jni.h>
#include <nfc/nfc.h>  // 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");
   }

but, still an error pops out while syncing the gradle files with the project:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.

Upvotes: 0

Views: 59

Answers (0)

Related Questions