A bug a footprint that you use Gradle.
1 A lot of information on the web is old. Not applicable with the new version of the present gradle especially some gradle methods have been renamed the old can not use
2 between the web is paste copy and fragmented I am very painful ah, walked a lot of fruitless to get out, so I get a completely complete version
3 I will not only write Gradle will also write ant packaging method, I hope to help everyone
Before this you need to have an Android project (the project cannot have outdated methods)
There can be no eclipse or ADT, because as long as your project is OK, gradle can use it directly.
The more I'm going to say in the back, the more simple it is, but it's going to start with Satan.
Link to previous article
Http://www.cnblogs.com/uncle2000/p/4276833.html
Engineering: The root directory of all files for a single application is called a project
Here's my "XXX Project".
Configuration is over Gradle Next is the configuration in the code. This first one is simple, the next is complicated: using Gradle signature to confuse and rely on engineering how to configure dependencies such as: Appcompat_v7_6 this dependency project and not just the jar
1 Create a new or enable a project (the project is called the letter, do not use Chinese characters), to ensure that there is no error code in the project, no outdated code (that is, the underlined code) since it is domestic, then the code format of the project is "Utf-8" by default.
2 in the root directory of your project, the new file is named "Build.gradle" to open the input as text (you do not have my content to apply, you first tiger paste copy, I will speak later)
The most initial code is this.
//configuration of the GradleBuildscript {//The warehouse will never change. If you're also using eclipse to develop you don't have to understand what it means, you just call him a reference to an external code.repositories {mavencentral ()}//Gradle Self-reliant package (note not your project-dependent package!!!) )Dependencies {classpath' com.android.tools.build:gradle:1.0.0 ' }}//General Engineering write ' Android '. jar Package Project write ' Android-library 'Apply plugin: ' Android '//!!! This is where your project relies on the claims of the package (note that this method is not within Buildscript yo)Dependencies {}//configuration of the projectAndroid {}
I am from simple to difficult to write, so step by step,
About the code in the
// Gradle Self-reliant package (note not your project-dependent package!!!) ) dependencies { ' com.android.tools.build:gradle:1.0.0 ' }
Why is the Gradle version number 1.0.0? Remember that 2.2.1 that you remember in the last article? Yes, Gradle's 2.2.1 corresponds to the version of the package that the CLASSPATH relies on is 1.0.0 and there's a correspondence right away.
So this code only applies to 2.2.1 's Gradle is suitable for 2015, if certainly does not apply after many years, then for Gradle this function version and it depends on the version is how one by one corresponds? Basically no one on the internet, and talk about is let go to see the API, but I tell the truth, those URLs can not open, because it is Goole is blocked, so I do not see the API, I do not know how to one by one corresponding, this is my groping out of a result.
The next part of the chip code, do not worry about the addition, because the concept of gradle "domain" at the beginning of the I was engaged in a bug everywhere
// make Gradle not confuse the Chinese comments in your code
Special note that the parameters are javacompile instead of compile many older versions of Gradle and Android studio tutorials are all used without Java's pit Daddy!
Tasks.withtype (javacompile) {options.encoding = "UTF-8"}
// reference to project // compile is compiled means a verb. // filetree represents a heap of files // dir: What do you want to "compile" the "Heap of Files" address/drive letter, here we are going to put the project "Libs" All. Jars in the directory are compiled together, and Libs is a subdirectory of the project // *. The jar represents all the. jar end files, if any. So libraries are written in the same way (and then a subfolder of "**/*.so ') compile Filetree (dir: ' Libs ', include: ' *.jar ' )}
// your version of the SDK for this project don't say you don't know = = Compilesdkversion // This is the last place that 2.2.1 corresponds to 1.0.0 and corresponds 19.1.0, buildtoolsversion "19.1.0" // default False What does it mean I don't know enforceuniquepackagename=false // The default configuration is not actually written, the inside of the thing and manifest meaning is the same defaultconfig { + }
The above should not notice if you and I download is gradle2.2.1 then classpath must be followed 1.0.0 here buildtoolsversion must be 19.1.0
sourcesets { // can specify a storage path for each file this is the standard main {' androidmanifest.xml ' = [' src '] = [ ' src '] = [' src '] = [' src '] = [' res '] = [' Assets '] } }
Then put the code together (not complete yo ~)
Buildscript {repositories {mavencentral ()} dependencies {Classpath' com.android.tools.build:gradle:1.0.0 '} tasks.withtype (javacompile) {options.encoding= "UTF-8"}}apply Plugin:' Android 'Dependencies {Compile Filetree (dir:' Libs ', include: ' *.jar ')}android {compilesdkversion19buildtoolsversion"19.1.0"Enforceuniquepackagename=falseDefaultconfig {targetsdkversion19} sourcesets {main {manifest.srcfile' Androidmanifest.xml 'Java.srcdirs= [' src '] Resources.srcdirs= [' src '] Aidl.srcdirs= [' src '] Renderscript.srcdirs= [' src '] Res.srcdirs= [' Res '] Assets.srcdirs= [' Assets '] } }}
If the following error occurs, the address of your SDK is not found.
SDK location isn't found.define location with Sdk.dir in the Local.properties file or with an Android_home environment varia ble.
There are two ways to solve
1: Configure Android_home specific own Baidu
2: Create a new file in the root directory "local.properties" content "SDK.DIR=D:\\ANDROID\\SDK\\SDK" Note that you are storing the root of the SDK, here is the address of my SDK, the parallel bars
If the following error occurs
9-path image Xxxxxxxxx.png Malformed.
Must has one-pixel frame, which is either transparent or white.
This is because your xxxxx.9.png format picture is not the real xxxx.9.png format, delete the middle one. 9 becomes xxxx.png
If you have to use. 9.png format then you should pay attention to how it is made. Because the Gradle check is very rigorous, your file header information is written by the file type is a, but your file suffix is B, of course, do not pass the
If the following error Gradle all is garbled and remember to add the front that sentence, you see the front has written, and the project if Utf-8 coding way yo
About the domain of the method I'll say it at the end of this article.
If the following error occurs
Could not find property ' Compile ' on Root project ' xxxxxx '
I said earlier that the old version of the Gradle parameter is Compile the new version is javacompile will all of your files Tasks.withtype (Compile) into Tasks.withtype (Javacompile)
If the following error occurs
Could not find Method Runproguard () for ....
It means that the Runproguard in your file is the old version of the method that says your file is changed to:
// Obfuscation method corresponds to the obfuscation file under the engineering root directory proguard-properties.txtproguardfile getdefaultproguardfile (' Proguard-properties.txt ')
If it is
Could not find Method Buildscript ()
If this method is not found, then
First check if all of the "{" and "}" in your file are one by one corresponding domain errors
The second is when you execute Gradle build
Your Build.gradle file has been opened in such a way that the default is open for text and cannot be changed. For example, the default is XML open because Gradle is open by null but the system is attached with an open method especially Win7 cannot return directly to the default
Gradle build may have occurred something similar to transcoding errors that resulted in a complete character not found at this point, open the cmd input "assoc. Gradle =" Note that spaces with 2 space equals sign are assigned null, which allows the. gralde file to be opened empty 。 Then there should be no problem, no more restart. I solved this problem anyway.
If this is the problem java.lang.StackOverflowError (honestly I do not know how to solve, I followed the internet to do the result is not, but suddenly good) I'm going to write it here again online
First delete the C:\Users\Administrator\.gradle. Gradle folder (the first Gradle downloaded 2.2.1 file)
Then delete the. GRADLE folder under%gradle_home%/bin (if not, forget it)
Then click%gradle_home%/bin under the Gradle.bat run and GRADLE build let it re-download 2.2.1 related files No, just reload it again GRADLE and then reboot.
About the concept of the domain, we must know.
a{}bbbbbbb=***c{}
So gradle to be careful is not to write the domain is wrong, be sure to write the domain attribution, or the error you will be very egg pain below is a simplified example
// buildscript Domain buildscript {//buildscript.repositories domain repositories { }// buildscript.dependencies Domain Dependencies { ' Android '//dependencies domain dependencies {} // Android Domain Android {}
In the case of an example method of execution and domain relationship, here, a domain is a method.
productflavors { no1{} no1{}// Note that the all method is now within the productflavors domain all {}}
The code above is exactly the same as the following code
productflavors { no1{} no1{}}// Note that the all method is now not in the productflavors domain, but is equivalent to the method block above Productflavors.all {}
This second article is about simple and some of the mistakes I've encountered.
Next article with Gradle signature confusion and dependency engineering
Gradle Tutorial [Original] (Eclipse/adt non-plugin non-Android studio/as) Pure hand Play the second: Gradle simple combat