One Question - Did you noticed that building apk with cordova have smaller size rather than use capacitor ? know me your feedback !
How to build a Ionic app using Cordova in windows
Prequsites :
-
Install
Andorid studio, JDK (preferd version 1.8), gradle
.
Tricks After installed Android studio build a native hello world app and run it through Emulator or physical device for the first time. It will automatically gives you the support of installing gradle & reduce much time to installing & finding gradle version compability.
-
Checking this info you can run
java --version
java version "1.8.0_321" Java(TM) SE Runtime Environment (build 1.8.0_321-b07) Java HotSpot(TM) 64-Bit Server VM (build 25.321-b07, mixed mode)
-
After install
JDK
you will get a path in your machine like thisC:\Program Files\Java
orC:\Program Files (x86)
you able to see this two folder path.
jdk1.8.0_321 jre1.8.0_321
-
Update environment variable
// Add these in User Variables : ANDROID_HOME : C:\Users\theanam\AppData\Local\Android\Sdk ANDROID_PLATFORM_TOOLS : C:\Users\theanam\AppData\Local\Android\Sdk\platform-tools ANDROID_TOOLS : C:\Users\theanam\AppData\Local\Android\Sdk\tools JAVA_HOME : C:\Program Files\Java\jdk1.8.0_321 //Add these in System Variables path: C:\Program Files\Java\jre1.8.0_321\bin // Otherwise you will get Jarsigner is not recognized internal or external command C:\Program Files\Java\jdk1.8.0_321\bin // Otherwise keytool is not recognized internal or external command C:\Program Files (x86)\Common Files\Oracle\Java\javapath C:\gradle-7.4.1\bin // If path not found installed it.
Ionic App build stage & Signing unsigned apk
- Go to the
App Folder
- Open
terminal
in that folder. - Run
keytool -genkey -v -keystore HERE_YOUR_KEY_NAME-key.keystore -alias HERE_YOUR_APP_ALIAS_NAME -keyalg RSA -keysize 2048 -validity 10000
. You will find a keystore file is generated in your app folder. -
Run
ionic cordova build android --prod --release --verbose
After successfully executed this command you will get a message like this,
Built the following apk(s):
D:\xyz\ion-cordova\platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk
It generate an unsigned apk that you never install in a phone so need to sign this apk.
- Run
jarsigner --verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore HERE_YOUR_KEY_NAME-key.keystore "D:\xyz\ion-cordova\platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk" HERE_YOUR_APP_ALIAS_NAME
it will start signing this apk.
Now you are happy to go with the APP.
Signing Off
Sefat
Top comments (3)
If you have already a keystore see the content inside it by
keytool -list -v -keystore my-release-key.keystore
then it will ask you to enter password.
Great job Man!!!
Thanks @coderinfinity 💖