我在eclipse中使用android ndk。我编译了我的项目,但在运行时遇到了错误。我有libcrytpoNative.so
和libsslNative.so
个文件,但是我收到有关libcrypto.so.1.0.0
未找到错误的错误。我该如何解决这个问题?
这是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
这是加载libs的MainActivity.java:
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);
}
}
由于
答案 0 :(得分:9)
我有类似的问题。 Android不喜欢版本化的库文件,在这种情况下,单独更改.so lib的文件名是不行的。您可以通过运行readelf
来查看分配给库的实际名称的一个很好的技巧(如果您的.so文件是elf格式,如果没有,请参阅this发布其他选项)。 / p>
运行此功能后,您需要查找DEPEND
& SONAME
。如果你看到版本化的.so.1.0.0名称,那么继续阅读,救恩就在附近:)
现在,你基本上有两个选择 - 重新编译你的libcrypto.so& libssl.so再次,这次添加适当的标志,以防止它附加版本后缀,或编辑库以删除版本后缀。我将展示如何做第二个选项。
确保安装了rpl
命令行工具。如果不是,请运行:
brew install rpl
您可能需要使用sudo
运行此功能。
安装此工具后,您需要使用它来编辑ssl和amp;中的符号。像这样的加密库:
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
差不多完成了!
再次运行readelf
工具以确保符号已正确更改。现在唯一要做的就是将实际文件名更改为libssl_1_0_0.so
& libcrypto_1_0_0.so
,加载库时,请务必使用调整后的文件名:
System.loadLibrary("ssl_1_0_0");
System.loadLibrary("crypto_1_0_0");
现在应该有用了。希望这能解决你的问题。