The Curious Case of the Missing google()

The idea of having Gradle be the single “source of truth” was that so builds could be the same whether you were building in Android Studio, from a CI server, from ./gradlew, from gradle, or anything else. That has never been completely the case. For example, environment variables are unavailable to Android Studio builds but are available to other types of builds. However, having the same builds across the board was the stated objective, even if the implementation didn’t completely realize that objective.

Android Studio 3.0 adds a new difference in behavior: where the Android Plugin for Gradle comes from.

Try this: create a new Android Studio 3.0 project, and in the project-level build.gradle, delete google() from the repositories in buildscript, so you are left with:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

Your project will still successfully build in Android Studio… but it will fail to build from anything else. The Android Plugin for Gradle is no longer in jcenter(), and we removed google(), so command-line builds will fail to find the plugin:

* What went wrong:
A problem occurred configuring root project 'MyApplication'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.0.0.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.jar
     Required by:
         project :

Unfortunately, this is officially working as intended.

UPDATE 2017-10-31: This is happening due to an “embedded Maven repository” that supplies the Android Plugin for Gradle. You can disable this in Android Studio in the Settings app by navigating to Build, Execution, Deployment > Gradle > Android Studio, and checking “Disable embedded Maven repository”. Note that this is not showing up in searches in Settings at the moment, so you have to navigate there via the tree. Many thanks to somebody who I suspect is Xav Ducrohet for posting more comments on the issue.

In this particular case, it’s not a huge deal. It’s easy enough to add google(). But it does beg some questions:

  • According to the response from Google, “Android Studio comes with its own version of the gradle plugin in a private repository that is not accessible when building from the command line”. What if we do not want to use that version? For example, we might want to pull all plugins and other dependencies from a private artifact repository for security reasons. How do we tell Android Studio to not use its own private copy of the plugin and instead use the one that we tell it to use?

UPDATE 2017-10-31: Per the above update, you can disable this repo in Android Studio’s Settings.

  • In what other ways will builds from Android Studio diverge from command-line builds?