Check out the official docs – Build your app from the commandline. You can use gradle commands depending on which variant you want . For example, ./gradlew installDebug will make a debug apk and load it onto a connected device (though it won’t open it like Android Studio does).
Read moreHow do I Build an APK in Android Studio?
In the Android menu, go to Build > Build Bundle(s) / APK (s) > Build APK(s) . Android Studio will start building the APK for you. Once done, a pop-up on the bottom right will notify you of its completion. Click the ‘locate’ button in this dialog.
Read more