Skip to content Skip to sidebar Skip to footer

Build Jitpack Library With Multi Flavor In Android

I am using Gradle 4.1 with Gradle-Android plugin 3.0.1 on Android Studio 3.2 I have 2 flavors 'production' and 'staging' and I am unable to build my project as a library with diffe

Solution 1:

After digging into this for 2 days, and emailing Jitpack support, the issue is because the lib has updated and publishNonDefault is deprecated. you just need to change your app build.gradle to:

apply plugin: 'com.github.dcendents.android-maven'
dependencies {...}

group = 'com.github.your-group'if (android.productFlavors.size() > 0) {
    android.libraryVariants.all { variant ->
        if (variant.name.toLowerCase().contains("debug")) {
            return
        }

        defbundleTask= tasks["bundle${variant.name.capitalize()}"]

        artifacts {
            archives(bundleTask.archivePath) {
                classifier variant.flavorName
                builtBy bundleTaskname= project.name
            }
        }
    }
}

Solution 2:

problem was to create multiple flavors using jitpack so what I do is, create a variable which stores the flavor name, after that loop through the available variant, pass the flavorBuild to artifact so when u push the code to GitHub and create artifact via jitpack then jitpack create the required implementation based on your build flavor and then u can use it. You need to just change build flavor

publishing {
    publications {
        def flavorBuild ='production'
        android.libraryVariants.all { variant ->

            "maven${variant.name.capitalize()}Aar"(MavenPublication) {
                from components.findByName("android${variant.name.capitalize()}")
                groupId = 'com.examplesdk'
                artifactId = 'examplesdk'
                version "1.0.0-${variant.name}"
                   artifact "$buildDir/outputs/aar/examplesdk-${flavorBuild}-release.aar"

                pom.withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')
                    configurations.api.allDependencies.each { dependency ->
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', dependency.group)
                        dependencyNode.appendNode('artifactId', dependency.name)
                        dependencyNode.appendNode('version', dependency.version)
                    }
                }
            }
        }
    }
    repositories{
        maven {
            url "$buildDir/repo"
        }
    }
}

Post a Comment for "Build Jitpack Library With Multi Flavor In Android"