I am trying to create an android library that uses the core of the Java library ( myLibrary-core ). I had problems with my dependencies that I found in my generated pom file, but I (I think) fixed it using the answer in this question: Gradle not including dependencies in published pom.xml
Now I am trying to decide why importing my library into a separate application gives this error. This is the error I get when I import the library into the project as a gradle dependency:
Error:Module version com.example:myLibrary:0.1.0 depends on libraries but is not a library itself
This is my build.gradle:
apply plugin: 'android-sdk-manager' apply plugin: 'com.android.library' buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.12.+' classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+' } } apply plugin: 'maven-publish' group = 'com.example' version = '0.1.0' android { compileSdkVersion 19 buildToolsVersion '19.1.0' defaultConfig { applicationId "com.example.android" minSdkVersion 11 targetSdkVersion 19 versionCode 1 versionName "0.1.0" } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/DEPENDENCIES' } } dependencies { // compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:20.0.0' compile 'com.example:myLibrary-core:0.1.2' compile 'com.android.support:support-v13:20.0.0' compile 'com.google.android.gms:play-services:+' } // build JAR file task androidReleaseJar(type: Jar, dependsOn: assembleRelease) { from "$buildDir/intermediates/classes/release/" } publishing { publications { maven(MavenPublication) { artifact androidReleaseJar { classifier "sources" } //The publication doesn't know about our dependencies, so we have to manually add them to the pom pom.withXml { def dependenciesNode = asNode().appendNode('dependencies') //Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each configurations.compile.allDependencies.each { def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', it.group) dependencyNode.appendNode('artifactId', it.name) dependencyNode.appendNode('version', it.version) } } } } } }
This creates a pom file:
<?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.1.0</version> <packaging>pom</packaging> <dependencies> <dependency> <groupId>com.android.support</groupId> <artifactId>appcompat-v7</artifactId> <version>20.0.0</version> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>myLibrary-core</artifactId> <version>0.1.2</version> </dependency> <dependency> <groupId>com.android.support</groupId> <artifactId>support-v13</artifactId> <version>20.0.0</version> </dependency> <dependency> <groupId>com.google.android.gms</groupId> <artifactId>play-services</artifactId> <version>+</version> </dependency> </dependencies> </project>
It is strange if I remove the game services, support-v13 and appcompat-v7, the error will disappear. I can not think of anything else to try, so I am happy to try any offer.
source share