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!

Categories
Learning Learning Tech

How to sync generated next.js out folder build to android/android studio in capacitor?

Hello, Welcome to the feel and question.

Here is a quick way do it out!

Build the Next.js project: Run the build command for your Next.js project, which typically generates a production-ready build in the “out”/ “build” folder.

npx next build && npx next export

Locate the build output: Once the build process is finished, locate the generated “out” folder in your Next.js project directory.

Copy the build output: Copy the entire contents of the “out” folder, including any subfolders and files.

Paste the build output in the Android project: Navigate to the root directory of your Android project in Capacitor. The default location is usually the “android” folder within your Capacitor project.

Paste the build output: Paste the contents of the “out” folder into the appropriate location in your Android project. By default, you can paste it into the “app/src/main/assets/public” directory of your Android project.

Sync the Android project: After pasting the build output, trigger a sync operation in Android Studio to ensure the changes are recognized. This can be done by clicking on the “Sync Project with Gradle Files” button or by selecting “File” -> “Sync Project with Gradle Files” in the Android Studio menu.

Build and run the Android project: Once the sync operation is complete, you can build and run your Android project to deploy the updated Next.js web application within your Capacitor app.

Voila you are done!.

Hope this question and learning helps.

Happy Learning!