【发布时间】:2014-10-24 11:37:27
【问题描述】:
我正在尝试构建一个使用 java 库“核心”(myLibrary-core) 的 android 库。我在生成的 pom 文件中显示我的依赖项时遇到了问题,但我(认为我)使用以下问题中的答案修复了它:Gradle not including dependencies in published pom.xml
我现在正在尝试解决为什么将我的库导入单独的应用程序会出现此错误。这是我将库作为 gradle 依赖项导入项目时遇到的错误:
Error:Module version com.example:myLibrary:0.1.0 depends on libraries but is not a library itself
这是我的 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)
}
}
}
}
}
}
这会生成 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.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>
奇怪的是,如果我删除 play-services、support-v13 和 appcompat-v7,错误就会消失。我想不出其他可以尝试的方法,所以我很乐意尝试提出的任何建议。
【问题讨论】:
-
我知道如何用 eclipse adt 做到这一点。 alt-enter 在每个项目上。库点击islibary,其他项目你点击库项目。
-
@danny117 这似乎与我的情况无关。 pom 文件是否正确生成,您可以通过 gradle 将库项目导入应用程序中吗?
-
其实我只知道eclipse的一种方法。当 android studio 退出测试版时,我会看看它。在此处查看使用 Android Studio 为库项目设置 gradle。 developer.android.com/sdk/installing/studio-build.html
-
我认为你没有理解我的问题..
-
我知道我在 gradle maven 构建方面实际上很弱。我只是想帮忙。图书馆导入祝你好运。嗯,IDE 是什么,或者您在自动夜间构建服务器上构建。
标签: android maven gradle android-studio