I have a multi-module build that has multiple variants, for example modules App, LibA and LibB and variants release, debug, and tester. When I run a build profile for the tester variant, I see under dependency resolution that the following are running:
App:releaseCompileClasspath
App:releaseRuntimeClasspath
App:releaseImplementationDependenciesMetadata
App:releaseRuntimeOnlyDependenciesMetadata
App:releaseAnnotationProcessorClasspath
App:releaseApiDependenciesMetadata
App:releaseCompileOnly
App:releaseCompileOnlyDependenciesMetadata
These extra tasks are slowing down my build, is there any reason they are running or any way to disable them?
Voila! This exact scenario has been targeted in Android Studio 3.3!
Android Studio 3.3 now supports Single-variant project sync!
As per the latest release notes for Android Studio 3.3,
Syncing your project with your build configuration is an important step in letting Android Studio understand how your project is structured. However, this process can be time-consuming for large projects. If your project uses multiple build variants, you can now optimize project syncs by limiting them to only the variant you have currently selected.
Requirements:
Android Studio 3.3 or higher
Android Gradle plugin 3.3.0 or higher
Steps:
Click File > Settings > Experimental > Gradle (Android Studio > Preferences > Experimental > Gradle on a Mac) and select the Only sync the active variant checkbox
Related
After downgrading from Gradle 6.1.1 to 7.2 and Android Gradle Build tools 7.1.0 to 4.0.1 (by switching branches in Git) I got the following exception in the Run console (tool window) of Android Studio Bumblebee 2021.1.1 (when trying to run the app on a device):
Unable to determine application id: com.android.tools.idea.run.ApkProvisionException: Couldn't get post build model. Module: My_App.app Variant: debug
The Grade build runs successfully but the app won't be installed in the device.
In Android Studio run File > Invalidate Caches ... and restart (you don't need to select the optional "Clear file system cache and Local History"). Just to be sure, also run Build > Clean Project.
I have faced this issue when i upgrade to android studio Dolphin. So for me this workaround was to delete the existing app configuration from Run/Debug Configurations.
After that add new configuration by clicking the left top + icon and then add Android App.
In my React Native project I'm using react-native#0.63.4, and following the migration guide from a previous version, I have the following line in my android/build.gradle file:
classpath('com.android.tools.build:gradle:4.1.3')
When I recently opened the project in Android Studio it recommended I upgrade my Android Gradle Plugin from 4.1.2 to 4.1.3.
What I Want To Know: What's the difference between the Android Gradle Plugin version referenced in my build.gradle file and the one in Android Studio? What effect does each have on the other, and how is each used in my app itself?
First of all, let's start with what build.gradle does:
Gradle is an open-source build automation tool that is designed to be flexible enough to build almost any type of software.
The Android Studio build system is based on Gradle, and the Android Gradle plugin adds several features that are specific to building Android apps.
Gradle build scripts are written using a Groovy or Kotlin DSL.
There are several differences on versions like:
Incremental Builds
Build Caching
Incremental Subtasks
Incremental Annotation Processing etc.
When you update Android Studio, you may receive a prompt which is telling you upgrade your project gradle. This is because you upgrade your Android Studio plugin, not the project. With this upgrade you can have some developed functionalities in gradle like above.
Surprisingly, my project is completely written and developed in Java only, it's also not containing any dependencies declared for Kotlin. Yet I'm receiving this weird error:
A problem occurred configuring project ':app'.
Configuration:
When I use the below configuration, it works perfectly fine, builds the project and the app gets installed on my device/emulator:
Android Studio Version: 3.1 Stable release
Gradle Plugin Version: 3.0.1
Gradle Distribution URL:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
BUT When I use the latest configuration declared below, the error occurs while running the app as shown in the images:
Android Studio Version: 3.1 Stable release
Gradle Plugin Version: 3.1.0
Gradle Distribution URL:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Steps I've followed/things I've tried:
Clean Project
Rebuild Project
Sync Project
Deleting build folder from project tree
Checked that project doesn't contain any names, references or declarations missing
Invalidate Caches/Restart
Check the whole dependency tree to make sure any Kotlin dependency is not imported or used as my project doesn't make use of Kotlin language
None of the above have worked!
I think instant run might be creating issue .
Do one thing disable instant run in android studio and try again .I think it might will resolve issue .
Try to update Android Studio. Turn off Instant Run from Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run.
I was working on android studio 1.4, there clicking on gradle sync icon ("Sync Project with gradle files") on the top middle , performed only sync for gradle scripts, no build.
Now in Android Studio 2.2, clicking on gradle sync perform sync and build both.
Is there a way to stop AS from doing that, no build, only sync.
Found it myself, we have to tick the "skip source generation.." in gradle experimental settings. For my purpose I have given the value 0 in module numbers.
In android studio when we build the project there are two options for building the project in:
settings->build Tools->Gradle->Project-level settings
The first option is "Use default gradle wrapper" and the second option is "Use local gradle distribution"
My question is which option is faster and when will it be used?
You can read about Gradle Wrapper in the official user guide.
The main thing about the wrapper - it cares about the Gradle version used to build your project. So, if one has configured the project to use a wrapper, then everyone will build it with the same version of Gradle. The version of Gradle could be specified in the configuration file called gradle-wrapper.properties.
One more important thing is that Gradle distribution will be included in your project and if someone will try to build it, no local Gradle installation will be needed.
But if you choose use local gradle distribution, then your project will be built with the version of Gradle you have currently installed and it doesn't guarantees, that your project will be built correctly, since Gradle version may differ.
I don't think, that time is different for this two cases, but wrapper usage seems to be preferable. Sure, in this case, you have to store wrapper distribution in your version control system, but you can set build tool version exactly used to build your project and make no one install Gradle manually if he doesn't have Gradle installed yet.
I want to add a very important point to the Stanislav's answer. Gradle could be used not only for building your project from Android Studio, but also the from command line. This is especially important if you want to build it in CI environment. In that case, you don't need to care about specific gradle version on your server. The project will be built with the same version for both IDE and CI and this will make your build stable and predictable.