简体   繁体   English

如何将Android Gradle项目的依赖项设置为不同版本的库?

[英]How to set dependency of android gradle project to different versions of library?

I have small log library and it is published to jcenter. 我有一个小的日志库,它已发布到jcenter。 I need to have two versions of the library - debug and release. 我需要具有该库的两个版本-调试和发布。 To do this I found flag publishNonDefault true and pushed new version of library. 为此,我发现publishNonDefault true标志publishNonDefault true并推送了新版本的库。

Structure of files in repository before flag was set: 设置标志之前存储库中文件的结构: 1.2.4 Structure of files in repository after flag was set: 设置标志后存储库中文件的结构: 1.3.1

And now 现在
dependencies { compile 'me.shikhov:wlog:1.3.1' }

gives me error 给我错误

Error:A problem occurred configuring project ':Project'.
 Could not find wlog.jar (me.shikhov:wlog:1.3.1).
   Searched in the following locations:
      https://jcenter.bintray.com/me/shikhov/wlog/1.3.1/wlog-1.3.1.jar

I have found syntax for local dependency, for example: 我发现了本地依赖的语法,例如:

debugCompile project(path: ':myLocalLibrary', configuration: 'debug')

releaseCompile project(path: ':myLocalLibrary', configuration: 'debug')

How to set remote library dependency? 如何设置远程库依赖关系?

The extra string after the version in the artifact name is the classifier. 工件名称中版本之后的额外字符串是分类器。

The classifier allows to distinguish artifacts that were built from the same POM but differ in their content. 分类器允许区分从相同POM构建但内容不同的工件。 It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number. 它是一些可选的任意字符串,如果存在,则在版本号之后附加到工件名称。 As a motivation for this element, consider for example a project that offers an artifact targeting JRE 1.5 but at the same time also an artifact that still supports JRE 1.4. 作为对此元素的激励,例如考虑一个提供针对JRE 1.5的工件的项目,同时提供仍然支持JRE 1.4的工件。 The first artifact could be equipped with the classifier jdk15 and the second one with jdk14 such that clients can choose which one to use. 第一个工件可以配备分类器jdk15,第二个工件可以配备jdk14,以便客户可以选择使用哪个分类器。

Another common use case for classifiers is the need to attach secondary artifacts to the project's main artifact. 分类器的另一个常见用例是需要将辅助工件附加到项目的主要工件。 If you browse the Maven central repository, you will notice that the classifiers sources and javadoc are used to deploy the project source code and API docs along with the packaged class files. 如果浏览Maven中央存储库,则会注意到分类器源代码和javadoc用于与打包的类文件一起部署项目源代码和API文档。

From here . 这里

Gradle dependency declaration takes the form: Gradle依赖项声明采用以下形式:

[organisation]:[module]:[revision]:[classifier]@[ext]

so you should be consuming the dependency as: 所以您应该将依赖项作为以下方式使用:

compile 'me.shikhov:wlog:1.3.1:release@aar'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android库(.aar)使用与应用程序相同的gradle依赖关系-但版本不同,会导致NoClassDefFoundError - Android library (.aar) using the same gradle dependency as app - but different versions, causes a NoClassDefFoundError 如何强制android studio为项目和库使用不同的库版本 - How to force android studio to use different library versions for project and library 库和项目android之间的Gradle依赖冲突 - Gradle dependency conflict between library and project android 将Gradle项目依赖项编译为Android库Arr - Compile gradle project dependency into android library arr 如何在不同的Android Studio模块中使用相同gradle依赖项的不同版本? - How to use different versions of the same gradle dependency in different Android Studio modules? 如何将gradle库依赖项添加到codenameone项目中 - How to add gradle library dependency to a codenameone project 如何选择 Android 库的依赖版本? - How to choose dependency versions on Android Library? Android Studio(IntelliJ)和gradle,如何添加依赖关系的不同版本? - Android Studio (IntelliJ) and gradle, how do I add different versions of a dependency? 如何通过Gradle使Android Studio中的两个不同模块使用同一库的不同版本 - How to make two different modules in Android Studio use different versions of the same library via Gradle Android Gradle库依赖项 - Android Gradle library dependency
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM