Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Import C++/Qt libary into Java Android
QtWS25 Last Chance

Import C++/Qt libary into Java Android

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 188 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tien TU
    wrote on last edited by Tien TU
    #1

    I created a shared library in C++ with Qt Creator and build for Android. This library works when I import it into an Android application created in Qt Creator.

    I defined MYLIBSHARED_EXPORT in mylib_global.h and include mylib_global.h in mylib.h

    MYLIBSHARED_EXPORT const char* info();    // in mylib.h
    
    const char* info()                        // in mylib.cpp
    {
        qDebug() << "You call info";
        const char* name = "MyLib";
        return name;
    }
    

    I can call the info() from an Android application created in Qt Creator. Here is the part I add in the .pro to import the .so file:

    INCLUDEPATH += home/myname/Projects/Qt/MyLib
    LIBS += -L/home/myname/Projects/Qt/build-MyLib/android-build/libs/armeabi-v7a -lMyLib_armeabi-v7a
    ANDROID_EXTRA_LIBS += /home/myname/Projects/Qt/build-MyLib/android-build/libs/armeabi-v7a/libMyLib_armeabi-v7a.so
    

    Next, I added a function with jni interface:

    JNIEXPORT void JNICALL                    // in mylib.h
    Java_com_mylib_sendIntToClib(JNIEnv *env, jobject thisObj, jint n);
    
    JNIEXPORT void JNICALL                    // in mylib.cpp
    Java_com_mylib_sendIntToClib(JNIEnv *env, jobject thisObj, jint n) {
        __android_log_print(ANDROID_LOG_INFO, "mylib", "%d received by clib", n);
    }
    

    My first question is how can I call this function from an Android application created in Qt Creator?

    For the very convenient, my second question is if I could import this library into an Android application created in Android Studio? (I made some tries but it seems that the QtCore library does not work on Android.)

    Can you help me ?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved