And why not use Ionic-cli itself to generate APK?
It informs you any lack of global dependency, as if the cordova
or the @ionic/app-scripts
, he even helps you install what’s missing
The command in the project folder is this:
ionic cordova build android
This will generate apk for debug, if you want to test in emulator or phone the command is:
ionic cordova run android -l -c
The -l
is the parameter to do the livereload (you can edit and it updates directly without needing to reinstall the apk in the emulator) and the -c
is to display console.log
and errors in the terminal/cmd
Note that ionic cordova build android
will generate apk for testing/debug, if you want to publish you need to do a number of steps:
Generate APK for production
In the project folder run:
ionic cordova build android --prod --release
At the end of the command it will show on the console or cmd where you saved the apk, copy the path
Note: this apk is usually not "installable" as it will need to be signed
Generate a signature
First, if it is windows, the folder "C:\Program Files\Java\jdk1.8.<versao do teu jdk 1.8>\bin\"
must be in the environment variables (of the operating system), because otherwise will have to type all the way to access the program keytool
and jarsigner
Then navigate to the project folder and run this:
keytool -genkey -v -keystore minhaassinatura.jks -keyalg RSA -keysize 2048 -validity 10000 -alias nomedoprojetoouqualqueroutracoisa
He will ask to fill in some data and then will ask for a password (key), choose a key, but remember to write it down somewhere
By signing the APK
done this your jks is ready, then the next step is to sign the apk, in the example below wrote: /CAMINHO/AONDE/ESTA/SALVO/O/APK/PRODUCAO.apk
, change the path where the ionic cordova build
generated the apk
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore minhaassinatura.jks /CAMINHO/AONDE/ESTA/SALVO/O/APK/PRODUCAO.apk nomedoprojetoouqualqueroutracoisa
Compressing
After the signing process you must compress the apk, both the program zipalign
regarding the program apksigner
are in the android sdk folder, then this folder should be placed in the environment variables, user or operating system, example if it is windows and want to add via line command/ run time:
set PATH=%PATH%;C:\<localização>\Android\Sdk\build-tools\<versão do sdk>
Or add in the same environment variables. Done this, let’s compress:
zipalign -v 4 /CAMINHO/AONDE/ESTA/SALVO/O/APK/PRODUCAO.apk /novo/caminho/apk-comprimido.apk
The way /novo/caminho/apk-comprimido.apk
is just example, you should choose a path to save the compressed version of your apk
Verifying the signature
To verify the signature perform:
apksigner verify /novo/caminho/apk-comprimido.apk
If you have done everything correctly your apk should be ready to publish, the rest you should do via:
App Bundle vs APK
If you intend to use App Bundle instead of apk (it generates apks for different versions of android), so instead of generating apk with ionic cordova build android --prod --release
just run:
ionic cordova prepare android
And then open the folder /projeto/platforms/android/
in androidstudio and do everything for it, I do not believe it has much advantage to Ionic or other projects Ordova use this, because the visual features are usually html, images and css, nothing that will really have difference between android versions, that is it is likely that the gain is minimal.
Do you have images downloaded from android versions on your PC? You downloaded Android Studio and did this?
– Edward Ramos
I have the versions of Android 6.0 up to 10.0 all installed in my Android Studio. System variables have been configured.
– Flavia Pino
I got it, add this info from the android images to your question, and take a look at Guilherme Nascimento’s answer.
– Edward Ramos