Learning

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.

admin

Recent Posts

What I Learned After Taking Break from Instagram for 30 Days

Break! I didn’t plan it. One day I just didn’t feel like opening Instagram—and then…

2 days ago

5 AI Tools That Actually Save You Time (And Aren’t Scary)

AI tools Let’s be real—AI sounds like either a robot apocalypse or something only tech…

2 days ago

Summer Learning Ideas

Summer vacation is a great time for kids to explore, have fun, and learn new…

5 days ago

Understanding How ChatGPT Works (ML/AI learning path)

Goal: Understand transformers, large language models, and the architecture behind ChatGPT. Tutorial Suggestions: ✅ “Transformers…

5 days ago

Using ChatGPT API (for developers)

Goal: Build apps or tools with ChatGPT or GPT-4 API. Tutorial Suggestions: ✅ OpenAI API…

5 days ago

Using ChatGPT Effectively (for general users or productivity)

Goal: Learn how to prompt better, write content, brainstorm, code, etc. Tutorial Suggestions: ✅ OpenAI's…

5 days ago