问题
I have a problem creating an Android app that makes use of both Renderscript and native code generated with NDK.
Substantially, I use NDK tools to generate a library called sprstr_native.so
. I managed to call their C++ functions through Java code without problems. Then I needed some Renderscript functionalities (in particular, ScriptIntrinsicYuvToRGB
) so I've added to my Eclipse project a reference to the relative support library, renderscript-v8.jar
, and this line in the project properties file:
renderscript.support.mode=true
Now the problem: Android can't recognize my sprstr_native
anymore and the app crashes when calling the code:
System.loadLibrary("sprstr_native");
This is the stack:
11-23 17:46:54.450: E/AndroidRuntime(3901): FATAL EXCEPTION: main
11-23 17:46:54.450: E/AndroidRuntime(3901): java.lang.ExceptionInInitializerError
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.Class.newInstanceImpl(Native Method)
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.Class.newInstance(Class.java:1409)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.os.Looper.loop(Looper.java:130)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.reflect.Method.invokeNative(Native Method)
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.reflect.Method.invoke(Method.java:507)
11-23 17:46:54.450: E/AndroidRuntime(3901): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-23 17:46:54.450: E/AndroidRuntime(3901): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-23 17:46:54.450: E/AndroidRuntime(3901): at dalvik.system.NativeStart.main(Native Method)
11-23 17:46:54.450: E/AndroidRuntime(3901): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load sprstr_native: findLibrary returned null
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.Runtime.loadLibrary(Runtime.java:429)
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.System.loadLibrary(System.java:554)
11-23 17:46:54.450: E/AndroidRuntime(3901): at com.lag.proj.MainActivity.<clinit>(MainActivity.java:18)
11-23 17:46:54.450: E/AndroidRuntime(3901): ... 15 more
Curiously, if I delete all the references to Renderscript the native lib turns to work again! Please don't tell me that there are incompatibilities between Renderscript and NDK code!
回答1:
I've probably solved it, but not without other errors that came after (see Getting different errors for different platforms using Renderscript Support Library). By the way, the library loading phase should be solved by adding this line on the Application.mk
file:
APP_ABI := all
That lets the NDK to compile the objs for all the supported architectures.
来源:https://stackoverflow.com/questions/20165072/is-renderscript-incompatible-with-ndk-libraries-in-the-same-project