@@ -10,8 +10,7 @@ If you are using the older ant build process, it is no longer officially
10
10
supported, but you can use the "android-project-ant" directory as a template.
11
11
12
12
13
- ================================================================================
14
- Requirements
13
+ Requirements
15
14
================================================================================
16
15
17
16
Android SDK (version 26 or later)
@@ -23,8 +22,7 @@ https://developer.android.com/tools/sdk/ndk/index.html
23
22
Minimum API level supported by SDL: 16 (Android 4.1)
24
23
25
24
26
- ================================================================================
27
- How the port works
25
+ How the port works
28
26
================================================================================
29
27
30
28
- Android applications are Java-based, optionally with parts written in C
@@ -42,8 +40,7 @@ dispatches to native functions implemented in the SDL library:
42
40
src/core/android/SDL_android.c
43
41
44
42
45
- ================================================================================
46
- Building an app
43
+ Building an app
47
44
================================================================================
48
45
49
46
For simple projects you can use the script located at build-scripts/androidbuild.sh
@@ -120,8 +117,7 @@ Here's an explanation of the files in the Android project, so you can customize
120
117
src/main/java/org/libsdl/app/SDLActivity.java - the Java class handling the initialization and binding to SDL. Be very careful changing this, as the SDL library relies on this implementation. You should instead subclass this for your application.
121
118
122
119
123
- ================================================================================
124
- Customizing your application name
120
+ Customizing your application name
125
121
================================================================================
126
122
127
123
To customize your application name, edit AndroidManifest.xml and replace
@@ -151,17 +147,15 @@ Then replace "SDLActivity" in AndroidManifest.xml with the name of your
151
147
class, .e.g. "MyGame"
152
148
153
149
154
- ================================================================================
155
- Customizing your application icon
150
+ Customizing your application icon
156
151
================================================================================
157
152
158
153
Conceptually changing your icon is just replacing the "ic_launcher.png" files in
159
154
the drawable directories under the res directory. There are several directories
160
155
for different screen sizes.
161
156
162
157
163
- ================================================================================
164
- Loading assets
158
+ Loading assets
165
159
================================================================================
166
160
167
161
Any files you put in the "app/src/main/assets" directory of your project
@@ -189,8 +183,7 @@ disable this behaviour, see for example:
189
183
http://ponystyle.com/blog/2010/03/26/dealing-with-asset-compression-in-android-apps/
190
184
191
185
192
- ================================================================================
193
- Pause / Resume behaviour
186
+ Pause / Resume behaviour
194
187
================================================================================
195
188
196
189
If SDL_HINT_ANDROID_BLOCK_ON_PAUSE hint is set (the default),
@@ -205,13 +198,37 @@ app can continue to operate as it was.
205
198
206
199
However, there's a chance (on older hardware, or on systems under heavy load),
207
200
where the GL context can not be restored. In that case you have to listen for
208
- a specific message, (which is not yet implemented!) and restore your textures
209
- manually or quit the app (which is actually the kind of behaviour you'll see
210
- under iOS, if the OS can not restore your GL context it will just kill your app)
201
+ a specific message (SDL_RENDER_DEVICE_RESET) and restore your textures
202
+ manually or quit the app.
211
203
204
+ You should not use the SDL renderer API while the app going in background:
205
+ - SDL_APP_WILLENTERBACKGROUND:
206
+ after you read this message, GL context gets backed-up and you should not
207
+ use the SDL renderer API.
212
208
209
+ - SDL_APP_DIDENTERFOREGROUND:
210
+ GL context is restored, and the SDL renderer API is available (unless you
211
+ receive SDL_RENDER_DEVICE_RESET).
212
+
213
+ Mouse / Touch events
214
+ ================================================================================
215
+
216
+ In some case, SDL generates synthetic mouse (resp. touch) events for touch
217
+ (resp. mouse) devices.
218
+ To enable/disable this behavior, see SDL_hints.h:
219
+ - SDL_HINT_TOUCH_MOUSE_EVENTS
220
+ - SDL_HINT_MOUSE_TOUCH_EVENTS
221
+
222
+ Misc
213
223
================================================================================
214
- Threads and the Java VM
224
+
225
+ For some device, it appears to works better setting explicitly GL attributes
226
+ before creating a window:
227
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
228
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
229
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
230
+
231
+ Threads and the Java VM
215
232
================================================================================
216
233
217
234
For a quick tour on how Linux native threads interoperate with the Java VM, take
@@ -226,8 +243,17 @@ your thread automatically anyway (when you make an SDL call), but it'll never
226
243
detach it.
227
244
228
245
229
- ================================================================================
230
- Using STL
246
+ If you ever want to use JNI in a native thread (created by "SDL_CreateThread()"),
247
+ it won't be able to find your java class and method because of the java class loader
248
+ which is different for native threads, than for java threads (eg your "main()").
249
+
250
+ the work-around is to find class/method, in you "main()" thread, and to use them
251
+ in your native thread.
252
+
253
+ see:
254
+ https://developer.android.com/training/articles/perf-jni#faq:-why-didnt-findclass-find-my-class
255
+
256
+ Using STL
231
257
================================================================================
232
258
233
259
You can use STL in your project by creating an Application.mk file in the jni
@@ -239,8 +265,7 @@ For more information go here:
239
265
https://developer.android.com/ndk/guides/cpp-support
240
266
241
267
242
- ================================================================================
243
- Using the emulator
268
+ Using the emulator
244
269
================================================================================
245
270
246
271
There are some good tips and tricks for getting the most out of the
@@ -252,8 +277,7 @@ Notice that this software emulator is incredibly slow and needs a lot of disk sp
252
277
Using a real device works better.
253
278
254
279
255
- ================================================================================
256
- Troubleshooting
280
+ Troubleshooting
257
281
================================================================================
258
282
259
283
You can see if adb can see any devices with the following command:
@@ -332,8 +356,7 @@ If you need to build without optimization turned on, you can create a file calle
332
356
APP_OPTIM := debug
333
357
334
358
335
- ================================================================================
336
- Memory debugging
359
+ Memory debugging
337
360
================================================================================
338
361
339
362
The best (and slowest) way to debug memory issues on Android is valgrind.
@@ -384,8 +407,7 @@ When you're done instrumenting with valgrind, you can disable the wrapper:
384
407
adb shell setprop wrap.org.libsdl.app ""
385
408
386
409
387
- ================================================================================
388
- Graphics debugging
410
+ Graphics debugging
389
411
================================================================================
390
412
391
413
If you are developing on a compatible Tegra-based tablet, NVidia provides
@@ -398,8 +420,7 @@ The Tegra Graphics Debugger is available from NVidia here:
398
420
https://developer.nvidia.com/tegra-graphics-debugger
399
421
400
422
401
- ================================================================================
402
- Why is API level 16 the minimum required?
423
+ Why is API level 16 the minimum required?
403
424
================================================================================
404
425
405
426
The latest NDK toolchain doesn't support targeting earlier than API level 16.
@@ -408,8 +429,7 @@ about 99% of the Android devices accessing Google Play support API level 16 or
408
429
higher (January 2018).
409
430
410
431
411
- ================================================================================
412
- A note regarding the use of the "dirty rectangles" rendering technique
432
+ A note regarding the use of the "dirty rectangles" rendering technique
413
433
================================================================================
414
434
415
435
If your app uses a variation of the "dirty rectangles" rendering technique,
@@ -427,8 +447,7 @@ screen each frame.
427
447
Reference: http://www.khronos.org/registry/egl/specs/EGLTechNote0001.html
428
448
429
449
430
- ================================================================================
431
- Ending your application
450
+ Ending your application
432
451
================================================================================
433
452
434
453
Two legitimate ways:
@@ -445,8 +464,7 @@ Don't call exit() as it stops the activity badly.
445
464
NB: "Back button" can be handled as a SDL_KEYDOWN/UP events, with Keycode
446
465
SDLK_AC_BACK, for any purpose.
447
466
448
- ================================================================================
449
- Known issues
467
+ Known issues
450
468
================================================================================
451
469
452
470
- The number of buttons reported for each joystick is hardcoded to be 36, which
0 commit comments