外部的Android库项目摇篮 [英] External Android library projects with Gradle
问题描述
我试图建立与摇篮和的 Android的摇篮插件。我想取决于外部(Maven的)存储库中找到库项目,例如: ActionBarSherlock。
I am trying to build an Android project with Gradle and the Android Gradle plugin. I would like to depend on library projects found in external (maven) repositories, e.g. ActionBarSherlock.
这根据<一个似乎是可能href="http://tools.android.com/tech-docs/new-build-system/using-the-new-build-system#TOC-Using-Library-Projects">official网站:
使用库进行的以下方式之一:
Using a library is done one of the following way:
多项目的设置。点击这里阅读:<一href="http://www.gradle.org/docs/current/userguide/multi_project_builds.html">http://www.gradle.org/docs/current/userguide/multi_project_builds.html
Multi-project setup. Read here: http://www.gradle.org/docs/current/userguide/multi_project_builds.html
依赖通过回购协议,如行家或常春藤。
我build.gradle的当前内容:
The current contents of my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.2'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:library:4.2.0'
}
android {
target = 'android-16'
sourceSets {
main {
manifest {
srcFile 'AndroidManifest.xml'
}
java {
srcDir 'src'
}
res {
srcDir 'res'
}
assets {
srcDir 'assets'
}
resources {
srcDir 'src'
}
}
}
}
我使用的摇篮1.2。当我尝试建立与摇篮组装
,我得到以下错误:
I am using Gradle 1.2. When I try to build with gradle assemble
, I get the following error:
Error: duplicate files during packaging of APK /[path to project]/build/apk/[project name]-debug-unaligned.apk
Path in archive: AndroidManifest.xml
Origin 1: /[path to project]/build/libs/[apk name]-debug.ap_
Origin 2: /[home directory]/.gradle/caches/artifacts-14/filestore/com.actionbarsherlock/actionbarsherlock/4.2.0/apklib/dd63451a922558005d8c10be1085b488ed731d19/actionbarsherlock-4.2.0.apklib
:packageDebug FAILED
好像它正试图从两个库项目,我的项目包括AndroidManifest.xml中。如果我删除清单
规范 sourceSets
,我仍然得到同样的错误。
It seems like it is trying to include the AndroidManifest.xml from both the library project and my project. If I remove the manifest
specification in sourceSets
, I still get the same error.
该网站提到使用应用插件:机器人库
图书馆项目;我猜测建设的实际库(与多项目设置)时,因为这样做不会生成APK这仅仅是。
The site mentions using apply plugin: 'android-library'
for library projects; I am guessing this is only when building the actual library (with a multi-project setup) since doing so does not produce an APK.
如何才能让外部的Android库项目依赖工作?
How can I get external Android library project dependencies to work?
推荐答案
虽然可以通过一个Maven或常春藤库中获得的依赖性,这些都不是封装在一个标准的JAR归档。有专门为此构建系统设计了一种新的格式。该类型是AAR
While it is possible to get dependencies through a Maven or Ivy repository, those are not packaged in a standard Jar archive. There is a new format designed specifically for this build system. The type is 'aar'
适用于Maven的中央当前的Android库,以便它们是不兼容的。
Current Android Libraries available on Maven Central were created using the Maven plugin which use a different archive format ('apklib') so they are not compatible.
如果你看一下com.actionbarsherlock:actionbacksherlock(这是该库的新位置),你会看到它的格式是apklib。 <一href="http://search.maven.org/#artifactdetails%7Ccom.actionbarsherlock%7Cactionbarsherlock%7C4.2.0%7Capklib">http://search.maven.org/#artifactdetails%7Ccom.actionbarsherlock%7Cactionbarsherlock%7C4.2.0%7Capklib
If you look at com.actionbarsherlock:actionbacksherlock (which is the new location of that library), you'll see its format is apklib. http://search.maven.org/#artifactdetails%7Ccom.actionbarsherlock%7Cactionbarsherlock%7C4.2.0%7Capklib
查看源$ C $ C,我们检查'AAR'包装和恢复处理所有其他的罐子,这显然是一个问题就在这里。我们应该检测apklib并提供更好的错误消息。
Looking at the source code, we check for 'aar' packaging and revert to processing all others as 'jar' which is obviously a problem here. We should detect apklib and provide a better error message.
这篇关于外部的Android库项目摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!