How to compile Android Studio project via command line
Android Studio IDE has become more buggy and shit, stuck on loading devices, invalid syntaxes even it still able to compile, random freezing, high CPU usages on idle, and many more. Maybe i’m dumb, but honestly it works like shit. Invalidate caches and full reinstall doesn’t help much. i’m tired of it, and gave up using it so I needed to find a way to compile via command line instead. Using Notepad++ and CMD is so much better for me. Today I will share my way to compile an Android Studio project via command line. I will use LGL menu as an example LGLTeam/Android-Mod-Menu
I will not explain the techinal details about how to set environment variable path, extracting zip, installation, etc, as the internet already covers. Just search how to do it
Correct me if i’m wrong, i’m not the best in Android development
Setup and Installation:
Assuming you have Android Studio, SDK and NDK installed. If not, please install them, gradle will not work without them
Additionally you can set the environment path as ANDROID_SDK to your SDK
IMPORTANT: Know the gradle version of the project, take a look on \gradle\wrapper\gradle-wrapper.properties for the version. This one is 6.7.1
Follow this site and download and install Gradle version that matches with the project. Set environment path to your [gradle location]/bin folder
Using mismatched Gradle versions may cause a lot of errors, I made a mistake using latest version of Gradle that didn’t match with 6.7.1. Please change the version in the gradle-wrapper.properties if you want to use other versions than the project’s, and make sure the version match
If you haven’t set the environment path to your SDK, you can create or edit the local.properties file and set path to your SDK
Example:
Code:
sdk.dir=E\:\\Android-SDK
Recommended that you already set the environment so you don’t need to change local.properties
Compiling the project:
Open CMD/Powershell/Terminal/ and CD to the project path, or launch the CMD/Powershell/Terminal directly from File explorer if your system supports it, so the path will be automatically changed to that
Build the project and output debug APK straight forward. Fix the errors if any.
Code:
gradle assembleDebug
APK will be outputted to \app\build\outputs\apk\release\app-release.apk
See more: Build your app from the command line | Android Developers
Compiling lib only:
This method doesn’t need gradle, only NDK needed
Create a file called compile.bat (Windows) or compile.sh (Linux/macOS) to [Project]\app\src\main\
Add these, change NDK path to yours and save
Code:
E:\Android-SDK\ndk\22.0.7026061\ndk-build
NDK_PROJECT_PATH=\
NDK_APPLICATION_MK=\jni\Application.mk
Then just double click the batch/sh file to compile.
But this way you can’t see the errors as it closes instantly. It’s recommended you leave the CMD/Powershell/Terminal open with the path changed to [Project]\app\src\main\
So you can just type
Code:
./compile
You can see if it successful or not
Libs will be outputted to [Project]\app\src\main\libs
That’s pretty much all. You are now free of Buggy Studio