We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2053

Summary: Android can't find SDL2's JNI functions by name
Product: SDL Reporter: Dan Hatch <danhatch333>
Component: *don't know*Assignee: Gabriel Jacobo <gabomdq>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gabomdq
Version: 2.0.0   
Hardware: x86_64   
OS: Linux   

Description Dan Hatch 2013-08-22 06:15:18 UTC
I've replaced sdl-hg with the SDL2-2.0.0 source in my android project and did a full recompile(had to reflect change of 'SDL2/src/main/android/SDL_android_main.c'). When I run the app, it crashes on both a real device and the emulator.

My project is C++, which might be mangling the JNI glue function names. If I add 'extern "C"' though I get a bunch of syntax errors which suggests it's being compiled as C, so maybe this isn't the problem?


Error on Real Device:
I/SDL     (20310): SDL_Android_Init()
W/IInputConnectionWrapper(20149): showStatusIcon on inactive InputConnection
W/SDL     (20310): SDL: Couldn't locate Java callbacks, check that they're named and typed correctly
I/SDL     (20310): SDL_Android_Init() finished!
I/DEBUG   (20203): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***


Error in Emulator:
I/SDL     (  410): SDL_Android_Init()
W/dalvikvm(  410): JNI WARNING: JNI method called with exception raised
W/dalvikvm(  410):              in Lorg/libsdl/app/SDLActivity;.nativeInit ()V (GetStaticMethodID)
W/dalvikvm(  410): Pending exception is:
I/dalvikvm(  410): Ljava/lang/NoSuchMethodError;: audioInit
I/dalvikvm(  410): 	at org.libsdl.app.SDLActivity.nativeInit(Native Method)
I/dalvikvm(  410): 	at org.libsdl.app.SDLMain.run(SDLActivity.java:516)
I/dalvikvm(  410): 	at java.lang.Thread.run(Thread.java:1019)
I/dalvikvm(  410): "SDLThread" prio=5 tid=9 NATIVE
I/dalvikvm(  410):   | group="main" sCount=0 dsCount=0 obj=0x40522488 self=0x2a2110
I/dalvikvm(  410):   | sysTid=418 nice=0 sched=0/0 cgrp=default handle=2760072
I/dalvikvm(  410):   | schedstat=( 4012991 82880980 8 )
I/dalvikvm(  410):   at org.libsdl.app.SDLActivity.nativeInit(Native Method)
I/dalvikvm(  410):   at org.libsdl.app.SDLMain.run(SDLActivity.java:516)
I/dalvikvm(  410):   at java.lang.Thread.run(Thread.java:1019)
Comment 1 Gabriel Jacobo 2013-08-22 13:02:50 UTC
It doesn't look like it's a C++ problem. The error says that the C code couldn't get a hold of the audioInit method on the Java side. Are you using the stock SDLActivity.java file? Any customizations to the Android project file?
Comment 2 Dan Hatch 2013-08-22 17:49:04 UTC
Thank you! Updating SDLActivity.java fixed it.