[英]How do I ship an Android Library (aar) with remote dependencies (gradle)?
I am trying to build an aar file with gradle that has remote dependencies. 我正在尝试使用具有远程依赖关系的gradle构建aar文件。 An example build script is below.
下面是一个示例构建脚本。 As you can see I have two dependencies.
如您所见,我有两个依赖项。 The problem I'm having is when I do a release, the aar file does not contain the remote dependencies, so when I include the aar file in other projects I get NoClassDefFound errors.
我遇到的问题是当我发布时,aar文件不包含远程依赖项,所以当我在其他项目中包含aar文件时,我得到NoClassDefFound错误。
I found that if I copy the jar from my local maven repo to a libs folder in my project, then the jar does get included in the release aar. 我发现如果我将jar从我当地的maven repo复制到我项目中的libs文件夹,那么jar确实会包含在发布版本中。 How do I include the remote dependencies in the aar file?
如何在aar文件中包含远程依赖项? I've also read elsewhere that it's bad practice to ship dependencies like this, so if there's a better way to do what I'm trying to do I'm all for it.
我还在其他地方读到,这样运送依赖关系是不好的做法,所以如果有更好的方法来做我想做的事情,我就是为了它。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
mavenLocal()
}
android {
... omitted for brevity
}
dependencies {
compile 'com.somepackage:someartifact:1.0'
compile 'com.anotherpackage:artifact:2.0'
}
try using the transitive
attribute: 尝试使用
transitive
属性:
compile ('group_id:artifact_id:version_name@aar'){
transitive = true
}
you can check this link: 你可以查看这个链接:
Transitive dependencies not resolved for aar library using gradle 使用gradle未解析aar库的传递依赖性
you have to create a POM file as follows: 你必须创建一个POM文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sprezzat</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>com.bugsense.trace</groupId>
<artifactId>bugsense</artifactId>
<version>3.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
and deploy it on maven. 并将其部署在maven上。
After that, you can define it in your android application build.gradle config like this: 之后,您可以在Android应用程序build.gradle配置中定义它,如下所示:
compile ('com.somepackage:LIBRARY_NAME:1.0.0@aar'){
transitive=true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.