| Summary: | Android StrictMode policy violation | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Sylvain <sylvain.becker> |
| Component: | *don't know* | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | frankinshtein85 |
| Version: | don't know | ||
| Hardware: | All | ||
| OS: | Android (All) | ||
| Attachments: |
log of all non sdk api used violations
patch updated patch modified SDL_android.c patch updated |
||
|
Description
Sylvain
2018-10-05 17:03:38 UTC
not sure all the log is relevant. the stack trace of the previous warning is : StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Ljava/io/FileDescriptor;->descriptor:I at android.os.StrictMode.lambda$static$1(StrictMode.java:428) at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2) at org.libsdl.app.SDLActivity.nativeRunMain(Native Method) at org.libsdl.app.m.run(Unknown Source:52) at java.lang.Thread.run(Thread.java:764) That stack isn't super helpful, but if you'd like to take a scan through and propose patches, that would be wonderful. Thanks! Created attachment 3351 [details]
patch
I have found out that this is the JNI open/read file parts that causes this Non Sdk Api Used violation.
Current code looks overcomplicated whereas using the JNI asset manager is very simple.
I've quickly tested a patch (mostly remove code).
Loading image and files works (I mean open, read, seek, close, and filesize), from SDL_image and SDL_mixer.
The warning from google play console reports now disappears.
But this patch also drops some code to open files in APK expansion. Not tested if this still work or not.
Have same crash error on Android P (helloworld, emulator, x86): 2018-10-22 15:52:56.822 4578-4646/org.oxygine.GamePart4 W/ygine.GamePart: Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (light greylist, JNI) 2018-10-22 15:52:56.973 1875-1946/? W/InputDispatcher: channel '2b247d6 org.oxygine.GamePart4/org.oxygine.GamePart4.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 2018-10-22 15:52:56.973 1875-1946/? E/InputDispatcher: channel '2b247d6 org.oxygine.GamePart4/org.oxygine.GamePart4.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! not sure.. will my app (build for v7a work on real device)? btw, I've found FileDescriptor has
/**
* Returns the int descriptor. It's highly unlikely you should be calling this. Please discuss
* your needs with a libcore maintainer before using this method.
* @hide internal use only
*/
// Android-added.
public final int getInt$() {
return descriptor;
}
Sylvain, can you make sure APK expansion files still work? What's the earliest version of Android that supports these NDK functions? I really don't know how to build expansion apk nor to include it. Have to find out how to get it working first. According to NDK release note, those asset API appeared with r5 : https://developer.android.com/ndk/downloads/revision_history "Android NDK, Revision 5 (December 2010) This release of the NDK includes many new APIs, most of which are introduced to support the development of games and similar applications that make extensive use of native code. Using the APIs, developers have direct native access to events, audio, graphics and window management, assets, and storage" Btw, I don't have a crash. Only a warning when it's run on android p on google pre-launch. On the emulator, it didn't crash. @dmuratshin: do you activate yourself StricMode ? or target specific sdk api ? > Btw, I don't have a crash. Only a warning when it's run on android p on
> google pre-launch. On the emulator, it didn't crash.
> @dmuratshin: do you activate yourself StricMode ? or target specific sdk api
> ?
sorry, nevermind it was my fault
Sam, I looked at the APK expansion. And the patch clearly removed it, as it's very interleaved with the code removed by this issue. In the NDK, there is "storage_manager.h" which would allow to implement it by mounting a main or patch expansion APK (AStorageManager_mountobb()). But, a (not so) quick try shows that it's broken: - If you mount an OBB with no encryption key (current case in SDL), then it crashes (https://issuetracker.google.com/issues/63624928) - If you set an encryption key, you can mount it. But in my case it appears to empty. (OBB created with https://developer.android.com/studio/command-line/jobb) After looking into other projects, it seems to use those APK expansion in Android nobody achieve to use ndk/storage_manager, but they use mere Zip tools instead. In fact, OBB are just specific files, can be zip renamed as .obb, that are served by google play, and stored in a obb phone directory. SDL currently only provide a very small part to use OBB and there are more things left to the user: https://developer.android.com/google/play/expansion-files). I am not sure, but it looks very similar to PhysicsFS: providing access to assest files under one or several zip files. In short, people who want to use APK expansion could rely on PhysicsFS. SDLActiviy.java could only provide helper function to have paths to those main/patch obb. Sylvain, can you update this patch to apply cleanly with the latest SDL? Thanks! I'll do that a little bit later, but this remove the APK Expansion features, is this ok for commit ? Is there a way to avoid that? Created attachment 3854 [details]
updated patch
Updated patch.
I don't really remember the details but I couldn't get the APK Expansion features working. See the previous message for the record.
I had some test code if you want to try ...
Created attachment 3855 [details]
modified SDL_android.c
This SDL_android.c contains some sample code for the APK feature .. (look for obb ...)
Moving all the remaining target-2.0.10 bugs to target-2.0.11. If these still aren't resolved when 2.0.11 ships, we should probably remove the keyword altogether. --ryan. We're changing how we do SDL release versions; now releases will be even numbers (2.0.10, 2.0.12, etc), and as soon as we tag a release, we'll move the internal version number to an odd number (2.0.12 ships, we tag the latest in revision control as 2.0.13 immediately, which will become 2.0.14 on release, etc). As such, I'm moving the bugs tagged with target-2.0.11 to target 2.0.12. Sorry if you get a lot of email from this change! Thanks, --ryan. We're changing how we do SDL release versions; now releases will be even numbers (2.0.10, 2.0.12, etc), and as soon as we tag a release, we'll move the internal version number to an odd number (2.0.12 ships, we tag the latest in revision control as 2.0.13 immediately, which will become 2.0.14 on release, etc). As such, I'm moving the bugs tagged with target-2.0.11 to target 2.0.12. Sorry if you get a lot of email from this change! Thanks, --ryan. Created attachment 4334 [details] patch updated This is the patch updated since asset manager code is used with SDL_GetPreferredLocales(). (https://hg.libsdl.org/SDL/rev/458e052261cb) the diff appears much cleaner (NB: the patch should also remove some obvious java method) https://hg.libsdl.org/SDL/rev/9668efdaef72 Fixed bug 4297 - Android StrictMode policy. Remove APK expansion support "In the second half of 2021, new apps will be required to publish with the Android App Bundle on Google Play" (see https://developer.android.com/guide/app-bundle) And "Android App Bundles don't support APK expansion (*.obb) files". |