Categories
Learning Learning Tech

How to build Android APK/apk from command line interface on windows/mac?

Hello,

If you are looking for, to build or generate the android apk file (in your capacitor project) directly from the command line rather then opening Android Studio and building up.

I will share few steps and challenges face to build android apk from CLI on windows and also would share below the mac version of command line code too incase you are mac user.

First step first,

Before running the CLI command which I will be sharing below, we make sure we add the two things under Environment variables of windows system.

  • Java JDK or JAVA_HOME path
  • zipalign if not set or when you run command your cli throw error not zipalign command (so we need it too in the PATH variable of the windows system)
See last two entries in the image above, second entry were zipalign.exe is available under your real Android Studio folder.

Next, just try out these command you will be good to go

Windows CLI command for Android APK release build
cd android && 
gradlew.bat assembleRelease && 
cd app/build/outputs/apk/release &&
jarsigner -keystore YOUR_KEYSTORE_PATH -storepass YOUR_KEYSTORE_PASS app-release-unsigned.apk YOUR_KEYSTORE_ALIAS &&
zipalign 4 app-release-unsigned.apk app-release.apk

In Code above, note we are using gradlew.bat which is important to note for window users reset is same for MAC command too (didn’t tested on mac, channel of command source from the post), result would working for me on windows!

Note the date and time of output (compare to post date and time, I renamed the file to mdw-app-release.apk for use)
Mac CLI command for Android APK release build
cd android && 
./gradlew assembleRelease && 
cd app/build/outputs/apk/release &&
jarsigner -keystore YOUR_KEYSTORE_PATH -storepass YOUR_KEYSTORE_PASS app-release-unsigned.apk YOUR_KEYSTORE_ALIAS &&
zipalign 4 app-release-unsigned.apk app-release.apk

If you like to generate for debug just changed assembleRelease to assembleDebug and change the file names accordingly, from release to debug or whatever names you would like to prefix or suffix.

Hope this gives ideas and info for the challenge you might facing.

Happy Learning & Thanks for visit.

Categories
Blog Tech

How to generate Public & Private SSH Keys on Windows?

Hello, Lets Begin.

Open a Command Prompt/Terminal Window.

Important Alert!: Before going further, there is very important to know. If you have already generated a private/public key pair, don’t do it again!.

Where to find those keys or check if generated or not?

Okay, lets quickly see that step, Open Explorer window and type in address of explorer %userprofile%/.ssh it will open the window for you.

Typing %userprofile%/.ssh

Result of opening the above path. if you already have files will be listed otherwise it would be empty, so you can continue following reading next few steps to generate up the same.

.ssh list keys if already generated on your system or otherwise it list empty

Follow steps if no keys are available in the case.

Lets go back to our open Terminal Window/Command Prompt enter command:

ssh-keygen -b 4096

You are prompted to answer a few questions.

First is “Enter file in which to save the key” Press enter to use the default location.

The next question is “Enter passphrase.” This step is optional, but good to have for better security. Use whatever you like or skip, and then press enter.

Then confirm the passphrase or enter if none.

Once done new keys will be saved to same path under .ssh

For example: C:\your-username\.ssh\id_rsa.pub

Then you can use both the files to upload it under your hosting server to make a communication with your server through terminal window.

To make a connection to hosting server from terminal windows, that’s another topic we will cover them later in new post.

Hope this solves your finding.

Happy Learning