Android Question Unzip and re-zip APK files

FabioAlbaneseTv

Member
Licensed User
Hi
I knew that APK files are basically ZIP files.
I tried, then to write this code for B4J

B4J Source code:
Sub Process_Globals
    Private fx             As JFX
    Private MainForm     As Form
    Private xui         As XUI
    Private Button1     As B4XView
    Private abZip         As ABZipUnzip
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    Dim myAppPath As String
    myAppPath=File.DirApp
    If File.Exists(myAppPath ,"\tmp")=False Then
        File.MakeDir (myAppPath , "\tmp")
    End If
    abZip.ABUnzip(myAppPath & "\input.apk",myAppPath & "\tmp")
    abZip.ABZipDirectory(myAppPath & "\tmp",myAppPath  & "\output.apk")
End Sub

that:

1. extract, using the ABZipUnzip library, the contents of a working APK (created with B4A) called input.apk in a tmp folder
2. create an output.apk file by compressing the contents of the tmp folder using the ABZipUnzip library.

I expected the generated file output.apk to be exactly identical to input.apk.

But is not so.

If I rename the two files input.apk and output.apk to input.zip and output.zip and extract the files in two different folders, the files in the two folders are the same, but the output.apk file is not seen as an apk valid from Android devices.
Can anyone explain to me why and possibly if there is a way to decompress and then recompress an apk file while keeping it functional?
Thank you.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…