简体   繁体   English

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

[英]How to publish apks to the Maven Central with gradle?

I create an android project with android studio. 我用android studio创建了一个android项目。

It will generate some apks. 它会产生一些apks。

How can i publish apks to the Maven Central with gradle? 如何用gradle将apks发布到Maven Central?

What can i write in the artifacts for the apk? 我可以在apk的文件中写什么?

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
    }
}

We publish our APK files to our local Nexus repository using gradle. 我们使用gradle将APK文件发布到我们的本地Nexus存储库。 This is what I've come up with. 这就是我想出来的。 This example demonstrated using a "googlePlay" build flavor. 此示例演示了使用“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
}

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

相关问题 如何将 Android 库发布到 Maven Central Gradle 7.2.0 - How to publish Android Library to Maven Central Gradle 7.2.0 使用Gradle将aar文件发布到Maven Central无法正常工作 - Publish an aar file to Maven Central with Gradle not working 如何 GPG 签名并将 aar 直接发布到 Maven Central? - How to GPG sign and publish an aar directly to Maven Central? 我该如何添加到Maven Central上的gradle库? - How do I go about adding a library to gradle that is on Maven Central? 将GitHub Android库发布到Maven Central - Publish GitHub Android Library to Maven Central 如何使用Gradle一次构建多个APK? - How to build multiple APKs at once using Gradle? 如何在我的Maven本地存储库中发布带有gradle的现有aar? - How to publish in my maven local repository an existing aar with gradle? 如何使用 Android Gradle 插件 3.0.0 将所有风味变体发布到 maven? - How to publish all flavor variants to maven with Android Gradle plugin 3.0.0? 如何使用maven-publish gradle插件附加AAR文件的源? - How to attach sources of an AAR file with maven-publish gradle plugin? 如何在android gradle构建文件中为从maven central中提取的库指定proguard的injar - how to specify injars for proguard within android gradle build files for libraries that are pulled from maven central
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM