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 2498 - PULL REQUEST: Android APK expansion files support
Summary: PULL REQUEST: Android APK expansion files support
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.3
Hardware: All Android (All)
: P2 enhancement
Assignee: Gabriel Jacobo
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-14 15:15 UTC by Alexey
Modified: 2014-06-22 03:38 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey 2014-04-14 15:15:50 UTC
Simple patch that adds initial support for android APK expansion files. Tiny issues is that it depends on "Google Play APK Expansion Library" from Android SDK Extra. Not sure if it's ok for SDL. Anyway feel free to share any your thoughts about this patch. It can be pulled from https://bitbucket.org/stopiccot/sdl/branch/apk

Regards, Alexey
Comment 1 Philipp Wiesemann 2014-04-18 18:18:17 UTC
In SDLActivity.java openAPKExtensionInputStream() calls getHint() 2x with the same argument.

According to convention documented at the top of SDL_hints.h the string for SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION should be "SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION".

Maybe getHint() could be renamed to nativeGetHint() to match the other native methods.
Comment 2 Alexey 2014-04-23 00:46:00 UTC
Thanks, Philipp for going through the code. I've fixed issues you discovered. I've also updated branch https://bitbucket.org/stopiccot/sdl/branch/apk. But the main question is still the same: How to deal with dependency on Google library?
Comment 3 Philipp Wiesemann 2014-04-23 21:56:06 UTC
(In reply to Alexey from comment #2)
> still the same: How to deal with dependency on Google library?

I have not tried this but maybe reflection could be used. This way the two classes would not need to be imported and it would still compile if the library is not installed. On the other hand this would make the implementation more complicated.
Comment 4 Alexey 2014-04-27 17:31:49 UTC
What about copying google files to SDL? Is Apache License compatible with license used by SDL?
Comment 5 Philipp Wiesemann 2014-04-28 22:07:51 UTC
I tried implement the library access using reflection. Here is a patch for SDLActivity.java from the original patch. I have not tested this implementation.

4a5
> import java.lang.reflect.Method;
25,27d25
< import com.android.vending.expansion.zipfile.APKExpansionSupport;
< import com.android.vending.expansion.zipfile.ZipResourceFile;
< 
505c503,506
<     private ZipResourceFile expansionFile = null;
---
>     /** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */
>     private Object expansionFile;
>     /** com.android.vending.expansion.zipfile.ZipResourceFile's getInputStream() or null. */
>     private Method expansionFileMethod;
513c514,526
<             expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this, mainVersion, patchVersion);
---
>             try {
>                 expansionFile = Class
>                     .forName("com.android.vending.expansion.zipfile.APKExpansionSupport")
>                     .getMethod("getAPKExpansionZipFile", int.class, int.class)
>                     .invoke(null, mainVersion, patchVersion);
>                 expansionFileMethod = expansionFile
>                     .getClass()
>                     .getMethod("getInputStream", String.class);
>             } catch (Exception ex) {
>                 ex.printStackTrace();
>                 expansionFile = null;
>                 expansionFileMethod = null;
>             }
517c530,536
<         InputStream fileStream = expansionFile.getInputStream(fileName);
---
>         InputStream fileStream;
>         try {
>             fileStream = (InputStream) expansionFileMethod.invoke(expansionFile, fileName);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>             fileStream = null;
>         }
Comment 6 Alexey 2014-04-30 19:54:58 UTC
Patch worked almost without modifications. Seems that everything is ready to get merged into mainline. As always all changes can be pulled from https://bitbucket.org/stopiccot/sdl/branch/apk
Comment 7 Gabriel Jacobo 2014-05-11 04:08:50 UTC
How should I test this?
Comment 8 Alexey 2014-05-28 23:28:29 UTC
Sorry for such horrible late response. I've missed last e-mail.
To test this patch just move some files from APK assets folder to OBB and try to read them. You can read detailed explanation here: http://developer.android.com/google/play/expansion-files.html
Please note, that this patch does not implement downloading missing obb's. But it's really a weird case when user downloads app and then removes obb without removing app itself.
Comment 9 Sam Lantinga 2014-06-22 03:38:43 UTC
Merged, thanks!