The last blog said that every line of code in Build.gradle is basically called a method, and since that's the case, we can use the Android Studio (hereinafter referred to as) to see its source method annotation description, so you can understand what each method is done, Even in the great God's build.gradle met some not understand the code, you can also click to see the method introduction to understand. Just like we're looking at the various methods in the SDK.
But there is a problem, should also have a small partner like me, each time in the Build.gradle see a bunch of code do not understand, press and hold the Ctrl key, the mouse moved to the code when there is a jump gesture is always very happy, always thought the original can look at the source Ah, then point in to see the introduction, What do you think this is? But every time you go in, the Open is a class code file, at most, only the method name, a little comment is not, and the method parameter name is also confused, also can not guess what to do. Do not know how to go to the official documents to find, can only go online with the keyword search, to find out and with their own problems are not the same, the more you find the gas simply do not find, put aside, and later.
Yes, if you can directly through as to see the source of comments that much better. Okay, nonsense to this, start with the text below.
Series Index
Build.gradle Series One: Can not understand the Build.gradle code
Build.gradle Series II: Learn some groovy to understand Build.gradle code
Build.gradle Series three: How to use Adnroid studio to view Build.gradle source code
...
Body
Let's cite an example, like the one in the blog of the series Build.gradle, which has the code:
Hey! This code is the first time seen in the build.gradle, what does it mean? Not afraid, I have the trick:
Android Studio Dafa---Look at the source code, and what can not be solved by looking at the source code comments
is jumping to the source, but why there is no method of comment description, this method is what ghosts who know ah. Take a closer look at the AS hint, originally opened is a class file AH.
As the hint there should be a download and select the source Location button, ah, do not understand why does not appear.
In addition, we know that as is generally the default first open Xxx-sources.jar that is xxx Java file source code, if there is no source file, will open the Xxx.jar class code. Let's see what file is open.
Yes, as Open is Gradle-2.3.0.jar, stating that as did not find Gradle-2.3.0-sources.jar source files, we look at the end is not so
as The title bar will show you the exact location of the file you are currently opening, so, knowing the location of Gradle-2.3.0.jar in the computer, let's go to that directory and see if
has only one Gradle-2.3.0.jar file and one pom file, normally there should be a The Xxx-sources.jar file is right, just like the following
because there is no Gradle-2.3.0-sources.jar file, as there is no way to open the source file with the method comments. Now that you know the problem, then it is good to solve, as the cue bar also has no download button, then we have to download the
to open the MAVEN website, where you can download the Gradle plugin. Enter &NBSP in the search box; com.android.tools.build , why do you enter this, you open the Build.gradle file under project to see what
These are Gradle plugin, we are in the root directory of the Build.gradle configuration of the Gradle version is actually to download here, it should be.
After the download of these files, the next step is to find the location of the file, copy a past
to open the appropriate plug-in folder, select the appropriate version, and finally copy the downloaded Xxx-sources.jar, the final look is as follows
OK, we're done, we'll open as again, remember to ReBuild it, and then try to see what Build.gradle source will look like
Translate the English is probably say, Lintoptions.abortonerror = False is to set the run of the build program even if an error is found during lint check.
This method is much more convenient than going to the official API documentation. Take a look at several effects.
Here you can see the source code to introduce the value of Plugin, which corresponds to which class, which class to see what its role is, what to do.
With AS, we can even easily find android{...} out which methods are available in this parenthesis, and if you want to see what each of them does, then go ahead and check the comments. is not found that we used in the build.gradle of the name of the android{...} original label is here AH.
In the future, it will be the Build.gradle file of the big God have not seen the name of the label, no longer worry about not understand. Do not understand the source code comments, so easy!
Of course, there will be some groovy code or task in the Build.gradle file of the great God, which is not found in the Gradle source code, need to know a little bit about the basis of groovy and Gradle language, interested can continue to read the following I wrote this A series of related blogs, of course, the ability is not enough, if you want to learn better, online information is also many.
Recently opened the public number, want to motivate themselves to persist in writing, the initial main share of the original Android or ANDROID-TV aspects of the small knowledge, interested can point a wave of concern, thank you support ~ ~
How to view Build.gradle source code in Android Studio