Android (Java) Learning Note 127:android Studio Build.gradle, Settings.gradle in the new project

Source: Internet
Author: User

With the rapid development of information technology, IT projects become more and more complex, usually by a number of subsystems work together to complete. For this multi-system, multi-project scenario, many build tools have provided good support, like Maven, Ant. Gradle, in addition to using ant or Maven's inherited approach to define sub-projects, also provides a more convenient way to centralize configuration, greatly reducing the complexity of the build. In addition, Gradle provides a clear project tree model to map the organizational structure of multiple projects. below, let's look at how to build multiple projects using Gradle .

1. Definition and structure of multiple projects

Mulit project settings are a form of gradle conventions that need to be used if you need to compile a project before compiling another project, such as (from an official document):

myproject/| Settings.gradle + app/| Build.gradle + libraries/ + lib1/| Build.gradle + lib2/| Build.gradle

You need to create a settings.gradle file under your workplace directory, and then write it on the inside:

Include ': App ', ': Libraries:lib1 ', ': Libraries:lib2 '

That way, Gradle Mutil project is set up.

For app Project if you need to apply LIB1 in the libraries directory, you only need to write this in the Dependencies in App project build.gradle :

1
Compile project (': Libraries:lib1 ')

Can be completed, after writing to use gradle AndroidDependencies to check the dependency status.

Places to be aware of
123456789
Buildscript {    repositories {    mavencentral ()}        dependencies {        classpath ' com.android.tools.build:gradle:0.4 '    }}

For buildscript{} the Android Gradle is used to preset the plugin environment, generally does not recommend the dependency written inside, the recommended dependency notation is:

1234567891011121314151617181920212223
{    repositories {    mavencentral ()}        {        ' com.android.tools.build:gradle:0.4 '     Com.google.android:support-v4:r13 '}  
Using the MAVEN Management library

Gradle for package management, support Filesystem,maven,ivy, here I'm talking about how to use Maven to manage Android dependency packs

Publish your local maven library with Gradle

This is the basic Java knowledge for how to package a jar package and publish it to maven.

What we want to learn now is, for example, publishing an Android library package.

In the past, the Android library did not have a good package management method, in short, before the advent of Gradle, the official does not have a way to manage the Android library dependency package, generally we are directly download other people's Android library The project source code is integrated, and the Android-maven-plugin for third parties is in apklib format.

Now, officially, the official launch of an Android library packaging format, the extension of the *.aar . As mentioned earlier, the current Android Gradle plugin does not support the local direct use *.aar of the file, however, support package management Library Reference Way, below, I say for everyone, how to release the Android library to use.

  1. Pack Android Library

    The Android library is packaged directly under the Library project, gradle build and then you will see two files in the Build/libs directory, one for the debug pack, *.aar one for release, and for personal use, Here we are using the release version of the. aar file.

  2. Publish Script

    Create a Build.gradle file under the build/libs of the Android Library project directory

    123456789101112131415161718
    Apply plugin: ' maven 'group = ' Com.youxiachai 'artifacts {//current AAR filename Archives file ('Gradlelib.aar ') }"File://F:/githubrepo/releases") pom.version = ' r1 ' Pom.artifactid = ' gradletest '   }}} 
    gradle uploadArchivesTo complete the release of the package.

By completing these two steps, you can reference the dependency of the Android library directly with Maven's dependency on the jar.

 

Android (Java) Learning Note 127:android Studio Build.gradle, Settings.gradle

in new project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.