1

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:0.0.1@aar" 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).

Community
  • 1
  • 1
NCode
  • 2,758
  • 1
  • 16
  • 25
  • `@aar` explicitly asks to only get the AAR and omit dependencies. From the information provided I can't tell what's the problem with the AAR. – Peter Niederwieser Dec 28 '14 at 22:25
  • I need the aar itself and all its transitive dependencies, but neither seem to be included. – NCode Dec 29 '14 at 15:30
  • To get transitive dependencies you need to omit `@aar`. If you don't even get the AAR's code, there is likely some other problem with the build or the published library, but I can't tell from here what it is. – Peter Niederwieser Dec 29 '14 at 16:46

1 Answers1

0

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.

SimenB
  • 6,410
  • 2
  • 23
  • 27