【发布时间】:2015-02-24 22:26:06
【问题描述】:
我有一个自定义 android 库使用以下 build.gradle 发布到我的本地 maven 存储库:
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)
}
}
}
}
}
在运行 ./gradlew publishToMavenLocal 时,将使用正确的内容(包括 classes.jar)和正确的 mylibrary-0.0.1.pom 创建文件 ~/.m2/repository/com/example/mylibrary/0.0.1/mylibrary-0.0.1.aar:
<?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>
但是,当我在另一个项目中将此库的依赖项声明为 compile "com.example:mylibrary:0.0.1@aar" 时,该库及其依赖项均不包括在内,即使它似乎已找到。 ./gradlew dependencies 收益
compile - Classpath for compiling the main sources.
\--- com.example:mylibrary:0.0.1
运行构建时,编译失败,因为我的库中的类及其依赖项中的类都找不到。
我正在使用 Gradle 2.2.1 和 android 构建工具 1.0.0 和新的 maven-publish 机制。
注意:由于缺少库中的类,它肯定不仅仅是传递依赖的问题,因此this 解决方案不起作用。 我希望从 maven 中获取库,因此不能像 here 那样在本地提供它(而且它对传递依赖没有帮助)。
【问题讨论】:
-
@aar明确要求仅获取 AAR 并忽略依赖项。根据提供的信息,我无法判断 AAR 有什么问题。 -
我需要 aar 本身及其所有传递依赖项,但似乎都不包括在内。
-
要获得传递依赖,您需要省略
@aar。如果您甚至没有获得 AAR 的代码,那么构建或发布的库可能存在其他问题,但我无法从这里判断它是什么。
标签: android maven gradle android-library aar