Tutorial How to compile Android Studio project via command line

AndnixSH

PMT Elite Modder
Original poster
Staff member
Modding-Team
Jun 27, 2017
4,679
296,805
1,213
Modding World
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

1623080444865.png


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

1623078652350.png


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\

1623082009736.png


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

1623081849850.png


Libs will be outputted to [Project]\app\src\main\libs

1623081987281.png


That's pretty much all. You are now free of Buggy Studio
 

Attachments

Last edited:

3.Sav.Modz

Platinian
May 19, 2021
31
87
8
23
Modding Universe
well , we can auto set it :D ,
by this way you will face issues on the devices that did not have android studio before , cuz for the NDK ,
you will have to manually install it , unless you specify the licence folder in the SDK path as well , so all files will be automatically downloaded ,
and if we set the path in system with ANDROID_SDK will be better for it , so we dont have to manually change in every template we use .
beside the gradle we can set any latest version in the path too , and any location on the PC ( disk c or d or whatever) {{ with any version of the gradle we will be able to avoid invalid syntaxes with whatever version of the gradle of the build.gradle file such as 4.1.2 with gradle 6.8.3 or any numbers will be working fine .}}}
 

AndnixSH

PMT Elite Modder
Original poster
Staff member
Modding-Team
Jun 27, 2017
4,679
296,805
1,213
Modding World
@3.Sav.Modz
by this way you will face issues on the devices that did not have android studio before , cuz for the NDK ,
you will have to manually install it , unless you specify the licence folder in the SDK path as well , so all files will be automatically downloaded ,
I already said in the thread:
> Assuming you have Android Studio, SDK and NDK installed.

if we set the path in system with ANDROID_SDK will be better for it , so we dont have to manually change in every template we use .
I already said in the thread:
>Additionally you can set the environment path to your SDK
>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

with any version of the gradle we will be able to avoid invalid syntaxes with whatever version of the gradle of the build.gradle file such as 4.1.2 with gradle 6.8.3 or any numbers will be working fine .
Well, i mean AS shows invalid syntaxes randomly even it still able to compile, and LGL was using newer gradle. Maybe it has been resolved but man i just hate AS, and i wanna give up using it

Thread edited
 
  • Love
Reactions: 3.Sav.Modz

LEIIKUN

Retired Staff
Retired but loved <3
Oct 13, 2019
502
10,945
1,193
20
Davao
I also used this for lib only, without creating .bat file, you'll just need to run a cmd or powershell inside the ndk folder that you've downloaded:

Code:
ndk-build -C directory-of-the-jni-folder
 

AndnixSH

PMT Elite Modder
Original poster
Staff member
Modding-Team
Jun 27, 2017
4,679
296,805
1,213
Modding World
I also used this for lib only, without creating .bat file, you'll just need to run a cmd or powershell inside the ndk folder that you've downloaded:

Code:
ndk-build -C directory-of-the-jni-folder
Nice one but i'm lazy to give directory to jni folder so it's better with the bat file
 
  • Like
Reactions: LEIIKUN

Numark

Awesome Active Platinian
May 23, 2017
116
925
193
Nice one, may use this due to the fact AS being stupid most of the times. 😴
 
  • Like
Reactions: AndnixSH