Hi everyone,
Java and Android development are definitely not my
forte therefore forgive me if what I'm asking is obvious or has been
covered elsewhere. I'm stumbling a little in the dark here and would
appreciate any light.
I'm trying to get the xcb library to work on Android.
I've
built the library using the Android NDK and now want to try it out
under an Android-x86 (or the emulator that comes with Android SDK) image
I have running via VirtualBox on my Debian Linux amd64 unstable setup.
The
combination of Bridj with JNAerator sounded like a good way to be able
to use my native library via java. I used the following to generate a
.jar for my library.
java -jar /home/jeetu/utils/JNAerator/
jnaerator-0.11-shaded.jar -f -library xcb ../src/xcb.h -o . -v -mode StandaloneJar -runtime BridJ -I/usr/include -parseChunks
I then created a sample Hello World example program using Eclipse and made sure it works as is under my test environment.
I
then went on to copy xcb.jar to the libs directory for my project
(myfirstapp) and I can see xcb.jar under Properties->Java Build
Path->Libraries as has been advised on online resources.
Unfortunately my .apk fails with the log pasted below. Apparently it is unable to initialize / find bridj.
There are a couple of things that I have playing on the back of the mind as possible things I'm doing wrong :
-
I realize that there is a bridj-0.6.2-android.jar available for
download on the bridj site however I am not clear how to use this with
JNAerator. Therefore what I am doing is simply leaving JNAerator to use
whatever bridj engine it uses when you specify a -runtime BridJ. Is this
correct or should I somehow be forcing it to use the -android.jar? How
would I do this?
- On the site I have seen mention of including
the bridj-0.6.2-android.jar to my libs directory as well. When I do this
I get the following error.
[2014-08-06 00:29:46 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/bridj/BridJRuntime;
[2014-08-06
00:29:46 - myfirstapp] Conversion to Dalvik format failed: Unable to
execute dex: Multiple dex files define Lorg/bridj/BridJRuntime;
I would appreciate if somehow could guide me on how to work this out since I can't figure out what to do next :)
Thank you.
- jeetu
--------------------------Log output--------------------------------------------------------------------------------------
W/audio_hw_primary( 989): out_write() limiting sleep time 23262 to 23219
W/System.err( 2733): java.lang.RuntimeException: Failed to initialize BridJ
W/System.err( 2733): at org.bridj.Platform.initLibrary(Platform.java:370)
W/System.err( 2733): at org.bridj.Platform.<clinit>(Platform.java:175)
W/System.err( 2733): at org.bridj.Pointer.<clinit>(Pointer.java:179)
W/System.err( 2733): at
com.example.myfirstapp.MainActivity.onCreate(MainActivity.java:30)
W/System.err( 2733): at
android.app.Activity.performCreate(Activity.java:5231)
W/System.err( 2733): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
W/System.err( 2733): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
W/System.err( 2733): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
W/System.err( 2733): at
android.app.ActivityThread.access$800(ActivityThread.java:135)
W/System.err( 2733): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
W/System.err( 2733): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err( 2733): at android.os.Looper.loop(Looper.java:136)
W/System.err( 2733): at
android.app.ActivityThread.main(ActivityThread.java:5017)
W/System.err( 2733): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 2733): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err( 2733): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
W/System.err( 2733): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
W/System.err( 2733): at
de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
W/System.err( 2733): at dalvik.system.NativeStart.main(Native Method)
W/System.err( 2733): Caused by: java.lang.UnsatisfiedLinkError:
Couldn't load bridj from loader
dalvik.system.PathClassLoader[DexPathList[[zip file
"/data/app/com.example.myfirstapp-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfirstapp-2,
/vendor/lib, /system/lib, /system/lib/arm]]]: findLibrary returned
null
W/System.err( 2733): at java.lang.Runtime.loadLibrary(Runtime.java:358)
W/System.err( 2733): at java.lang.System.loadLibrary(System.java:526)
W/System.err( 2733): at org.bridj.Platform.initLibrary(Platform.java:355)
W/System.err( 2733): ... 18 more
W/dalvikvm( 2733): No implementation found for native
Lorg/bridj/Platform;.sizeOf_ptrdiff_t:()I
W/dalvikvm( 2733): Exception Ljava/lang/UnsatisfiedLinkError; thrown
while initializing Lorg/bridj/Platform;
W/dalvikvm( 2733): Exception Ljava/lang/UnsatisfiedLinkError; thrown
while initializing Lorg/bridj/Pointer;
D/AndroidRuntime( 2733): Shutting down VM
W/dalvikvm( 2733): threadid=1: thread exiting with uncaught exception
(group=0x42d60140)
E/AndroidRuntime( 2733): FATAL EXCEPTION: main
E/AndroidRuntime( 2733): Process: com.example.myfirstapp, PID: 2733
E/AndroidRuntime( 2733): java.lang.UnsatisfiedLinkError: Native method
not found: org.bridj.Platform.sizeOf_ptrdiff_t:()I
E/AndroidRuntime( 2733): at
org.bridj.Platform.sizeOf_ptrdiff_t(Native Method)
E/AndroidRuntime( 2733): at org.bridj.Platform.<clinit>(Platform.java:179)
E/AndroidRuntime( 2733): at org.bridj.Pointer.<clinit>(Pointer.java:179)
E/AndroidRuntime( 2733): at
com.example.myfirstapp.MainActivity.onCreate(MainActivity.java:30)
E/AndroidRuntime( 2733): at
android.app.Activity.performCreate(Activity.java:5231)
E/AndroidRuntime( 2733): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime( 2733): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
E/AndroidRuntime( 2733): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
E/AndroidRuntime( 2733): at
android.app.ActivityThread.access$800(ActivityThread.java:135)
E/AndroidRuntime( 2733): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/AndroidRuntime( 2733): at
android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 2733): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 2733): at
android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 2733): at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2733): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 2733): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 2733): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 2733): at
de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
E/AndroidRuntime( 2733): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 1301): Force finishing activity
com.example.myfirstapp/.MainActivity
W/audio_hw_primary( 989): out_write() limiting sleep time 24920 to 23219
W/audio_hw_primary( 989): out_write() limiting sleep time 25124 to 23219
W/audio_hw_primary( 989): out_write() limiting sleep time 23532 to 23219
I/WindowManager( 1301): Screenshot max retries 4 of Token{219fe750
ActivityRecord{21873dc0 u0 com.example.myfirstapp/.MainActivity t6 f}}
appWin=Window{21a544e0 u0 Starting com.example.myfirstapp} drawState=4
W/WindowManager( 1301): Screenshot failure taking screenshot for
(800x600) to layer 21010
W/audio_hw_primary( 989): out_write() limiting sleep time 23968 to 23219
W/audio_hw_primary( 989): out_write() limiting sleep time 24304 to 23219
W/ActivityManager( 1301): Activity pause timeout for
ActivityRecord{21873dc0 u0 com.example.myfirstapp/.MainActivity t6 f}
W/audio_hw_primary( 989): out_write() limiting sleep time 23808 to 23219
W/audio_hw_primary( 989): out_write() limiting sleep time 25032 to 23219
W/audio_hw_primary( 989): out_write() limiting sleep time 24896 to 23219
W/audio_hw_primary( 989): out_write() limiting sleep time 26212 to 23219
E/WindowManager( 1301): Starting window AppWindowToken{21bce1a8
token=Token{219fe750 ActivityRecord{21873dc0 u0
com.example.myfirstapp/.MainActivity t6}}} timed out
W/ActivityManager( 1301): Activity destroy timeout for
ActivityRecord{21873dc0 u0 com.example.myfirstapp/.MainActivity t6 f}