Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

load shared library in android with dlopen



  • I'm trying to load a shared library on android with dlopen.

    here is my code:

    QFile ddd("/data/data/org.qtproject.example.Mobiledinamicload/files/libuntitled1armv7a.so");
        qDebug()<<ddd.exists();
    
        void *libuntitled1 = dlopen("/data/user/0/org.qtproject.example.Mobiledinamicload/files/libuntitled1armv7a.so", RTLD_LAZY);
            if (!libuntitled1) {
                qDebug()<<"szzzzzzzzzzz";
            }
    

    but not works and writes this errors on console:

    D libMobile_dinamic_load_armeabi-v7a.so: true
    D libMobile_dinamic_load_armeabi-v7a.so: szzzzzzzzzzz
    I qtMainLoopThrea: type=1400 audit(0.0:37736): avc: denied { open } for path="/data/data/org.qtproject.example.Mobiledinamicload/files/libuntitled1armv7a.so" dev="mmcblk0p19" ino=245815 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0 tclass=file permissive=1
    

    it works on android studio and i can use the library :

    extern "C" JNIEXPORT jstring JNICALL
    Java_aaa_bbb_testnativecppqt_MainActivity_stringFromJNI(
            JNIEnv* env,
            jobject /* this */) {
        std::string hello_str ="Hello from C++ shared library";
    
    
        void *libuntitled1 = dlopen("/data/data/aaa.bbb.testnativecppqt/files/libuntitled1armv7a.so", RTLD_LAZY);
        if (!libuntitled1) {
            hello_str ="cant load shared library";
            return env->NewStringUTF(hello_str.c_str());
        }
    
    // call functions from library
    
        return env->NewStringUTF(hello_str.c_str());
    }
    

    load with QLibrary not works too:

            auto path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
            QString fileName= path+"/libuntitled1armv7a.so";
            QFile ddd(fileName);
            qDebug()<<ddd.exists();
        QLibrary myLib(fileName);
        qDebug()<<myLib.isLibrary(fileName);
        qDebug()<<myLib.load();
        qDebug()<<myLib.errorString();
    

    here is the error of QLibrary:

    D libMobile_dinamic_load_armeabi-v7a.so: true
    D libMobile_dinamic_load_armeabi-v7a.so: true
    I qtMainLoopThrea: type=1400 audit(0.0:38721): avc: denied { open } for path="/data/data/org.qtproject.example.Mobiledinamicload/files/libuntitled1armv7a.so" dev="mmcblk0p19" ino=245778 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0 tclass=file permissive=1
    D libMobile_dinamic_load_armeabi-v7a.so: false
    D libMobile_dinamic_load_armeabi-v7a.so: "Cannot load library /data/user/0/org.qtproject.example.Mobiledinamicload/files: (dlopen failed: library \"_data_user_0_org.qtproject.example.Mobiledinamicload_files\" not found)"
    

    --> my phone is rooted and i can copy any file to any path manually and change files permissions


  • Lifetime Qt Champion

    You are showing 3 different libraries:



  • @jsulm
    All these files are the same.
    I changed the name of the library during various tests and I wrote down the errors elsewhere.
    I forgot to correct them when writing this topic.
    Thanks for letting me know.
    I corrected them now.


Log in to reply