简体   繁体   中英

Android Studio - Export Android library aar with pure gradle

This question is so basic, and I didn't find documentation for it.

I have an Android Library project, and I would like to export an aar file of it, and use it in another project.

I have the following gradle.build file, from so many other examples:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.4.2'
    }
}

apply plugin: 'android-library'

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 7
    }
}

I would like to use pure Gradle to run this, which means that I need to run the tasks, but first things first, I get the following error:

> Plugin with id 'android-library' not found.

Why does the plugin not found, and which tasks should I run?

Thanks, Adam.

Here's what has worked for me. It's manual, but it is a pure gradle way to do it. This assumes that you have 'apply plugin: "android-library" in your module's build.gradle file which I see you have.

  1. on the command line go to the root directory of the project
  2. ensure that your JAVA_HOME environment variable points to the version of the java sdk you are going to use. On a Mac via the bash shell that would look something like this:

    export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home'

(click here to find out how to find your Java Home )

  1. To clean type ./gradlew clean
  2. To build the library type ./gradlew aR (This may take a while)

You should now find the .aar file in mymodulename/build/outputs/aar

Thanks to [geekgarage] for clarification. 2

You should try updating/upgrading your build tools and gradle through AndroidStudio. Once you do this, or if you have already done it, you should be able to modify your build file to reflect the updates:

classpath 'com.android.tools.build:gradle:0.5.+'
...
buildToolsVersion "18.0.1"

NOTE: I am still unable to generate aar files even with this setup, although compiling is fine. At least this might get you past this hurdle.

Try adding this at the top of your grandle file

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2+' 
    }
}

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