Skip to content
Browse files

Android: Fixed trying to read from APK expansion files without versio…

…n hint set.

This also fixed overwriting the asset error message which is more useful if no
APK expansion files are available and the requested file was not found.
  • Loading branch information
philippwiesemann committed Sep 17, 2015
1 parent 92ca42d commit 6e7c479ec256f3b845cb648a985f4febccae0c2e
Showing with 17 additions and 3 deletions.
  1. +13 −2 android-project/src/org/libsdl/app/
  2. +4 −1 src/core/android/SDL_android.c
@@ -688,12 +688,23 @@ public InputStream openAPKExtensionInputStream(String fileName) throws IOExcepti

* This method is called by SDL using JNI.
* @return an InputStream on success or null if no expansion file was used.
* @throws IOException on errors. Message is set for the SDL error message.
public InputStream openAPKExpansionInputStream(String fileName) throws IOException {
// Get a ZipResourceFile representing a merger of both the main and patch files
if (expansionFile == null) {
Integer mainVersion = Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"));
Integer patchVersion = Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"));
if (mainHint == null) {
return null; // no expansion use if no main version was set
if (patchHint == null) {
return null; // no expansion use if no patch version was set

Integer mainVersion = Integer.valueOf(mainHint);
Integer patchVersion = Integer.valueOf(patchHint);

try {
// To avoid direct dependency on Google APK expansion library that is
@@ -790,7 +790,10 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
"openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, context, mid, fileNameJString);

if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
/* Exception is checked first because it always needs to be cleared.
* If no exception occurred then the last SDL error message is kept.
if (Android_JNI_ExceptionOccurred(SDL_FALSE) || !inputStream) {
goto failure;

0 comments on commit 6e7c479

Please sign in to comment.