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 5515 - android build fails for API levels < 18 due to use of BluetoothGatt
Summary: android build fails for API levels < 18 due to use of BluetoothGatt
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: build (show other bugs)
Version: 2.0.15
Hardware: ARM Android (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-29 02:01 UTC by rose.garcia-eggl2fk
Modified: 2021-02-04 18:06 UTC (History)
1 user (show)

See Also:


Attachments
log from android-x86 version 4.4.4 (312.95 KB, text/plain)
2021-02-04 02:03 UTC, rose.garcia-eggl2fk
Details

Note You need to log in before you can comment on or make changes to this bug.
Description rose.garcia-eggl2fk 2021-01-29 02:01:09 UTC
according to https://developer.android.com/reference/android/bluetooth/BluetoothGatt this API was introduced in API level 18.
this causes a build failure targeting an older API, which SDL2 claims to support.
Comment 1 rose.garcia-eggl2fk 2021-01-29 14:55:05 UTC
after updating my toolchain to support android-18, i now get:

    [javac] /root/sdl2-android-hello/src/org/libsdl/app/SDLActivity.java:39: error: cannot find symbol
    [javac] import android.view.PointerIcon;
    [javac]                    ^
    [javac]   symbol:   class PointerIcon
    [javac]   location: package android.view

according to https://docs.microsoft.com/en-us/dotnet/api/android.views.pointericon?view=xamarin-android-sdk-9

(developer.android.com seems offline atm)

this was introduced in API level 24.

that's a real blocker for me as the device i target is api level 19, though i'd prefer to be able to compile for api level 16 at least.
Comment 2 rose.garcia-eggl2fk 2021-01-29 15:25:06 UTC
tracing back history from where this came from we find that commit related to https://bugzilla.libsdl.org/show_bug.cgi?id=4319 (and patch from there) broke it.

https://github.com/libsdl-org/SDL/commit/67a94893c0ec08cdbd98b013c518b032e5811d0a

the poster claims that SDL2 only supports API 26 and newer ??

in docs/README-android.md we find this:

> Minimum API level supported by SDL: 16 (Android 4.1)                                                                   
> Android SDK (version 26 or later)                                                                                      

so it seems sylvain confused SDK version with API level.
Comment 3 Sam Lantinga 2021-01-29 16:43:46 UTC
Yes, you need to use a newer SDK, but you can target down to Android 4.1.

FYI, the Google Play Store requires you to use SDK version 28 or newer, I believe.

When building with a newer SDK you should be able to compile, and then run on older devices. Is that not what you're seeing?
Comment 4 Sylvain 2021-01-29 16:56:15 UTC
Just tried and it seems to build fine for me with:
minSdkVersion=16
targetSdkVersion=18
compileSdkVersion=26
Comment 5 rose.garcia-eggl2fk 2021-01-29 21:33:44 UTC
i have to go back as far as parent of https://github.com/libsdl-org/SDL/commit/03ff7dcf6  (git checkout 03ff7dcf6~1) to get the build to succeed with API level 19. with 03ff7dcf6 and later commits one regression after the other was introduced.

i wrote up the process i used here: https://github.com/rofl0r/sdl2-android19-tutorial. for the record, i started with setting the target API to 16, and then gradually increased it to 19 when i figured out there was no way to get it to work with API level 16. and indeed with every platform bump there were less compile errors (i used the same SDK version for all these attempts).

> Yes, you need to use a newer SDK, but you can target down to Android 4.1.

how should that work when you're using APIs that don't exist in API level 16-26 ?

the only approach that could possibly work was how it was done before the patch from bug 4319 : you need to import whatever.* and then use introspection to access methods that have been introduced in a newer API level.

did you actually try to set the target platform API to 16 in your android studio and compile the java sources ? i'm 99% certain it will fail for you too.

> FYI, the Google Play Store requires you to use SDK version 28 or newer, I believe.

that might well be, but i'm actually trying to use SDL to make some custom apps for the android device i recently bought second hand for $5. SDL2 seemed like the right choice as i'm already familiar with it, and it supports video, audio and input, i.e. everything i need without having to mess around with JAVA.
Comment 6 Sylvain 2021-01-30 12:41:25 UTC
Maybe the usual build with gradle pull extra dependencies that you have to include yourself manually: eg library support-v4
Comment 7 Sylvain 2021-01-31 09:01:45 UTC
Sorry, just thought again:

You need build with the Android SDK >= 26 as required, so that it compiles correctly.

Even with this, you can still set your min value:
 minSdkVersion=16
and
 targetSdkVersion between 16 and 26


I mark this as invalid
Comment 8 rose.garcia-eggl2fk 2021-01-31 17:46:16 UTC
i actually used SDK_TOOLS_VERSION=4333796 which is the same version latest and greatest android studio downloads. it labels the download as "sdk tools revision 26.1.2" so i *did* use SDK 26.

while messing around with the android studio/gradle build system since 3 days (without success so far) i figured the only way this could possibly work with older API versions is the android support libraries you mentioned as well,
however they're not referenced anywhere from the build system.

according to the documentation i've read the gradle.build file should contain a
line like:

implementation "com.android.support:appcompat-v7:26.1.0"

or something along these lines, but it doesn't.

so it's still a miracle how this works for you, sylvain.
i'm reopening this until i can resolve the issue.

next thing i'll try is to manually add the android support module to my ant build (if i can figure out how), as using the gradle build system was just endless pain and frustration.
even an empty android project created using the IDE without any sources took over 2 minutes to build (after it finished downloading gigabytes of crap, including a different NDK version than i already installed via the IDE), while the ant build takes 2 seconds.
Comment 9 Sylvain 2021-01-31 18:35:52 UTC
I had no explicit appcompat in my gradle file when using targetSdkVersion=18 for testing (but this may also be pulled automatically).


One more suggestion,
I you really believe you are using a SDK 26, then 
just try to update your targetSdkVersion to 26, and it shouldn't need any support/compat lib to build since the targetSdk is exactly what the build sdk is.
Comment 10 Sylvain 2021-01-31 18:38:08 UTC
Also: 
Changing the compileSdkVersion to something < 26 produces the same compile errors you have! So gradle isn't fixing it magically,
Which makes me think the issue is still with the sdk version.
Comment 11 rose.garcia-eggl2fk 2021-01-31 20:04:24 UTC
if i understand this correctly: https://stackoverflow.com/questions/27301867/what-is-compilesdkversion
compileSdkVersion is actually the version you use the featureset of.

of course if you use features of version 26, this requires at least compileSdkVersion 26 - but the app will not run on API level 16 devices.

the other two values seem to be only hints to the app store what your app claims to support.

i actually managed to get a hold of the well-hidden android support package via the helpful directory listing of https://mirrors.cloud.tencent.com/AndroidSDK/ .
link from google dl server: https://dl.google.com/android/repository/support_r19.1.zip

it contains the source code of the compatibility layer, and there's no mention of e.g. "PointerIcon" at all in it. so even if the support package would be automatically used by the build (as opposed to manually importing its features via import android.support.v4.whatever) the unconditional use of android.view.PointerIcon (for example) cannot work on older devices.

so from all i can tell, as it stands, SDL2 in its current form cannot be used on devices < API 26.

i'd appreciate if you could test your build on a the android emulator or on a device with e.g. API level 20, sylvain and confirm that it is broken at the moment.
Comment 12 rose.garcia-eggl2fk 2021-02-01 00:20:12 UTC
btw for testing it might be the best/simplest option to download android-x86 iso for android 4.4, it should run in any PC emulator (it's android modded for use on desktop pcs):
https://osdn.net/projects/android-x86/downloads/65695/android-x86-4.4-r5.iso/
Comment 13 Sylvain 2021-02-01 07:10:19 UTC
yes, compiling with:
   compileSdkVersion 26
   minSdkVersion 16
   targetSdkVersion 18

works on old device that has SDK 21
Comment 14 rose.garcia-eggl2fk 2021-02-02 00:03:29 UTC
ok thanks, i too managed to build my hello world using git master with the ant equivalent to "CompileSdkVersion" (default.properties and project.properties) and the result runs on android 4.4 device, miraculously.
so i'm closing this, though i guess it would be helpful if the default gradle build could be enhanced with CompileSdkVersion set to 26.
Comment 15 Sylvain 2021-02-02 07:19:44 UTC
What did you change more precisely ?
just set default.properties and project.properties to SDK 26 ?
Comment 16 rose.garcia-eggl2fk 2021-02-04 02:03:14 UTC
Created attachment 4759 [details]
log from android-x86 version 4.4.4

> just set default.properties and project.properties to SDK 26 ?

correct.

btw, i installed above mentioned android-x84 iso (android 4.4.4, API 19) in qemu and on that my demo app doesn't work - the window isn't displayed.
qemu config:

qemu-system-x86_64 -cpu host -smp cpus=2 -m 1024 -device cirrus-vga -enable-kvm -cdrom ~/Downloads/android-x86-4.4-r5.iso -hda ax86-4.4.qcow2 -soundhw es1370

log file created with "logcat" is attached.
Comment 17 Sylvain 2021-02-04 07:22:31 UTC
ok thanks,


don't know about qemu,

try using the android emulator AVD. there are command line tools for it.
Comment 18 rose.garcia-eggl2fk 2021-02-04 17:17:52 UTC
if i read the log correctly, it's due to GL ES not working since the kernel built for that android image doesn't support the DRM_VIRTIOGPU driver and i have to run the image using the 2D-only cirrus driver.
there are other interesting bits in that log though, for example one can see messages about PointerIcon not found and how android deals with stuff from a higher API level that's not supported. it seems the VM instructions are live patched to just nop those calls, so one needs to be careful that everything still works as intended, and it's likely that some advanced things i didn't test yet will behave quite unexpected.
Comment 19 Sylvain 2021-02-04 18:06:00 UTC
Yes, but, in SDL java code, there are conditions like "if (Build.VERSION.SDK_INT >= 24) {" to protect from using PointerIcon and others,