Does your Android Studio takes a lot of time to build and run??
If you have a low-end pc, then this time increases.
When I hit the run button, I sit and wait for gradle to get finished. One minute is gone, two minutes, three minutes.
In my old PC, Waiting has passed more than 30 minutes.
That affected my productivity very badly.
End of the day, I feel miserable, nothing is done, Still waiting for gradle build completion.
At that time, Just like any other beginner, I searched on Google “How to reduce Android build time”. But nothing gets worked.
Then I learned about the Gradle build system. after that, I got to know we can run the project using Commands.
So in this post, I will tell you a way that I am using which reduced my APK build time.
Yes, this is really interesting and It will be useful in the long run.
Before that, let’s make a simple talk about Gradle and gradlew.
What is gradle and gradlew??
Gradle is a build tool which makes APK using our source code and resources like layouts, images by giving them to suitable tools. When you click the run button, Android Studio delegates power to gradle and wait for it to finish just like us.
gradlew is a batch file in Windows. In Mac and Linux, it available in the form of a shell. You could find it on the Android Studio project’s root directory. It has the ability to pass commands to gradle. Using those commands we can make Gradle work. gradlew is also responsible for downloading gradle from the Internet.
If you are in the Android Studio project folder, Open your command prompt and Just type gradlew and press enter. The script runs and looking for a gradle in your system. If the desired one not found, It goes online and downloads gradle.
Let’s find out how to build APK using gradlew.
- Open the command prompt and navigate to the root folder of your project.
- Type ‘gradlew installdebug (‘without quotes) in command prompt and press enter key.
This command will start building process with the use of the gradlew.bat file.
If there are no errors, The APK will be moved and installed on your smart device.
Just tap on the app icon manually to launch.
Other commands
- gradlew -version – It shows us gradlew, groovy, JVM and OS versions.
- gradlew clean – Cleans the project by deleting build directory , actually reduces your project size.
- gradlew tasks – Shows all tasks.
- gradlew unInstallDebug – Uninstalls the app
- gradlew wrapper – Generates wrapper files.
- gradlew –help – Shows list of command line options.
Want to know more about build apps through command line
Conclusion
Everybody hates to be waited, there no change in build time too. Build takes so much time from our life and it increases the development period. High-level PC and gradlew installdebug command can help you to save your valuable time. Using gradlew and Gradle we can do so much stuff. If there is any other technique you use. Feel free to comment here and please share this article. Thank you, guys.
Make sure that you enabled USB debugging on your device and still connected.