Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it mandatory to use Gradle with Android Studio?

I'm using android studio since its official release. Till now which I use Android Studio version 2.1.2, I need to wait for hours to import a project for first time and let gradle synchronize. Some people recommend to run android studio in offline mode but when I want to use external libraries I need to make my project synced and so I have to enable gradle.

Is there a way that I can get rid of Gradle?

As an example:

4:19:03 PM Executing tasks: [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:prepareDebugUnitTestDependencies, :app:mockableAndroidJar, :app:assembleDebug]

And now it is 4:30 and still gradle build is running! It was just required to press F11 in Eclipse and debug application in 20 seconds.

like image 547
VSB Avatar asked Jun 09 '16 12:06

VSB


1 Answers

I need to wait for hours to import a project for first time and let gradle synchronize

Reduce your dependencies and identify the problem with your Internet connection. Presumably, something is interfering with your computer's access to sites like JCenter, where some of your dependencies are being pulled from.

You might run an experiment with a new scrap project, slowly introducing your dependencies from your main project, to identify where the problem comes in.

You might also examine the Gradle Console while the build is going on, to see where it is getting stuck.

You might also try running a command-line build, with Android Studio closed. If this dramatically improves matters, my guess is that you have insufficient RAM on this development machine. Personally, I would not dream of using Android Studio on less than 8GB.

when I want to use external libraries I need to make my project synced and so I have to enable gradle

AFAIK, moving out of offline mode should only be necessary when you change your dependencies (add, change versions, and possibly remove).

Is there a way that I can get rid of Gradle?

Switch to a different IDE, one that supports alternative build systems. I am not aware that Android Studio supports anything other than Gradle.

You may run into the same problems, if you try using live online dependency resolution, because those other build systems will be pulling from the same locations and would encounter the same Internet access problems (if that is the source of your difficulty).

Part of the reason why Eclipse was not giving you trouble is that Eclipse was not resolving dependencies. It just used whatever you had in libs/ and attached library projects and that was it.

There is nothing stopping you from applying the Eclipse approach to Android Studio development, even if offline Gradle mode is not working. Most of your dependencies will fall into two buckets:

  • Stuff from repositories that you already have offline, such as the Android Support Repository and the Google Repository, both downloaded via the SDK Manager

  • Stuff that is open source

For the latter, go to the original project (e.g., GitHub repo), download the source code, and add it as a library module to your project, along with the sources for any transitive dependencies. Or, see if there is a tool out there that will let you manually download the artifacts (and transitive dependencies) from the repositories, then use them via compile fileTree().

Part of the reason that Eclipse ran faster is that it did less. For example, I am uncertain how much of the manifest merging feature we have with Gradle-based builds was available in Eclipse. For stuff like this, the problem is not "Gradle", but rather modern Android development.

In the end, you need to do what computer programmers do: debug the source of your difficulty.

like image 134
CommonsWare Avatar answered Nov 15 '22 16:11

CommonsWare