Issue
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
Solution
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.
Answered By - Gil Moshayof
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.