0

I am able to build an unsigned APK using flutter build apk --split-per-abi --no-tree-shake-icons. However, when I attempt to generate a signed APK, I get several Kotlin related errors. To be clear, I can build the project without signing just fine. However, when I attempt to generate a signing key (via Android Studio) the process fails with the errors shown below. I believe the signing process uses 'tools.jar' which is available in JDK 8. I have added JDK 8 (liberica-1.8) to the project structure. I've seen some postings indicating openjdk@8 is not compatible with M1 Macs. The JDK 8 included with Android Studio, however, indicates that it supports aarch64 so I assume this isn't a problem. Nevertheless, I cannot determine the source of these errors.

enter image description here

MainActivity.kt:

enter image description here

I'm using the APK key generation process in Android Studio to sign my APK (Build > Generate Signed Bundle / APK): enter image description here

I am not attempting to run ProGuard at this time: enter image description here

I am running on Apple silicon. I've tried flutter clean and invalidating caches.

MySilmaril
  • 185
  • 2
  • 13

1 Answers1

0

After further investigation and testing, I believe the bundle and APK signing process that's built into Android Studio (Bumblebee 2021.1.1) will not work on a M1 Mac. I tested this process using a variety of JDKs. Each time, I get the same errors I shared earlier (JDK 8 must be used to avoid a missing tools.jar problem). I strongly suspect (but have not yet tested) that this same signing process works fine on Intel Macs.

As a workaround for M1 Macs, I am posting a comprehensive solution found here that is derived from posts by RichardC and Kit.

(A) To generate the keystore:

keytool -genkey -v -keystore ~/Desktop/upload-keystore.keystore -alias upload -keyalg RSA -keysize 2048 -validity 10000

(B) To sign an APK:

jarsigner -verbose -keystore ~/Desktop/upload-keystore.keystore ~/Desktop/app-armeabi-v7a-release.apk  upload

(C) If the above command fails, try this one (SDK must be at least 1.7):

jarsigner -verbose -digestalg SHA1 -sigalg MD5withRSA -keystore ~/Desktop/upload-keystore.keystore ~/Desktop/app-armeabi-v7a-release.apk  upload

(D) To zip align an APK:

~/Library/Android/sdk/build-tools/32.0.0/zipalign -f -v 4 ~/Desktop/app-armeabi-v7a-release.apk ~/Desktop/app-armeabi-v7a-release-za.apk

NOTE: make sure to check/replace 32.0.0 as needed.

(E) If the APK file is already signed, remove the original sign with following code:

Zip -d ~/Desktop/app-armeabi-v7a-release.apk META-INF/*

I was able to sign the APKs I built with Flutter flutter build apk --split-per-abi --no-tree-shake-icons using these CLI commands with no issues on my M1 Mac. Hopefully a future release of Android Studio corrects this issue.

MySilmaril
  • 185
  • 2
  • 13