Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sefatanam/2a1a278b83a0afc0d29614d93e58e774 to your computer and use it in GitHub Desktop.
Save sefatanam/2a1a278b83a0afc0d29614d93e58e774 to your computer and use it in GitHub Desktop.

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.
    
  5. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment