Android build issues with OpenSSL on 5.0/5.1



  • When I try to start my application on an Android phone running 5.0 or 5.1 I get the following error, on version 6.0/7.0 the application starts/works just fine. I have tried NDK r10e and Crystax, but both have the same issue.

    E/art     (18856): dlopen("/data/app/org.qtproject.example-1/lib/arm/libMyName.so", RTLD_LAZY) failed: dlopen failed: cannot locate symbol "RSA_generate_key" referenced by "libMyName.so"...
    D/AndroidRuntime(18856): Shutting down VM
    E/AndroidRuntime(18856): FATAL EXCEPTION: main
    E/AndroidRuntime(18856): Process: org.qtproject.example, PID: 18856
    E/AndroidRuntime(18856): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "RSA_generate_key" referenced by "libMyName.so"...
    E/AndroidRuntime(18856): 	at java.lang.Runtime.loadLibrary(Runtime.java:371)
    E/AndroidRuntime(18856): 	at java.lang.System.loadLibrary(System.java:988)
    E/AndroidRuntime(18856): 	at org.qtproject.qt5.android.bindings.QtLoader.loadApplication(QtLoader.java:245)
    E/AndroidRuntime(18856): 	at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:655)
    E/AndroidRuntime(18856): 	at org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:183)
    E/AndroidRuntime(18856): 	at org.qtproject.qt5.android.bindings.QtActivity.onCreateHook(QtActivity.java:266)
    E/AndroidRuntime(18856): 	at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:273)
    E/AndroidRuntime(18856): 	at android.app.Activity.performCreate(Activity.java:5990)
    E/AndroidRuntime(18856): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    E/AndroidRuntime(18856): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
    E/AndroidRuntime(18856): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
    E/AndroidRuntime(18856): 	at android.app.ActivityThread.access$800(ActivityThread.java:151)
    E/AndroidRuntime(18856): 	at android.app.ActivityThread$H.handleMessage2(ActivityThread.java:1303)
    E/AndroidRuntime(18856): 	at android.os.Handler.dispatchMessage(Handler.java:102)
    E/AndroidRuntime(18856): 	at android.os.Looper.loop(Looper.java:135)
    E/AndroidRuntime(18856): 	at android.app.ActivityThread.main(ActivityThread.java:5254)
    E/AndroidRuntime(18856): 	at java.lang.reflect.Method.invoke(Native Method)
    E/AndroidRuntime(18856): 	at java.lang.reflect.Method.invoke(Method.java:372)
    E/AndroidRuntime(18856): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    E/AndroidRuntime(18856): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    W/ActivityManager(  585):   Force finishing activity 1 org.qtproject.example/org.my.MyNameActivity
    

    I have these 2 in my .pro file so the library is added

    
    ANDROID_EXTRA_LIBS += /path/to/sysroot/lib/libcrypto.so
    ANDROID_EXTRA_LIBS += /path/to/sysroot/lib/libssl.so
    

    Also checking the .so file itself the function seems to be there

    ./arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-readelf -all /path/to/sysroot/lib/libcrypto.so | grep RSA_generate_key
      1020: 0009c0f4  1504 FUNC    GLOBAL DEFAULT    7 RSA_generate_key_ex
      1084: 000a00fc   220 FUNC    GLOBAL DEFAULT    7 RSA_generate_key
      9625: 0009c0f4  1504 FUNC    GLOBAL DEFAULT    7 RSA_generate_key_ex
      9689: 000a00fc   220 FUNC    GLOBAL DEFAULT    7 RSA_generate_key
    

    Any idea what might be the issue? As I see 5.1 still has a lot of users.

    Also I'm using PyQt with a modified Python install (which uses that function) but it still seems weird that 5.1 fails and 6.0 works.


  • Moderators

    The problem is that Android 5 ships with a default build of old OpenSSL release (something around 1.0.0). Since these are system libs, they get picked up before your .so files. And that's why you get a missing symbol - because wrong OpenSSL was loaded by the Android system.

    I did solve this issue once, but I don't remember how, I'll try to find my solution and come back here :-)



  • I implemented my custom function using RSA_generate_key_ex instead and the application works now (I'm guessing the OpenSSL on Android 5.0 was built without deprecated functions).

    This is kind of a workaround of the original issue tho, if you find your old solution please share :)


  • Moderators

    @kviktor said in Android build issues with OpenSSL on 5.0/5.1:

    if you find your old solution please share :)

    Uh... I just did. Turns out that the function which was missing for me was not really necessary so I removed it. So in that sense it's the same solution you used.

    As far as I know there are 2 proper solutions:

    • recompile Qt with custom (static) OpenSSL build and use it to build your project (make sure you only link to OpenSSL statically)
    • create a custom wrapper for OpenSSL functions you need, link it statically to OpenSSL and to your app

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.