[英]Android Library AAR depending on another library
Hi I have a Android Library Project which produces an AAR. 嗨我有一个Android库项目,它生成一个AAR。
All is good but when I use the AAR in another project I get this error: 一切都很好但是当我在另一个项目中使用AAR时,我收到此错误:
java.lang.NoClassDefFoundError: com.squareup.picasso.Picasso
The AAR makes use of picasso, is it possible to export the dependencies of the AAR as well when generating one? AAR使用毕加索,是否可以在生成AAR时导出AAR的依赖关系?
How can one go about setting up a local maven repo. 如何设置当地的maven回购。
WARNING: the following recipe works, but probably could use improvement, as I am far from a Maven expert. 警告:以下配方有效,但可能会使用改进,因为我远非 Maven专家。 I hammered out this approach last year for use with my CWAC libraries. 去年,我在我的CWAC库中使用了这种方法。
Step #1: Add classpath 'com.github.dcendents:android-maven-plugin:1.0'
to your buildscript
dependencies
block in your library project's build.gradle
file. 步骤1:将classpath 'com.github.dcendents:android-maven-plugin:1.0'
到库项目的build.gradle
文件中的buildscript
dependencies
块。 Also add version
and group
statements to provide that information about your AAR. 还要添加version
和group
语句以提供有关AAR的信息。
Step #2: Use gradle install
to compile the AAR and install it in the default local Maven repository. 步骤2:使用gradle install
编译AAR并将其安装在默认的本地Maven存储库中。
Step #3: Ordinarily, you would add mavenLocal()
to the dependencies
block of your application project to pick up the AAR via its artifact ID. 步骤3:通常,您可以将mavenLocal()
添加到应用程序项目的dependencies
块中,以通过其工件ID获取AAR。 That may be working again, though it was broken for a bit. 这可能会再次起作用,虽然它已经被打破了一点。 Instead, use maven { url "${System.env.HOME}/.m2/repository" }
as a short-term workaround. 相反,使用maven { url "${System.env.HOME}/.m2/repository" }
作为短期解决方法。
So, for example, your library project build.gradle
file might contain: 因此,例如,您的库项目build.gradle
文件可能包含:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
classpath 'com.github.dcendents:android-maven-plugin:1.0'
}
}
apply plugin: 'android-library'
apply plugin: 'android-maven'
version '0.4.0'
group 'some.likely.group.name.goes.here'
repositories {
mavenCentral()
}
dependencies {
compile 'com.squareup.picasso:picasso:2.2.0'
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
// as normal
}
You would use gradle install
to publish the JAR to your local Maven repo. 您可以使用gradle install
将JAR发布到本地Maven gradle install
。 Your application project would then have the following stuff in its build.gradle
: 然后,您的应用程序项目将在build.gradle
包含以下内容:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven { url "${System.env.HOME}/.m2/repository" } // mavenLocal()
}
dependencies {
compile 'some.likely.group.name.goes.here:name-of-library:0.4.0'
}
android {
// as normal
}
where you replace: 在哪里替换:
some.likely.group.name.goes.here
with something some.likely.group.name.goes.here
有一些东西
0.4.0
with a version number in XYZ format 0.4.0
版本号为XYZ格式
name-of-library
will be the directory name that contains the Android library project (eg, presentation
or foo
) name-of-library
将是包含Android库项目的目录名称(例如, presentation
或foo
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.