app:transformClassesWithDexBuilderForDebug takes very long time in Android - android

Whenever I checkout a different branch and build the app, this particular task takes around 10 minutes. It's awfully long.
app:transformClassesWithDexBuilderForDebug
Android Studio : 3.2.1
Gradle plugin: 3.1.3
I tried many things such as invalidate cache, clean build, clean whole gradle cache etc.
My app contains libraries which uses annotation processor.
Is there any direction to find out the root cause or anyone had a similar issue and solved it?

Related

Do not build Android project automatically on opening

I have been using Android studio for a long time, yet never understood what are the processes that Android studio runs at when we load a new project via File>New or File>Open. We just load the project and have to wait for so many minutes before the android studio completes those processes (I know that we can still click on file names and editor would open them, but i have observed the android studio will still lag until all those processes are completed)
However I don't know how, recently My Android studio started behaving differently. I don't know what i did, But every time i created a new project, or loaded a previous one, it would show a message like this:
This was very good for me, because even when i don't click the try again
button, I am still able to access all files and without any lag, thereby removing a need for external file editor. I feel this was some bug in gradle or cache handling that got fixed when i uninstalled AS and updated to AS 3.5 .
So is there a way to manually run all those build and indexing processes, instead of Android Studio just running them automatically?
UPDATE:
I think i was not clear before. I want that error to occur . Meaning I want to have a control over when the building process starts. Also, I am NOT having any error as of now, all my projects are working fine.
Look for highlighted warnings in you Gradle file, you may need to update some things and then sync again.
You could also try to clean and rebuild your project.
You can also File->Invalidate Caches / Restart if none of the above work.
If none of the above work, please provide more details on what warnings/errors you get.
When version conflict in gradle file, it cant be able to build and sync the project.There may be show "Unsupported Modules Detected: Compilation is not supported for following modules”. Fix them too

Android gradle build time exponential increase

My Gradle build time is usually around 12 seconds, but after around 10 - 20 builds it starts to increase at once, exponentially: 30 seconds, 50 seconds, 2 minutes, 5 minutes, etc. up to out of memory.
Healthy build:
:app:compileDev21DebugJavaWithJavac 4.783s
:app:transformClassesWithRealmTransformerForDev21Debug 3.011s
:app:transformClassesWithDexForDev21Debug 2.133s
:app:compileRetrolambdaDev21Debug 1.325s
:app:packageDev21Debug 0.997s
:app:processDev21DebugResources 0.703s
After 10 - 20 of those, it starts increasing:
:app:transformClassesWithDexForDev21Debug 39.172s
:app:compileDev21DebugJavaWithJavac 34.221s
:app:packageDev21Debug 9.922s
:app:transformClassesWithRealmTransformerForDev21Debug 8.353s
:app:compileRetrolambdaDev21Debug 3.120s
:app:fabricGenerateResourcesDev21Debug 1.376s
As you can see, every task increases in time.
I use Android Studio 2.2.2, but I had the problem since the last 3 versions or so. Gradle 2.14.1. Probably it’s related to our project. I use Mac, my colleague on Windows has the same on the same project. If I stop AS, kill Java and start AS again, that solves it for a while.
I am not using the Jack compiler (yet).
To be clear: my build time is NOT generally slow: 13 seconds is fine. This is not a duplicate of all the "slow build time" questions. Only after 10 - 20 builds the build time increases exponentially with every build.
Update: Make Gradle build "offline" didn't help. Using "gradle-3.1-all.zip" (distributionUrl in grade-wrapper.properties) also did not help.
Anyone had this problem and knows a solution?
I experienced(and somehow still facing) the same issue. There are some fixes that you can try.
1- Make Gradle build Offline.
2- Install Gradle on machine and use local installation alongside Offline work checked in Android Studio instead of Using wrapper which connects to proxy and takes more time with building cache of Studio.
I followed this and this article and it helped me not substantially but enough to get me nearly 6,7 hours of continuous development on 8GB memory system then i have to Invalidate and Restart.
It is fixed since the day that I removed Fabric (CrashLytics) and replaced it with FireBase Crashes. Fabric was most probably causing it, but I'm not 100% sure.

Android Studio Build Gradle Runnig too long without end

I have a project which was working very well on android studio , suddenly it turns not able to build anyway .. It keeps telling Build Gradle Runnig without any result for 30 min !
I tried to clear .gradle file of project without result.
I tried to uninstall android studio and clean all its files from user directory AndroidStudio 2.1 and .gradle files and also no result.
This problem occures only with this project and others working fine on android studio ..
What should I do to make my project build again ?!
I had that once when I updated the gradle wrapper. It really took 45 minutes to download that 16MB or so. I had to that time some network issues with their repo servers.
Try to run in the console gradlew aR and see what happens. If you see there hundreds of dots you need to wait if there happens nothing kill all java processes and try again.

What's the fastest way to run unit tests in Android

There are two options available to run unit tests in Android Studio:
Right click on the file with your unit tests (which is Gradle-Aware Make).
testAppDebugUnitTest task is from the list of available Gradle tasks.
The first one actually consists of two tasks:
- :app:assembleAppDebug and :app:assembleAppDebugUnitTest
The second one is just testAppDebugUnitTest itself.
The first one is a recommended way by Google Tools Team, but it takes as twice as much time compared to the second one.
There is no visible difference how to run unit tests except the duration. You might think your code won't be compiled without assembleAppDebug, but this is not true - changes you introduce to either class under a test or a test itself compiled and executed as expected.
So, what's the difference and why is it the recommended way if it takes as twice as much time to prepare everything before actual unit tests run?
I don't have much work experience with Gradle, But off course it is always better to use Google Team recommended tools instead of others.
it takes as twice as much time compared to the second one.
If you use the new Gradle build system with Android (or Android Studio) you might have realized, that even the simplest Gradle call (e.g. gradle project or grade tasks) is pretty slow.
To avoid this time taking processes in android studio you need to Speed up Gradle build time. It will definitely makes a difference
Here is few steps to speed up the Gradle build time >>
In compiler settings (Android Studio -> Preferences -> Project
settings[your project] -> Compiler (Gradle-based Android Projects)),
type --offline in the "Command-line options" box.
from ~4 minutes to ~20 seconds.
In another way, You can decrease this startup time of Gradle (on my computer down to two seconds), if you tell Gradle to use a daemon to build. Just create a file named gradle.properties in the following directory:
/home/<username>/.gradle/ (Linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)
Add this line to the file:
org.gradle.daemon=true
From now on Gradle will use a daemon to build, whether you are using Gradle from command line or building in Android Studio. You could also place the gradle.properties file to the root directory of your project and commit it to your SCM system. But you would have to do this, for every project (if you want to use the daemon in every project).
Note: If you don’t build anything with Gradle for some time (currently 3 hours), it will stop the daemon, so that you will experience a long start-up time at the next build.
For more details please refer this Building and running app via Gradle and Android Studio is slower than via Eclipse
Performance improvements are one of the great tasks in the Gradle roadmap for 2015 (and reaching into 2016). So hope, we’ll see the general performance increasing within these years.
n g+ there is a discussion with the developers about it.
Hope this information will helps you.
The reason your option 1 takes twice as time is because most of the time is wasted on spinning up Gradle and checking if tasks are up to date. So running an no-op assemble will make it twice as long. You can verify this by running it yourself and check the time wasted by doing an no-op.
With gradle, running with "--offline --daemon --parallel" can get you somewhere (offline is helpful when you have slow internet access to Maven/JCenter repos, daemon is helpful to keep files cached, and parallel is particularly helpful if you have MultiDex on and have split your app into small modules)
If you are just asking about "What's the fastest way to run unit tests in Android?" without considering the change you would need, I would recommend switching to Buck (https://buckbuild.com/), which is 10x faster than Gradle on dex-xing and spinning up tests but has limited AS support.

Painfully slow make with IDEA 12.0

I love the new incremental Java compile in IDEA 12.0 but there seems to be a price to pay. Making now takes about twice as long as in 11.x, most of the time appearing to be spent
Executing DEX
(according to the status bar).
I can take a 12.0 project, revert to 11.x and making is back to "normal speed" (approx 4 minutes vs 30 seconds).
I don't get this. AFAIK, IDEA (or Eclipse or any other IDE) is just shelling out to dx.jar to compile the Dalvik executable. If there was a problem with the ADT, it would affect 11.x equally.
OS is Win 7 Ultimate. 3.2GHz quad core with 16GB but I suspect that the issue is not related to OS or PC since 11.x is OK.
Any ideas? I'll log a bug with Jetbrains but wanted to see if anyone has more concrete info or workarounds? There's nothing so far on the Jetbrains bug tracker or fora that I can find.
I have had this issue a couple of times in the past and it's always been due to the inclusion of a global library that hangs during build.
On one occasion it was due to the Python libraries trying to execute when the Android project was built because I had a python file in my Android project and IntelliJ decided to add the Python runtime libs to my project dependencies.
More recently the same thing happened with Groovy when I had a gradle file in the Android project.
For me I simply removed these dependencies from the project and the problem resolved itself.
In my case I discovered this by force killing (kill -9) the java process that was running the make. This caused intellij to dump the error to the Messages view in the IDE where I could see groovy trying to execute.

Categories

Resources