aar android library not included by gradle build

By : NCode
Source: Stackoverflow.com
Question!

I have a custom android library published to my local maven repository with the following build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1'
}

apply plugin: "com.android.library"
apply plugin: "maven-publish"

group = "com.example"
//name = "mylibrary"
version = "0.0.1"

repositories {
    mavenCentral()
    mavenLocal()
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        versionCode 1
        versionName project.version

        minSdkVersion 14
        targetSdkVersion 21
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile "org.slf4j:slf4j-api:1.7.5"
}

publishing {
    publications {
        android(MavenPublication) {
            artifact bundleRelease

            //FIXME manually add the dependencies as gradle doesn't find them in the default configuration
            pom.withXml {
                def dependenciesNode = asNode().appendNode('dependencies')

                configurations.default.allDependencies.each {
                    def dependencyNode = dependenciesNode.appendNode('dependency')
                    dependencyNode.appendNode('groupId', it.group)
                    dependencyNode.appendNode('artifactId', it.name)
                    dependencyNode.appendNode('version', it.version)
                }
            }
        }
    }
}

When running ./gradlew publishToMavenLocal the file ~/.m2/repository/com/example/mylibrary/0.0.1/mylibrary-0.0.1.aar is created with the right contents (including classes.jar) and the correct mylibrary-0.0.1.pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>mylibrary</artifactId>
    <version>0.0.1</version>
    <packaging>aar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
    </dependencies>
</project>

But when I declare a dependency on this library as compile "com.example:mylibrary:[email protected]" in another project, neither the library nor its dependencies are included, even though it seems to be found. ./gradlew dependencies yields

compile - Classpath for compiling the main sources.
\--- com.example:mylibrary:0.0.1

When running the build, the compilation fails as neither the classes from my library nor the classes from its dependencies are found.

I'm using Gradle 2.2.1 with android build tools 1.0.0 and the new maven-publish mechanism.

Note: As the classes from the library are missing, it must be more than a problem with transitive dependencies, so this solution didn't work. I want the library to be fetched from maven, so providing it locally like here is not an option (and it wouldn't help with the transitive dependencies).

By : NCode


Answers

Not enough reputation to comment...

I haven't used the new maven-plugin, but if you deploy to bintray using the android-maven-plugin, you just have to add the repo to your build.gradle (Or you can ask them to host it on jcenter, and you don't have to do anything). Then you'll be able to use transitive = true.

By : Simen


This video can help you solving your question :)
By: admin