3

I am using android ndk in eclipse. I got my project compiled but am facing errors at run time. I have the libcrytpoNative.so and libsslNative.so files but I am getting this error about libcrypto.so.1.0.0 not found error. How should I fix this?

This is the output of ndk-build V=1

    Android NDK: WARNING: APP_PLATFORM android-21 is larger than android:minSdkVersion 14 in ./AndroidManifest.xml    
    rm -f ./libs/arm64-v8a/lib*.so ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/armeabi-v7a-hard/lib*.so ./libs/mips/lib*.so ./libs/mips64/lib*.so ./libs/x86/lib*.so ./libs/x86_64/lib*.so
    rm -f ./libs/arm64-v8a/gdbserver ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/armeabi-v7a-hard/gdbserver ./libs/mips/gdbserver ./libs/mips64/gdbserver ./libs/x86/gdbserver ./libs/x86_64/gdbserver
    rm -f ./libs/arm64-v8a/gdb.setup ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/armeabi-v7a-hard/gdb.setup ./libs/mips/gdb.setup ./libs/mips64/gdb.setup ./libs/x86/gdb.setup ./libs/x86_64/gdb.setup
    [armeabi-v7a] Install        : libcpabe.so => libs/armeabi-v7a/libcpabe.so
    install -p ./obj/local/armeabi-v7a/libcpabe.so ./libs/armeabi-v7a/libcpabe.so
    /home/yogi/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libcpabe.so
    [armeabi-v7a] Install        : libcryptoNative.so => libs/armeabi-v7a/libcryptoNative.so
    install -p ./obj/local/armeabi-v7a/libcryptoNative.so ./libs/armeabi-v7a/libcryptoNative.so
    /home/yogi/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libcryptoNative.so
    [armeabi-v7a] Install        : libglib.so => libs/armeabi-v7a/libglib.so
    install -p ./obj/local/armeabi-v7a/libglib.so ./libs/armeabi-v7a/libglib.so
    /home/yogi/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libglib.so
    [armeabi-v7a] Install        : libgmp.so => libs/armeabi-v7a/libgmp.so
    install -p ./obj/local/armeabi-v7a/libgmp.so ./libs/armeabi-v7a/libgmp.so
    /home/yogi/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libgmp.so
    [armeabi-v7a] Install        : libpbc.so => libs/armeabi-v7a/libpbc.so
    install -p ./obj/local/armeabi-v7a/libpbc.so ./libs/armeabi-v7a/libpbc.so
    /home/yogi/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libpbc.so
    [armeabi-v7a] Install        : libsslNative.so => libs/armeabi-v7a/libsslNative.so
    install -p ./obj/local/armeabi-v7a/libsslNative.so ./libs/armeabi-v7a/libsslNative.so
    /home/yogi/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libsslNative.so

This is the MainActivity.java that loads libs:

package com.example.myproject;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends Activity {

    static {
        System.loadLibrary("gmp");             
//        System.loadLibrary("ssl");
//        System.loadLibrary("crypto");
        System.loadLibrary("glib");
        System.loadLibrary("pbc"); 
        System.loadLibrary("sslNative");
        System.loadLibrary("cryptoNative");
        System.loadLibrary("cpabe");          
    }

    //System.loadLibrary("ssl_static");


    public static native void InitMainActivityjni();
    public native String cpabeNative();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        TextView  tv = new TextView(this);
        tv.setText(cpabeNative());
        setContentView(tv);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

Thanks

re3el
  • 695
  • 1
  • 10
  • 27
  • What are the lines that load these library at runtime ? In (at least) one of your java files you should have something like `System.loadLibray(libname)`. – sonic Oct 13 '15 at 13:49
  • Also see [Changing OpenSSL library in Android app for HttpClient](http://stackoverflow.com/a/28392326/608639). It discusses Zygote and problems with supplying your own copies of `libcrytpo.so` and `libssl.so`. – jww Oct 13 '15 at 13:50
  • @sonic: System.loadLibray("ssl"); System.loadLibray("crypto"); – re3el Oct 13 '15 at 13:59
  • Drop into the command line, and run `ndk-build V=1` by hand. Then, post the results to Pastebin. (Does Stack Overflow have a Pastebin like-service?) – jww Oct 13 '15 at 14:06
  • @jww: yes, as you mentioned I guess it initializes with system/openssl. I find it too complex to understand from your answer. If possible could you share the files for armeabi-v7? Sorry for the trouble – re3el Oct 13 '15 at 14:06
  • @jww: edited the post. Kindly check – re3el Oct 13 '15 at 14:10
  • I edited libssl.so to libsslNative.so(similarly with libcrypto.so) thinking that it can get linked to this module rather than the system module as mentioned by a post elsewhere. But even that didn't help. – re3el Oct 13 '15 at 14:13
  • The `ndk-build` looks good to me. Add your Java code with the static initializer that shows how you load them (and other libraries). – jww Oct 13 '15 at 14:18
  • @jww: added the Java file. – re3el Oct 13 '15 at 14:22

1 Answers1

10

I had a similar problem. Android does not like versioned library files, and changing the file name of the .so lib alone will not do in this case. A nice trick you can do to see the actual name assigned to the library is by running readelf (if your .so file is in elf format, if not, see this post for other options).

Once you run this, you will need to look for items appearing under DEPEND & SONAME. If you see the versioned .so.1.0.0 name, then keep on reading, salvation is near :)

Now, you basically have two choices - either recompile your libcrypto.so & libssl.so again, this time adding the appropriate flags preventing it from appending the version suffix, or edit the libs to remove the version suffix. I will show how to to do the 2nd option.

Ensure you have the rpl command line tool installed. If it isnt, run:

brew install rpl

You might need to run this with sudo.

Once this tool is installed, you will need to use it to edit the symbols in both the ssl & crypto libraries like so:

rpl -R -e .so.1.0.0 "_1_0_0.so" /path/to/libssl.so
rpl -R -e .so.1.0.0 "_1_0_0.so" /path/to/libcrypto.so

Almost done!

Run the readelf tool again to make sure the symbols have been properly changed. The only thing left to do now is to change the actual file names to libssl_1_0_0.so & libcrypto_1_0_0.so, and when loading the library, make sure to use the adjusted file names:

System.loadLibrary("ssl_1_0_0");
System.loadLibrary("crypto_1_0_0");

Things should work now. Hope this solves your problem.

Community
  • 1
  • 1
Gil Moshayof
  • 16,433
  • 4
  • 44
  • 57
  • Thanks, this saves my life. It solves my issue: load conflict name with system AOS 5.x – kairen Oct 18 '17 at 08:38
  • "Now, you basically have two choices - either recompile your libcrypto.so & libssl.so again, this time adding the appropriate flags preventing it from appending the version suffix," Do you know how to do this? I haven't been able to figure this out openssl 1.1.1. I can' t find anything in the documentation for it either. – Matt Wolfe Mar 24 '20 at 18:50