Wish Disabling of compression of certain file extensions when generating apk

moster67

Expert
Licensed User
Longtime User
I am working on a project which works fine in Android Studio but when using my wrapper in B4A, I keep getting the following error:

Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
This happens in these code snippets from my wrapper from two different methods:
B4X:
classifier.interpreter = new Interpreter(classifier.loadModelFile(assetManager, modelPath));
    //and
    AssetFileDescriptor fileDescriptor = assetManager.openFd(modelPath); //crashes here

This seems to happen because certain files, depending on file extensions, are being compressed into the Asset-folder when generating the apk.

There are some workarounds as explained here such as inserting the files afterwards in the apk or by using the CacheDir but they are not any good solutions in my opinion, especially since there is a solution already available with Android Studio i.e. you tell AS to not compress files with a certain extension. This is done by inserting a snippet in the build.gradle similar to the one listed below:
B4X:
aaptOptions {
    noCompress "tflite"
    noCompress "lite"
}

Would this be possible with B4A, perhaps using a new attribute?
Or maybe it can already be done by using the #CustomBuildAction attribute. If yes, how would I do that?

Many thanks in advance.
 

moster67

Expert
Licensed User
Longtime User
Yes, I get the same error also in release mode.

One clarification, perhaps not clear from my first post. The error happens also in Android Studio if I don't use the option to disable the compression in the build.grade.
 

moster67

Expert
Licensed User
Longtime User
Unfortunately the code for opening the files in the asset-folder is in the compiled library sources so I am unable to change that and the extension to open. I am currently resolving it by using some of the code shown in the SO-post to which I linked to in my first post but it is cumbersome.

Unless there are technical reasons for doing it, a solution such as the "noCompress" aaptOption mentioned in my first post would be nice to have in B4A in the future.
 
Top