I’m mostly new into the Gradle world, besides episodic encounters that I’ve been having through my Android dev career.
Long story short, I’m trying to publish an Android library using the maven-publish
plugin, and it all works on the most part but I haven’t been able to package my JNI cpp libraries within the AAR file that is ultimately generated. Here’s some of my code inside build.gradle
:
apply plugin: 'maven-publish'
publishing {
publications {
aar(MavenPublication) {
groupId 'com.some.sdk'
artifactId 'test-sdk'
version '0.1-beta'
artifact("$buildDir/outputs/aar/${getAarName()}-release.aar")
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
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) {
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('groupId', '*')
exclusionNode.appendNode('artifactId', '*')
} else if (!dep.properties.excludeRules.empty) {
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
dep.properties.excludeRules.each { ExcludeRule rule ->
exclusionNode.appendNode('groupId', rule.group ?: '*')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
}
}
}
configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }
configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }
configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") }
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/some/repo")
credentials {
username = githubProperties['gpr.usr']
password = githubProperties['gpr.key']
}
}
}
}
I believe the problem is with the pom.withXml
function, but I’m not sure how to reference the libraries in there.
Here’s an example of my directory hierarchy:
root
- gradle
- app
- library
- build
- src
- androidTest
- main
- java (included in AAR)
- cpp (missing in AAR)
- another-lib (also missing in AAR)
- res