Bug? Issue with Accessing Subfolder in Assets When Compiling in B4A

mzsoft

Member
Hello,
I encountered a strange issue in a project where I needed to include an activity from a library inside an AAR file.
The activity runs fine with an intent.
In this activity, I need to read a file from a subfolder inside the assets.
like ("assets\game\exported\")
The project worked fine when compiled and run with pure Java.
However, when I brought it into B4A and compiled it, the activity couldn’t access the subfolder.
Interestingly, I opened the APK file with APK Editor Studio, decompiled it, and compiled it again without any changes. This time, the app ran without any issues and was able to find the file.
This is likely a bug in B4A.
 

mzsoft

Member
i found the problem .
in java i read all assets file.

in java assets path is
B4X:
game/b1/ball.png
in java code it was ok.
but when compile with b4a the path change to
B4X:
game\b1\ball.png
and java code cant read file.

if i decompile apk with APK Editor Studio and save apk the path a gain change to
B4X:
game/b1/ball.png

and it was ok .
 

mzsoft

Member
B4A uses the Windows path separator (\) when processing files on the Windows operating system, which may be due to the operating system’s characteristics or the project settings in B4A. AAPT2 cannot automatically convert these paths (since paths must be in ZIP standard), so the paths stored in resources.arsc remain in the Windows format (\). During the build process, the input paths to AAPT2 should be correctly set (with /). If the issue is related to paths in B4A, you need to ensure that the input files are saved in the correct format before being sent to AAPT2."

when i decompile b4a apk in file resources.arsc i saw wrong sub folder path.like this.

B4X:
- resources.arsc
- png
- assets/1.png
- assets/game\2.mp3
- assets/game\b.png
 

mzsoft

Member
and in b4a core source .you replace('/', '\\') that android path separator is the same as linux.no need to replace.

B4X:
 public static File.InputStreamWrapper OpenInput(String Dir, String FileName) throws IOException {
      File.InputStreamWrapper is = new File.InputStreamWrapper();
      if (Dir.equals("AssetsDir")) {
         if (virtualAssetsFolder != null) {
            is.setObject(new GZIPInputStream(new FileInputStream(new java.io.File(virtualAssetsFolder, FileName.toLowerCase(BA.cul)))));
         } else {
            is.setObject(BA.applicationContext.getAssets().open(FileName.toLowerCase(BA.cul).replace('/', '\\')));
         }
      } else if (Dir.equals("ContentDir")) {
         is.setObject(BA.applicationContext.getContentResolver().openInputStream(Uri.parse(FileName)));
      } else {
         is.setObject(new BufferedInputStream(new FileInputStream(new java.io.File(Dir, FileName)), 4096));
      }

      return is;
   }

.if b4a when make assets resources not use Windows path separator anduse linux path separator.i think problem with assets sub folder become solved.
please check b4a ide.

i search a lot about AAPT2 and apk tool also use AAPT2 .so wrong path is not related to AAPT2 and it is related to B4A.
 

mzsoft

Member
so why in java project path separator is "/" .
i check some apk in java .the path in file resources.arsc is correct.i dont know why.
my project need it.can i use custombuild to compile my own way?maybe i found problem.
 

mzsoft

Member
i check resources.arsc file.
at the end of this file it show asset file that no need compress.
and i change
B4X:
doNotCompress:
- resources.arsc
- png
- assets/1.png
- assets/game\2.mp3
- assets/game\b.png

to

B4X:
doNotCompress:
- resources.arsc
- png
- assets/1.png
- assets/game/2.mp3
- assets/game/b.png

my app work.
i search about this option in AAPT2.it has option to set this file name.
this is smaple of aapt2.

B4X:
aapt2 link \
  --no-compress "assets/game/2.mp3" \
  --no-compress "assets/game/b.png" \
  --no-compress "resources.arsc" \
  -o output.apk \
  -I path/to/android.jar \
  --manifest AndroidManifest.xml \
  --res res/ \
  --assets assets/

please check if this.
mybe b4a when read assets folder to make --no-compress files command use windows separator and not to change them.
 
Top