Androidstudio Use tutorial (fourth bullet) Gradle
I feel it necessary to explain here Gradle .
Gradleis a Apache Ant Apache Maven Project automation Building tool based on and concept. It uses a Groovy specific domain language based on which to declare project settings, rather than traditional XML .
For more information, please refer directly to Gradle or Google search.
The following are the main reasons why Android Studio chooses Gradle:
-Use domain-specific languages (domain specific Language) to describe and manipulate building logic. (hereinafter referred to as DSL)
-Based on groovy. DSLs can mix various declarative elements and manipulate these DSL elements in code to achieve logical customization.
-Support existing MAVEN or Ivy warehouse infrastructure
-Very flexible, allowing the use of best practices, does not force you to follow its principles.
-Other plugins can expose their own DSL and API to let Gradle build files for use.
-Allows IDE integration, is a good API tool
Overview
AndroidStudio buildThe system is a tool you can use build, test, run, package your apps . The build system Android Studio is independent from one another,
So you can be in Android Studio or
command lineTo execute. Once you have finished writing your own application, you can use the build system to do the following things:
-Customize, configure, and extend the build process.
-Create multiple using the same project based on different characteristics APK .
-Re-use code and resources.
Android StudioThe flexible build system allows you to do all the work without modifying the project and the core files.
Overview of the Build System
Android StudioBuild system contains a Gradle Android plug-in that Gradle is an advanced build tool that manages dependencies and allows custom build logic. Many software is used Gradle to build.
GradleAndroidplug-ins are not dependent Android Studio , although Android Studio they are all integrated Gralde , which means:
-You can use the command line to build the Android application or on some machines that are not installed Android Studio .
-You can use the configuration and logic at the command line to build the Android Studio project in Android .
The output is consistent whether you are using a command line or a remote machine or a Android Studio build.
Build Configuration
The build configuration for the project is in Gralde build files , with the options and syntax that are compliant with Gradle , Android plugin does not depend on Android
uses the build file to configure several aspects:
- Build variants build system can generate multiple APK for the same project through different configurations , this is useful when you want to build multiple different versions, because you don't have to build many different projects for them.
- The Dependencies builds the dependencies of the System Management project and supports the dependencies of the local already remote repositories. So you don't have to search, download, and then copy the corresponding package to your project directory.
- The Manifest entries build system enables you to specify the values of some elements in a manifest file by building a configuration. This is useful when you want to generate some package names, a minimum version of the SDK , or a different APK version of the target SDK .
- The Signing build system can set the specified signature in the build configuration, and the building's composition will be signed for APK .
- The Proguard build system allows different obfuscation rules to be set based on different build configurations, and will run Proguard to confuse the class file during the build process.
- Testing the build system will generate a test based on the test code in your project APK , so that you do not need to create a separate test project, which will run the appropriate test function during the build process.
Gradle build files using Groovy syntax, groovy is a customizable build logic and can be passed Gradle The language that the Android plugin communicates with some specific elements of Android.
Build by convention
Android StudioThe build system makes some good default specification declarations for the project structure and some other build options, and Gradle the build file is very simple if your project meets these criteria. If your project does not meet the
Some of these requirements, the flexible build system also allows you to configure almost all of the build options. For example, your project's source code is not placed in the default folder, you can use build the file to configure its location.
Projects and modules
the project in Android Studio represents a complete Android app, each project You can have one or more Module in. Module is a component in your app that can be separate build, test , or debug . The
module contains the source code and resource files in your app, and the Project in Android Studio contains the following three types of Module :
-A Java library modules that contains reusable code. Building the system to Java Library module generates a JAR package.
-There is a reusable Android code and resources for Android library modules . The library Modules build system generates a AAR (Android ARchive) package.
-There is an app code or may also be dependent on other library modules 's android application modules , although a lot of Android The app contains only one application module .
The build system for application modules
generates a APK package.
Android Studio projectsThe project most outer city contain a list modules of all Gradle build file , each of which module also contains its own Gradle build file .
Dependencies
Android StudioThe build system manages dependent projects and supports dependencies module , local binary file dependencies, and remote binary file dependencies.
Module Dependencies
A project module can contain a series of other dependencies that are not seen in the build modules , and when you build this module , the system goes back and assembles the included modules .
Local Dependencies
If the local file system has a module dependent binary package such as a JAR package, you can module declare these dependencies in the build file in that.
Remote Dependencies
When your dependencies are in a remote repository, you don't need to download them and copy them to your project. Android Studiosupport remote Maven dependencies. Mavenis a popular project management tool,
It can use warehouses to help organize project dependencies.
Many of the best software libraries and tools are in public Maven warehouses, where they can only be specified by the definitions of the different elements in the remote repository Moven .
The location format used by the build system Maven is group:name:version . For example Google Guava 16.0.1 The coordinates of the class library Maven are
com.google.guava:guava:16.0.1.
Maven Central RepositoryIt is now widely used to distribute many class libraries and tools.
The following are the configuration of the above three kinds of dependencies respectively;
dependencies { compile project(":name") compile fileTree(dir‘libs‘, include: [‘*.jar‘]) ‘com.google.guava:guava:16.0.1‘}
Build Tasks
Android StudioThe build system defines some of the column's build tasks, and high-level tasks invoke some of the tasks that output the necessary outputs. The build system provides the project tasks building app and module tasks
To build independently modules .
You can Andorid Studio see the list of currently available tasks through or on the command line, and perform the tasks inside.
The Gradle Wrapper
Android StudioThe project contains Gradle wrapper , including:
-A JAR file
-A Properties File
-A shell script for Windows platforms
-A shell script for Mac and Linux platforms
Disclaimer: These files need to be submitted to the Code control system.
Using Gradle wrapper (instead of installing locally Gradle ) ensures that the version configured in the configuration file is run frequently Gralde . Make sure your project is up-to-date with the latest version defined in the configuration file Gradle .
Android StudioRead the configuration file from the directory in your project Gradle wrapper and run it in that directory wrapper , so you can handle multiple projects that require different Gradle versions.
statement: Android Studio Do not use shell scripts, so any changes to them IDE will not take effect at the time of construction, you should Gradle build files set custom logic in.
You can Android Studio use the command line to run shell scripts to build your project, either in development or in some of the ones that are not installed.
Direct:
- Email: [Email protected]
- Good luck!
Androidstudio Use tutorial (fourth bullet)