Android Custom Gradle plugin for current project use

Source: Internet
Author: User

1, create a Java library project named BUILDSRC, delete the contents of Build.gradle, add the following content

apply plugin: ‘groovy‘dependencies {     compile gradleApi()//gradle sdk    compile localGroovy()//groovy sdk}

2. Delete all directory files under Src/main

    • Create the Groovy directory under the main directory, create the package name Com.home.plugin, and create the Myplugin.groovy content as follows
package com.home.pluginimport org.gradle.api.Pluginimport org.gradle.api.Projectpublic class MyPlugin implements Plugin<Project> {    void apply(Project project) {        System.out.println("========================");        System.out.println("这是个插件!");        System.out.println("========================");    }}
    • Create the Resources directory under the main directory and then new Meta-inf directory in the Resources directory
      Then create a new Gradle-plugins directory inside the Meta-inf. Finally create a new properties file in the Gradle-plugins directory
      Notice the name of this file, you can name it at will, but use it later
      For example, if you are named Com.home.plugin.properties, and you use a custom plugin in other build.gradle files, you need to write: Apply plugin: ' Com.home.plugin '
      Com.home.plugin.properties file content is: Implementation-class=com.home.plugin.myplugin

    • The project directory structure is as follows:

3, in the app Build.gradle Add reference to apply plugin: ' Com.home.plugin '

Demo Source: Https://github.com/xuguohongai/android/tree/master/GradlePlugin

Reference connection: http://kvh.io/cn/tags/EmbraceAndroidStudio/

Android Custom Gradle plugin for current project use

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.