[Android][3510] Cannot open files when using expansion file

When building my app with version 3502 the app crashes on startup.

Error log, tells me that the following failed: dir is nil instead of string.

local dir = system.pathForFile("game/config/color.json", system.ResourceDirectory); local file, errorString = io.open(dir, "r");

The same code works, if I just set usesExpansionFile to false in build settings.

This isn’t a 64-bit specific issue.

This occurs when you are trying to access a file that does not exist in system.ResourceDirectory. If you change to system.DocumentsDirectory, the crash won’t occur.

e.g. for ResourceDirectory,

local path = system.pathForFile( "ThisFileDoesntExist.json", system.ResourceDirectory ) print( path ) -\> nil local file, errorString = io.open( path, "r" ) -\> Runtime error print( file, errorString )

for DocumentsDirectory,

local path = system.pathForFile( "ThisFileDoesntExist.json", system.DocumentsDirectory ) print( path ) -\> outputs path to documents folder local file, errorString = io.open( path, "r" ) print( file, errorString ) -\> nil, no such file or directory

You can add a simple “if path then” check to prevent these crashes.

Does same code works on 3480 or something?

I’m running 3459 and the ResourceDirectory example I posted results in a runtime error: “bad argument #1 to ‘open’ (string expected, got nil)”.

I’ve just been using the following method to prevent the issue.

local path = system.pathForFile( "ThisFileDoesntExist.json", system.ResourceDirectory ) local file, errorString if path then file, errorString = io.open( path, "r" ) end

Sorry it took me so long to get back to you. 

To clarify, we’re using normal apks with expansion files, not android bundles. Our app is larger than 200MB so we’re dependant on expansion files. 

We’re building all apps (android and iOS) on a Mac, if that makes any difference.

I’m trying to load files, that are packed to the android expansion files (obb files). In this case, color descriptors and localization files. Preventing the crash would not help, as the files are required for the app to function.

This has worked in the past!

2019.3476 - works

2019.3480 - works

2019.3486 - Build Error 11

2019.3487 - Build Error 11

2019.3490 - Build Error 11

2019.3502 - does not work

2019.3504 - does not work

2019.3508 - does not work

I also retested, if 2019.3508 works, if I set usesExpansionFile to false. Yes, it does. The problem only happens, if an expansion file is created!

I tested 2019.3510, it does not work either. 

I stripped our problem down to an example project and attached it to this post. I just uploaded the build of that project to a testapp on google: It shows the same crash. Hope that helps fixing the problem.

Thanks for the example, it was quite helpful. I think it should be fixed in latest daily build, 3512.

Looks good. Works on my device now. I will check in detail over the next days.

There still seems to be problems with this on Android 9. I got send the following Crashlog:

--------- beginning of crash FATAL EXCEPTION: background thread Process: com.XXX, PID: 26682 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/utils/URLEncodedUtils; at com.google.android.vending.licensing.Policy.decodeExtras(Policy.java:183) at com.google.android.vending.licensing.APKExpansionPolicy.processServerResponse(APKExpansionPolicy.java:139) at com.google.android.vending.licensing.LicenseValidator.handleResponse(LicenseValidator.java:203) at com.google.android.vending.licensing.LicenseValidator.verify(LicenseValidator.java:163) at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run(LicenseChecker.java:229) at android.os.Handler.handleCallback(Handler.java:907) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:216) at android.os.HandlerThread.run(HandlerThread.java:65) Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.client.utils.URLEncodedUtils" on path: DexPathList[[zip file "/data/app/com.XXX-8HOybYupzcltEQStmlofaA==/base.apk"],nativeLibraryDirectories=[/data/app/com.XXX-8HOybYupzcltEQStmlofaA==/lib/arm64, /data/app/com.XXX-8HOybYupzcltEQStmlofaA==/base.apk!/lib/arm64-v8a, /system/lib64, /product/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

Affected Device: Huawei P30 Pro, Android 9.1, Instant crash on App launch

Thanks. This is unrelated to the expansion file. Will look at it

This should be fixed in latest daily build as well

This isn’t a 64-bit specific issue.

This occurs when you are trying to access a file that does not exist in system.ResourceDirectory. If you change to system.DocumentsDirectory, the crash won’t occur.

e.g. for ResourceDirectory,

local path = system.pathForFile( "ThisFileDoesntExist.json", system.ResourceDirectory ) print( path ) -\> nil local file, errorString = io.open( path, "r" ) -\> Runtime error print( file, errorString )

for DocumentsDirectory,

local path = system.pathForFile( "ThisFileDoesntExist.json", system.DocumentsDirectory ) print( path ) -\> outputs path to documents folder local file, errorString = io.open( path, "r" ) print( file, errorString ) -\> nil, no such file or directory

You can add a simple “if path then” check to prevent these crashes.

Does same code works on 3480 or something?

I’m running 3459 and the ResourceDirectory example I posted results in a runtime error: “bad argument #1 to ‘open’ (string expected, got nil)”.

I’ve just been using the following method to prevent the issue.

local path = system.pathForFile( "ThisFileDoesntExist.json", system.ResourceDirectory ) local file, errorString if path then file, errorString = io.open( path, "r" ) end

Sorry it took me so long to get back to you. 

To clarify, we’re using normal apks with expansion files, not android bundles. Our app is larger than 200MB so we’re dependant on expansion files. 

We’re building all apps (android and iOS) on a Mac, if that makes any difference.

I’m trying to load files, that are packed to the android expansion files (obb files). In this case, color descriptors and localization files. Preventing the crash would not help, as the files are required for the app to function.

This has worked in the past!

2019.3476 - works

2019.3480 - works

2019.3486 - Build Error 11

2019.3487 - Build Error 11

2019.3490 - Build Error 11

2019.3502 - does not work

2019.3504 - does not work

2019.3508 - does not work

I also retested, if 2019.3508 works, if I set usesExpansionFile to false. Yes, it does. The problem only happens, if an expansion file is created!

I tested 2019.3510, it does not work either. 

I stripped our problem down to an example project and attached it to this post. I just uploaded the build of that project to a testapp on google: It shows the same crash. Hope that helps fixing the problem.

Thanks for the example, it was quite helpful. I think it should be fixed in latest daily build, 3512.

Looks good. Works on my device now. I will check in detail over the next days.

There still seems to be problems with this on Android 9. I got send the following Crashlog:

--------- beginning of crash FATAL EXCEPTION: background thread Process: com.XXX, PID: 26682 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/utils/URLEncodedUtils; at com.google.android.vending.licensing.Policy.decodeExtras(Policy.java:183) at com.google.android.vending.licensing.APKExpansionPolicy.processServerResponse(APKExpansionPolicy.java:139) at com.google.android.vending.licensing.LicenseValidator.handleResponse(LicenseValidator.java:203) at com.google.android.vending.licensing.LicenseValidator.verify(LicenseValidator.java:163) at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run(LicenseChecker.java:229) at android.os.Handler.handleCallback(Handler.java:907) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:216) at android.os.HandlerThread.run(HandlerThread.java:65) Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.client.utils.URLEncodedUtils" on path: DexPathList[[zip file "/data/app/com.XXX-8HOybYupzcltEQStmlofaA==/base.apk"],nativeLibraryDirectories=[/data/app/com.XXX-8HOybYupzcltEQStmlofaA==/lib/arm64, /data/app/com.XXX-8HOybYupzcltEQStmlofaA==/base.apk!/lib/arm64-v8a, /system/lib64, /product/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

Affected Device: Huawei P30 Pro, Android 9.1, Instant crash on App launch

Thanks. This is unrelated to the expansion file. Will look at it