如何使用gradle将apk发布到Maven Central?

6
我使用Android Studio创建了一个Android项目,会生成一些APK文件。如何使用Gradle将这些APK发布到Maven Central?在APK的工件(artifacts)中应该写什么?请注意,不要删除HTML标签。
apply plugin: 'maven'
apply plugin: 'signing'

configurations {
    archives {
        extendsFrom configurations.default
    }
}

afterEvaluate { project ->
    uploadArchives {
        repositories {
            mavenDeployer {
                configurePOM(pom)
                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

                repository(url: sonatypeRepositoryUrl) {
                    authentication(userName: nexusUsername, password: nexusPassword)
                }
            }
        }
    }

......

    artifacts {
       archives file: files(dir: '$buildDir/apk/*.apk', include: '*.apk')
        // archives androidReleaseApklib
        archives androidReleaseJar
        archives androidSourcesJar
        archives androidJavadocsJar
    }
}
1个回答

1
我们使用gradle将APK文件发布到本地Nexus存储库。这是我想出的方法。此示例演示了使用“googlePlay”构建风格。
// make sure the release builds are made before we try to upload them.    
uploadArchives.dependsOn(getTasksByName("assembleRelease", true))

// create an archive class that known how to handle apk files.
// apk files are just renamed jars.
class Apk extends Jar {
    def String getExtension() {
        return 'apk'
    }
}

// create a task that uses our apk task class.
task googlePlayApk(type: Apk) {
    classifier = 'googlePlay'
    from file("${project.buildDir}/outputs/apk/myApp-googlePlay-release.apk")
}

// add the item to the artifacts
artifacts {
    archives googlePlay
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接