DEV Community

Cover image for Step-by-Step Guide to Building Your First Ionic App with Cordova on Windows
Sefat Anam
Sefat Anam

Posted on • Updated on

Step-by-Step Guide to Building Your First Ionic App with Cordova on Windows

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 :

  1. 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.
    
  2. 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)
    
  3. After install JDK you will get a path in your machine like this C:\Program Files\Java or C:\Program Files (x86) you able to see this two folder path.

    jdk1.8.0_321
    jre1.8.0_321
    
  4. 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

  1. Go to the App Folder
  2. Open terminal in that folder.
  3. 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.
  4. 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.
Enter fullscreen mode Exit fullscreen mode
  1. 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)

Collapse
 
sefatanam profile image
Sefat Anam • Edited

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.

Collapse
 
coderlifeisawesome profile image
lifeascoder

Great job Man!!!

Collapse
 
sefatanam profile image
Sefat Anam • Edited

Thanks @coderinfinity 💖