How to get verbose messages of gradle sync? - android

I have a multi-module (>20) project in Android Studio. The problem which I am facing is that whenever there in some change in build.gradle file of any module or if a new module is added, Android Studio asks for gradle sync which takes insanely high time (~12-15 minutes) and memory (order of 5GB). I want to know why what is causing this? Is there a way to find out what happens during gradle sync? Is there a terminal command to run gradle sync?
Please help!

I have been trying to figure out what actually happens during a gradle sync and how one can improve gradle sync timings. I am summarizing what I have found in this answer.
Gradle sync is an Android Studio feature. Its sole purpose is to update the project model in Android Studio with respect to the build.gradle files in the project. For example, you might notice that a newly created module in your app is shown as a directory, but after gradle sync (assuming you have appropriate build.gradle for that module which points towards java sources, tests, resources etc.) the module is shown as a library (with a icon on your module's directory) in Android Studio. You may refer to helpful answer here.
In a project which has large number of modules, you might notice that the gradle sync process consumes a lot of time and memory. I do not completely understand the reason behind this, but changing the vmstudio.options file to following configuration has helped me improve the gradle sync time to some extent:
-Xms512m
-Xmx4g
-XX:MaxPermSize=2g
-XX:ReservedCodeCacheSize=512m
-XX:+UseCompressedOops
I hope this is useful!

Related

Unsupported kotlin version

My gradle build completes successfully, but I get:
WARNING: Unsupported Kotlin plugin version.
The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `1.5.31` that
might work differently than in the requested version `1.6.10`.
All of my build.gradle.kts scripts refer to using version 1.5.31. The only association my project has with version 1.6.10 is that Android Studio has the Kotlin version 1.6.10 plugin added. If I try to disable that plugin, I get a message that several other plugins will be disabled. If I accept that, android studio crashes and will not start up again. It won't start up again even if you reinstall android studio again. The solution is to find the file named "disabled-plugins.txt" and delete that file. It's in your AppData folder and in a JetBrains subdirectory. It turns out that it's one or more of those other disabled plugins that prevents Android Studio from starting up again.
The question I have is how do I fix this version mismatch issue. I can't delete the plugin from Android Studio for the reasons I mentioned above. If I try to update my project to using version 1.6.10 I get literally 100's of unresolved dependencies. And it seems from opinionated investigation that 1.6.10 still have too many issues for general use.
By the way, when I look at the gradle window for the project I can see where the dependencies come from. Usually when I look at the gradle window I just see sub project folders that I can drill into for more information, but for this project, it has an additional folder name dependencies. I don't know how they get into my project. But when I look at their version numbers that's where the 1.6.10 mismatch happens.
So, I think I understand why the warning message is valid, I'm at a lost on what I need to do to correct this situation. For the moment, I'm just ignoring the warning, and so far I'm not finding any issues in proceeding that way. But that's means I'm proceeding, without an understanding of what's going on here! Sometimes that's okay and at other times that's a bad judgment The error message itself seems inverted. I would think that 1.6.10 is the embedded kotlin and kotlin-dsl since it an android studio plugin, but the error message seems to say it in the opposite way. So anyway, if someone can bring some clarity as to what's going on, and how I'm thinking wrongly about this problem would be greatly appreciated.
I'll accept the following as the answer to what's going on about the unsupported kotlin version:
https://github.com/gradle/gradle/issues/13020
So, for the moment, I'll go on like this is just a nuisance warning and ignore that.
What I just did was to re-create my Android Studio from a blank brand new project. I copied and pasted stuff from the previous project into the new project. I copied the source and build.script.kts files, so essentially everything is a copy of the disabandoned project. This new project didn't give me the WARNING message anymore. And in additional, I'm now able to upgrade my project to using kotlin 1.6.10, which I previously couldn't do because of the literally 100's of dependencies resolution issues. Whatever, that issue went away, and a lot of others things started working as expected once I recreated the project. I can't say what got my project into that weird state. Deleting the .gradle and .idea folders, wouldn't fix the problem. I didn't try deleting the JetBrains cache, I wish I would have tried that.

Android studio NDK Gradle build "Source ... and destination ... must be different"

I'm using Android Studio with NDK, Gradle and CMake to build several shared libraries and link them together.
I keep getting the same error again and again in the build log:
:app:processDebugManifest [Passed]
:app:externalNativeBuildDebug [Passed]
Source C:\XXX\app\build\intermediates\cmake\debug\obj\arm64-v8a\libBGS-d.so and destination C:\XXX\app\build\intermediates\cmake\debug\obj\arm64-v8a\libBGS-d.so must be different
It's like gradle is trying to copy my library at the same position.
The thing is, I have no idea where this instruction comes from and how I can debug it. There's really not much indication in the build log.
What's confusing is that is doesn't occur 100% of the time. Seems like there is a race condition somewhere. Also sometimes it's another library that triggers the build to fail. Also, cleaning the project doesn't help.
So here's my question: is there any place where I can get granular control over the Gradle build sequence ?
According to Dan Albert at https://stackoverflow.com/a/62223434/8068814 this appears to be a bug and he suggests cleaning the project, then triggering "refresh linked c++ projects" and then building the project. Since it is sometimes working for you, this might be a reliable solution in your case.
For me this did not help, but reverting the Gradle plugin to 3.6.2 was the only way for me to build my project.

IntelliJ can't build Gradle project due to missing libraries

A while back I started a project that uses libgdx. It supports all platforms so I have a module for each in my project structure. The project worked for a long time and then I updated a few things in the IDE (I don't know what, I just accepted the updates) and nothing would build or run. Since I hadn't really made any changes I backed up my project folder, deleted it, checked out the project from github and tried to start over. Unfortunately no.
Every time I build the project I get this error:
Error:Android Gradle Build Target: java.lang.NoClassDefFoundError: com/android/utils/ILogger
When I go to file > project structure > Modules > android > dependencies the following libraries are all missing classes:
appcompat-v7-25.3.1
support-compat-25.3.1
support-v4-25.3.1
support-core-ui-25.3.1
support-core-utils-25.3.1
support-fragment-25.3.1
support-media-compat-25.3.1
support-vector-drawable-25.3.1
animated-vector-drawable-25.3.1
According to the IDE they are all supposed to be located in:
PROJECTDIR\android\build\intermediates\exploded-aar\com.android.support\LIBNAME
but \exploded-aar\ doesn't exist.
I have spent the whole day searching and trying different solutions to no avail so I don't even know if this is the problem. Any help is much appreciated.
There is an open bug logged for this problem. Please follow for updates.

Rebuild, Sync Gradle and Clean for just one Module with Android Studio

I have in Android Studio a complex project establish by five modules. Four of them act as independent apps, but one of them is the base code for the rest. This way, I can have a big common core and four separates codes for every app (these apps share the shame model data and api connection).
My question is if it is possible rebuilding, cleaning or syncing just for one module, non the entire project in Android Studio.
Thanks!
Nowadays with Android Studio you can use build -> make module “nameModule”
sure, just use the project name when running Gradle, e.g. gradlew :api:build. This will build api module only.
More details in the docs.
I face the same problem,search for Google,No answer direct question.
I find Android Studio Menu,find the method .
Run - > Clean and Rerun"modle name"
For the addition the all of answer you can type a specific gradle task instead:
https://www.jetbrains.com/help/idea/work-with-gradle-tasks.html#gradle_tool_bar
In my case, Press ^ (macOS) twice -> Type gradle :your-specific-dfm:build

Gradle execution fails: Unknown command-line option '--daemon'

I use latest Android Studio (0.8.2). On my other PC the same code is successfully builded.
It means that build scripts are correct.
So I assume that it is something with Gradle configuration, but I double rechecked all configs:
I completely removed .gradle folder under C:\Windows\Users{MyUser}.gradle to delete old configurations;
gradle.properties file doesn`t have any uncommented options
What do I miss?
NOTE! I have not specified '--daemon' option. Or I only think so:( I can`t find it in Gradle default and project specific settings
Also I created absolutely new project in the studio. It didn`t help - the same error(
The answer is very simple. It seems that new version of Android studio imported all setting from previous one. Some of old options added additional options to compiler
Android Studio always uses a Gradle daemon. It connects to the daemon via the Gradle Tooling API, and perhaps the latter doesn't understand --daemon (because it's redundant).

Categories

Resources