Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

android - Uploading JNI project into Maven repository

I'm trying to upload my Android library to GitHub Packages thru the Maven repository using this guide, and I'm having trouble including the .so files that my project depends on.

In general, the library is uploaded fine, and I'm even able to downloaded on the other side. The problem is that the AAR file only contains the Java/Kotlin files from my library, but not the rest of the native C code from the JNI layer.

Here's how my library's build.gradle looks like:

apply plugin: 'maven-publish'

publishing {
    publications {
        aar(MavenPublication) {
            groupId 'group.id'
            artifactId 'artifact-id'
            version '1.0'
            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/url")
            credentials {
                username = githubProperties['gpr.usr']
                password = githubProperties['gpr.key']
            }
        }
    }
}

And here's how my directory tree looks more or less to for reference:

root
   - gradle
   - app
   - library
      - build
      - src
         - androidTest
         - main
            - java (included in AAR)
            - cpp (missing in AAR)
            - res

I'm not sure what is it that I'm missing. I've read a lot of question/answers saying that I must point the maven-publish plugin to my .so files, but I haven't figured out how to do this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...