简体   繁体   中英

How can I create aar file using build.gradle

I created a project as a library and I wrote a class in that. Now I want to have an aar file from that using build.gradle .

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 17
    }
}

What changes are needed in the above code?

Just make sure that your <modulename>/build.gradle contains the right plugin:

apply plugin: 'com.android.library'

Then you can create with

gradlew aR

your release aar file. Which will land in <modulename>\\build\\outputs\\aar directory with the name modulename-release.aar .


The more tricky part is to include that aar file to your project (if you don't use maven or jcenter).

You need to put this lines to your <projectroot>/build.gradle :

allprojects {
    repositories {
        mavenCentral()
        flatDir { dirs('aars') }
    }
}

When you put your aar files in <modulename>/aars , then you can include your aar file in your desired module like this:

compile(name:'<your-aar-file-name>', ext:'aar')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM