0
votes

I'm trying to build the APK to post my plea on Ionic in the Play Store. But when it comes to the command below I get the error:

PS C:\Projetos\XXX> jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore android.keystore platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk

android-app-key Picked up _JAVA_OPTIONS: -Xmx512M Enter Passphrase for keystore: jarsigner: unable to open jar file: platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk

And the release is not generated in the APK folder. Can someone help me?

3

3 Answers

2
votes

This problem may occur because of the following reasons :

  1. app-release-unsigned.apk does not exist
  2. when executing above command you are not in the release folder, release folder can be found in platforms/android/app/build/outputs/apk/release
  3. keystore does not exist

Verify that you are following these steps

  • after running ionic cordova build --release android make sure the build is successful and release folder is created under, the path is platforms/android/app/build/outputs/apk/release.
  • once release folder is created navigate to that folder through terminal
  • once you reach there generate key store by running following command keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000 you can change the key name to anything, in this example the key name is my-release-key, alias name is also up to you, here alias name is alias_name.
  • the key will be created under the release folder, save this key somewhere else to publish subsequent builds, also save alias name.
  • Once key is created run jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore app-release-unsigned.apk alias_name here put the same alias name in place of alias_name and keystore name in place of my-release-key.keystore what you choose in step 4, make sure you release apk name is same as app-release-unsigned.apk if it is different change it as well.
  • in the end run zipalign -v 4 app-release-unsigned.apk myapp.apk, to compress you app, this will create the compressed apk with name myapp.apk it is the same apk that you will use to publish.
1
votes

Checked whether android.keystore is located in C:\Projetos\XXX directory. Also check app-release-unsigned.apk is present on platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk this path.

1
votes

I was typing the wrong command. The correct one to generate is

ionic cordova build --release

and then, to generate the key for the first time, I used these commands:

keytool -genkey -v -keystore xxx.keystore -alias xxx-app-key -keyalg RSA -keysize 2048 -validity 10000

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore GestaoDespesas.keystore platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk xxx-app-key

.\zipalign -v 4 platforms\android\app\build\outputs\apk\release\xxx.apk xxx.apk