24

I want to learn how it works to build Android program. Do you know where I can download the source code of the build plugin of com.android.build.gradle?

halfer
  • 19,824
  • 17
  • 99
  • 186
user3236879
  • 511
  • 2
  • 7
  • 17

6 Answers6

22

If you have Android Studio, the android gradle plugin and an android app that builds, you should be able to find gradle plugin source code on your own development machine.

  1. cd into your home dir
  2. cd into .gradle/caches/modules-2/files-2.1/com.android.tools.build/gradle-core/
  3. use a deep search tool (such as find) to look for a file with a name like 'gradle-core-2.3.1-sources.jar' (Note: the '2.3.1' in this example is only one possibility. You may have a different version. And there may be multiple versions on your machine.)

In other words, the downloaded plugin source jar files are stored by gradle down a path that looks something like:

~/.gradle/caches/modules-2/files-2.1/com.android.tools.build/gradle-core/2.3.1/59c72f62795f6ce6dd95c0b2e91c16dc16a1c8c7/gradle-core-2.3.1-sources.jar

(On your machine the hash and version in this path may be different.)

You can copy that jar file to another location and then unzip it to see the actual source files for the android gradle plugin:

./com/android/build/gradle/api/AndroidArtifactVariant.java ./com/android/build/gradle/api/AndroidSourceDirectorySet.java ./com/android/build/gradle/api/AndroidSourceFile.java ./com/android/build/gradle/api/AndroidSourceSet.java ./com/android/build/gradle/api/ApkOutputFile.java
./com/android/build/gradle/api/ApkVariant.java ./com/android/build/gradle/api/ApkVariantOutput.java ./com/android/build/gradle/api/ApplicationVariant.java ./com/android/build/gradle/api/AtomVariant.java ./com/android/build/gradle/api/AtomVariantOutput.java ./com/android/build/gradle/api/BaseVariant.java ./com/android/build/gradle/api/BaseVariantOutput.java
. . .

albert c braun
  • 2,650
  • 1
  • 22
  • 32
12

Is this one what you are looking for?

Thomas
  • 174,939
  • 50
  • 355
  • 478
Stanislav
  • 27,441
  • 9
  • 87
  • 82
5

Instructions for building the gradle plugin are here;

http://tools.android.com/build/gradleplugin

Which directs you to use repo to get the source, but also hints that the plugin can be found in tools/base.

Which you can clone, or browse online here;

https://android.googlesource.com/platform/tools/base/

Jeremy Lakeman
  • 9,515
  • 25
  • 29
3

You can download the source, jar (or other artifacts) directly from Google's Maven Repository:

https://maven.google.com/web/index.html#com.android.tools.build:gradle

Screenshot of Google's Maven Repository

Kartik Soneji
  • 1,066
  • 1
  • 13
  • 25
1

Set gradle 2.3.1 as exmple, you can download gradle plugin source code as follow:

$ mkdir gradle_2.3.0

$ cd gradle_2.3.0

$ repo init -u https://android.googlesource.com/platform/manifest -b gradle_2.3.0

$ repo sync

xiaohu Wang
  • 859
  • 7
  • 4
0

The instructions for Building the Android Gradle Plugin point to the Android Studio Project Site, which points to how to clone the massive repository that includes the entire Android Studio itself.

However, you may consider it over-kill, consuming unnecessary time and hard disk space, to be cloning the entire repository just to get the Android Gradle plugin, and then sync'ing the whole repository from time to time when you want to get the latest versions.

Google's notes on Checkout and build the source code gives a couple of helpful pieces of advice:

  • repo sync has a -c flag that can be used to sync "only the current branch to reduce sync time and disk space" (use it as repo sync -c)
  • For more on how to use repo, they suggest to see https://source.android.com/source/using-repo
  • You can look for the tag for a specific version of gradle, and it would be in the form gradle_x.y.z

Following up on the last point above, you can do

$ repo init -u https://android.googlesource.com/platform/manifest -b gradle_3.4.0
$ repo sync -c

to get just the gradle plugin version 3.4.0 ; even then, it would still be something like 21 Gb (includings lots of tools, prebuilts, etc.).

If you just want to view the source code for study purposes, but not to modify/build it, one of the other answers to this question may suffice. However, if you may want to modify and/or build the Android Gradle Plugin yourself, and have at least 21 Gb to spare, you may consider following the above suggestions.

auspicious99
  • 3,902
  • 1
  • 44
  • 58