我(终于)能够使用本指南将我的Android库发布到AWS S3 maven存储库。它作为 AAR 而不是 JAR 文件发布,这意味着即使生成的 POM 文件列出了其所有内部依赖项,在将库添加到另一个项目时也会忽略它们。似乎是一个非常普遍的问题。我从中了解到,我只需要在 maven 清单中列出依赖项,但这是如何完成的呢?
我真的是一个新手,所以越简单越好...谢谢!
注意:我也发现了这个问题,所以我在依赖性实现行的末尾添加了“{transitive=true}”,它起了作用。
所以现在要成功包含我的库,依赖项必须编码为:
implementation (group: 'com.mygroup', name: 'my_library', version: '1.3', ext: 'aar', classifier: 'release') { transitive=true changing=true }
(我添加了“changing=true”以强制它每次重新下载库。)
如果我不包含“transitive=true”,我会得到以下错误:
02-04 20:11:48.462 10225-10225/com.mydomain.app.testapplication4 E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
02-04 20:14:07.080 10225-10225/com.mydomain.app.testapplication4 E/dalvikvm: Could not find class 'android.app.NotificationChannel', referenced from method com.mydomain.library.mydomain$1.onReceive
02-04 20:14:07.290 10225-10225/com.mydomain.app.testapplication4 E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.firebase.iid.FirebaseInstanceId
at com.mydomain.library.MyActivity.onCreate(MyActivity.java:88)
at android.app.Activity.performCreate(Activity.java:4701)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1924)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4477)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
以下是我用于发布库的最新脚本(请注意,它仅发布发布版本,但依赖项行仍需要“release”分类器):
apply plugin: 'maven-publish'
group = 'com.mydomain'
version = '1.3'
// Add sources as an artifact
task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier "source"
}
// Loop over all variants
android.libraryVariants.all { variant ->
if (variant.buildType.name == "release") { // only release build
variant.outputs.all { output ->
// This creates a publication for each variant
publishing.publications.create(variant.name, MavenPublication) {
// The sources artifact from earlier
artifact sourceJar
// Variant dependent artifact, e.g. release, debug
artifact source: output.outputFile, classifier: output.name
// Go through all the dependencies for each variant and add them to the POM
// file as dependencies
pom.withXml {
final dependenciesNode = asNode().appendNode('dependencies')
ext.addDependency = { Dependency dep, String scope ->
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
return // ignore invalid dependencies
final dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)
dependencyNode.appendNode('scope', scope)
if (!dep.transitive) {
// If this dependency is transitive, we should force exclude all its dependencies them from the POM
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('groupId', '*')
exclusionNode.appendNode('artifactId', '*')
} else if (!dep.properties.excludeRules.empty) {
// Otherwise add specified exclude rules
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
dep.properties.excludeRules.each { ExcludeRule rule ->
exclusionNode.appendNode('groupId', rule.group ?: '*')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
}
}
}
// List all "compile" dependencies (for old Gradle)
configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }
// List all "api" dependencies (for new Gradle) as "compile" dependencies
configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }
// List all "implementation" dependencies (for new Gradle) as "runtime" dependencies
configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") }
}
}
}
}
}
// Ensure that the publish task depends on assembly
tasks.all { task ->
if (task instanceof AbstractPublishToMaven) {
task.dependsOn assemble
}
}
// Configure the destination repository with
// S3 URL and access credentials
publishing {
// Properties properties = new Properties()
// properties.load(file('maven.properties').newDataInputStream())
repositories {
maven {
url "s3://androidsdk.mydomain.com.s3.amazonaws.com"
credentials(AwsCredentials) {
accessKey "myaccesskey"
secretKey "mysecretkey"
}
}
}
}
以下是库的gradle.build文件中的依赖项:
dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
api 'com.android.support:appcompat-v7:27.1.1'
api 'com.android.support.constraint:constraint-layout:1.1.3'
api 'com.android.support:design:27.1.1'
api 'io.reactivex.rxjava2:rxandroid:2.1.0'
api 'io.reactivex.rxjava2:rxjava:2.2.4'
api 'com.github.instacart.truetime-android:library-extension-rx:3.3'
api 'com.google.dagger:dagger-android:2.15'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.15'
annotationProcessor 'com.google.dagger:dagger-compiler:2.15'
api 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
api 'com.google.firebase:firebase-core:16.0.7'
api 'com.google.firebase:firebase-messaging:17.3.4'
}
我认为下面生成的POM文件可能与库的依赖项不匹配,但它们确实匹配。POM文件中的“scope”标记应该不需要“transitive=true”,对吗?
<?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.mydomain</groupId>
<artifactId>my_library</artifactId>
<version>1.3</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<version>27.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.android.support.constraint</groupId>
<artifactId>constraint-layout</artifactId>
<version>1.1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>design</artifactId>
<version>27.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxandroid</artifactId>
<version>2.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.instacart.truetime-android</groupId>
<artifactId>library-extension-rx</artifactId>
<version>3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-android</artifactId>
<version>2.15</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.nostra13.universalimageloader</groupId>
<artifactId>universal-image-loader</artifactId>
<version>1.9.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-core</artifactId>
<version>16.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-messaging</artifactId>
<version>17.3.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
我遇到过类似的问题,但我的问题是在发布块中我使用了“库”函数而不是“maven”函数
在我的库build.gradle中,我有这样的块:
afterEvaluation{
publishing {
publications {
maven(MavenPublication) { // here I had library(MvenPublication) which caused the packaing to be pom instead of aar
artifacts = ["build/outputs/aar/library-release.aar"]
}
}
}
您应该能够通过更改POM XML生成来解决这个问题,这样< code >
<?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.humanvideoboard</groupId>
<artifactId>hvb_library</artifactId>
<version>1.0</version>
<packaging>aar</packaging>
然而,现在我正在重新检查这一点,为什么它与<code>可传递的
我有一些OSGi包(简单的OSGi,没有eclipse依赖项)和一个maven构建,使用pax runner在Knopflerfish服务器中启动它们。 maven构建和启动包工作得非常好,但是只能通过Pax runner(< code > mvn Pax:provision )。 为了调试捆绑包,最好直接从eclipse中启动它们,否则我的断点不会触发(似乎很明显,因为pax:provision
我尝试了以下链接:https://docs.microsoft.com/en-us/azure/devops/artifacts/get-start-maven?view=azure-devops
问题内容: 我正在运行一个依赖groovy 1.7-beta-1的项目。gmaven插件使用groovy 1.6版作为依赖项。在pom中,我在依赖性管理部分中将grooyv-all版本指定为: 但是,当我在调试模式下运行maven时,我看到groovy 1.6被用于对gmaven插件的依赖。我以为我的依赖项管理部分会重写此设置,因此它们都使用1.7-beta-1,但是由于常规版本不同,我遇到了错误
问题内容: 我有一个依赖关系如下: 当我部署一切正常时,这将拉下另一个引发ClassDefNotFound的依赖项。 我添加了两个依赖项,如下所示: 并且仍然面临着同样的问题,即:MVN带来下来不 我该如何解决? 编辑: 添加; 问题答案: 您可能有一个传递依赖项,另一个依赖项取决于您不需要的版本。 要获得所有直接和传递依赖关系的概述,请尝试: mvn依赖项:树 如果您发现同一依赖项的不同版本之间
Remove wrapper, open mouth, insert muffin, eat. — Instructions on 7-11 muffin packaging 为确保事物以正确的顺序发生,你可以在 Puppet 中指定一个资源依赖另一个资源, 例如:你必须先安装软件包 X 然后再启动它提供的服务,因此应该标记这项服务依赖于软件包 X。 Puppet 会按要求的顺序排出它遇到的所有依
使用 我修改了以包含导入语句。因此,maven无法找到我试图使用并将其与项目链接的jar。 我向pom.xml文件添加了一个依赖项,如下所示: