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
Learning Tech

What does this actually means: Warning: The signer’s certificate is self-signed. POSIX file permission and/or symlink attributes detected.

If you encounter this warning message on CLI

What does this actually means: Warning: The signer's certificate is self-signed. POSIX file permission and/or symlink attributes detected. These attributes are ignored when signing and are not protected by the signature.

on after your local Android APK build for release version, basically it means, as learned from AI source to understand it real cause of the warning, so no need to worry much, you can continue reading the details for more understandings.

It indicates that the certificate used to sign the file is self-signed, meaning it was generated by the developer rather than being issued by a trusted certificate authority.

Additionally, the warning mentions POSIX file permission and/or symlink attributes. POSIX refers to the Portable Operating System Interface, which defines a standard set of APIs for compatibility between different Unix-like operating systems. The warning suggests that the file permissions and symbolic links present in the file are ignored during the signing process and are not protected by the digital signature.

This warning is informational and does not necessarily indicate an error or problem. Self-signed certificates are commonly used during development or testing stages, but for production or public distribution, it is recommended to use certificates issued by trusted certificate authorities.

If you are encountering this warning while signing an APK file, you can consider obtaining a certificate from a trusted certificate authority to replace the self-signed certificate. This will provide users with more confidence in the authenticity and integrity of the application. However, if you are using a self-signed certificate for personal or internal use, you can generally ignore this warning as long as you trust the source of the file and its contents.

It’s important to note that the warning regarding POSIX file permission and symlink attributes being ignored during signing does not have a significant impact on the functionality of the signed file. The signature primarily ensures the integrity of the file contents and detects any modifications made after signing.

Happy Learning!