Android Question Forward/Back slashes in manifest.MF

gregmatthews

Member
Licensed User
I have an APK, which I unzip, replace a file, re-sign with jarsigner and zipalign. The new apk installs fine, no warnings. However it fails on run, when trying to access /assets/control.bal with "An error has occurred in sub:main_activity_create(Java line:375) java.io.FileNotFoundException:control.bal".

The file is present in the APK.

The only difference I can see is that before the unpacking, signing, repacking, the manifest.MF uses forward slashes:
B4X:
Manifest-Version:1.0
Created-By:1.8.0_112(OracleCorporation)
Name: assets/longblackbar.png
SHA1-Digest:1Fq7U1Y/dLAVflFmTzLcC0tvKu4=

whereas afterwards it has backslashes
B4X:
Manifest-Version:1.0
Created-By:1.8.0_111(OracleCorporation)
Name: assets\longblackbar.png
SHA1-Digest: vaky9S8cGhJIvh7a4LmmtWOpqAg=

would that be enough to break this:
B4X:
Activity.LoadLayout("Control")

.. and if so any ideas on how to solve it? (just replacing the slashes breaks the APK integrity)

G.
 

gregmatthews

Member
Licensed User
Hi Erel,
The APK works correctly before swapping in the new file, re-signing it and re-aligning it.
Re-sign is done by:
B4X:
jarsigner -storepass myPassword -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my.keystore my.apk my

I have made some progress - it is the process of Zipping the files that seems to be the start of the problem.
If I zip all the files into an APK then the manifest.mf has the backslashes.
If I just add one file to the assets folder in the APK created by b4a, then after running jarsigner, the paths for the unaltered files are still all forward slashed correctly, and it is just the additional file that is backslashed.
So, I'm almost there. If I try and add "assets/myfile.xml" to the zip, then the zipper falls over.
I can add the file to the root of the zip, just as "myfile.xml", but then I can't load it in B4A as I can't see any parameter I can try other than File.DirAssets.
What does b4a use to do the zipping? if it is available as a standalone .exe then I can run it instead of the c# .net ZipArchive file extensions.

So, paths to try are:
(1) can I just drop the file I need into the root of the APK, and still access it from b4a
(2) b4a manages to zip the files correctly, can I run the same zipper?

Thanks for taking time to help me,
Greg
 
Upvote 0

gregmatthews

Member
Licensed User
An update - success!!
I ditched the c# zipfile extensions approach (ZipFile.CreateFromDirectory(foldername, zipFileName), and ran a separate process to run 7za.exe.

Using 7za.exe, the manifests are recreated with the correct forward slashes, and everything seems to work ok now!
 
Upvote 0
Top