fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
25.04k stars 1.39k forks source link

fyne release -os android does not seem to zip align the apk properly #4707

Closed Callial closed 7 months ago

Callial commented 7 months ago

Checklist

Describe the bug

Using fyne release -os android to build an aab and apk for app store distribution results in an APK that cannot be installed directly or through adb. When installed directly it simply does not finish the install and says app not installed. When installed through adb it gives the following error.

adb: failed to install TestAPK.apk: Failure [-124: Failed parse during installPackageLI: Targeting R+ (version 30 and above) requires the resources.arsc of installed APKs to be stored uncompressed and aligned on a 4-byte boundary]

How to reproduce

  1. Create a basic fyne app
  2. Create a keystore
  3. Run fyne release -os android with all needed flags
  4. Attempt to install the apk

Screenshots

No response

Example code

package main

import (
    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/widget"
)

func main() {
    a := app.NewWithID("com.callial.test")
    w := a.NewWindow("APK Tester")
    w.SetContent(widget.NewLabel("Hello Fyne!"))
    w.SetMainMenu(fyne.NewMainMenu(
        fyne.NewMenu("File",
            fyne.NewMenuItem("Quit", func() {
                a.Quit()
            })),
    ))
    w.ShowAndRun()
}

Fyne version

2.4.4

Go compiler version

1.22.1

Operating system and version

Windows 11 Home 23H2

Additional Information

I am using a Galaxy S23 Ultra for testing. I used keytool -genkeypair -v -keystore Test.keystore -alias Test -keyalg RSA -keysize 2048 -validity 10000 to generate the keystore for Testing I only populated the OU with Android to keep things simple

zip and unzip installed with chocolatey bundletool setup with a basic bundletool.bat file with the following

@echo off
java -jar "C:\Users\Callial\Tools\bundletool-all-1.15.6.jar" %*

development kits for Android and Java installed using Android Studio

The full release command I used for the test environment is fyne release -os android -appID com.callial.test -appVersion 0.0.1 -appBuild 1 -keyStore Test.keystore -keyStorePass 123456 -keyName Test

I then run adb install TestAPK.apk to test it on the phone before the error pops up

andydotxyz commented 7 months ago

The alignment is done when we call the "zipalign" tool which is part of the SDK, so the zip install should not make any difference. Are you able to check the zip align boundary for the .apk file that was generated?

You can get tips on checking here https://developer.android.com/tools/zipalign

Callial commented 7 months ago

Ok so I figured it out, it is zipaligning properly, but I mistakenly assumed it was zipaligning both the .apk generated by the command and the apk bundled in the aab. And as such during my testing I was not extracting the .apk from the .aab and instead I was just using the generated .apk When the apk told me that it was not zipaligned, I mistakenly assumed that meant that both apks would not be zipaligned.

tldr: .aab is generated and the internal apk is zipaligned properly, but the .apk generated is the apk before zipaligning

andydotxyz commented 7 months ago

Oh, does this mean we are leaving a temporary file lying around? the .apk output should be created by "fyne package" and the .aab is by "fyne release". A released Android app (.aab) is for upload to Google Play only and should not be tested locally - that is what the package command is for.

Callial commented 7 months ago

It appears to be that way, I only wanted to make sure it worked properly since it was my first time using the command and the last time I attempted to release an android app years ago I struggled with the signing process. Since it gives me both an apk and an aab, I figured it would be fine to test before uploading and that is where I went wrong I guess lol. But yeah I just deleted both files and ran just the release command again and it 100% generates both without deleting the apk after zipaliging and bundling.

andydotxyz commented 7 months ago

It appears to be that way,

I cannot replicate this - when preparing android for release I get a .aab file and no .apk left lying around. Unless you can create specific steps to replicate the issue I think this should be closed.