androidflutterandroid-gradle-pluginflutter-dependenciesflutter-plugin

Integrating a Native Android Package via a Flutter Plugin


I am migrating from using a native android package to making a flutter plugin around this package. During the build process, I encounter an error indicating that the required dependency cannot be found in the usual repositories (Google, Maven Central, etc.). The error message specifies that the build fails because it cannot resolve com.github.convertedin:android-pixel-sdk:1.4.4

error:

What went wrong: Execution failed for task ':app:checkStageReleaseDuplicateClasses'. Could not resolve all files for configuration ':app:stageReleaseRuntimeClasspath'. Could not find com.github.convertedin:android-pixel-sdk:1.4.4. Searched in the following locations: https://dl.google.com/dl/android/maven2/com/github/convertedin/android-pixel-sdk/1.4.4/android-pixel-sdk-1.4.4.pom https://repo.maven.apache.org/maven2/com/github/convertedin/android-pixel-sdk/1.4.4/android-pixel-sdk-1.4.4.pom https://storage.googleapis.com/download.flutter.io/com/github/convertedin/android-pixel-sdk/1.4.4/android-pixel-sdk-1.4.4.pom https://jcenter.bintray.com/com/github/convertedin/android-pixel-sdk/1.4.4/android-pixel-sdk-1.4.4.pom https://sdk.uxcam.com/android/com/github/convertedin/android-pixel-sdk/1.4.4/android-pixel-sdk-1.4.4.pom Required by: project :app > project :convertedin

The package com.github.convertedin:android-pixel-sdk:1.4.4 is available via JitPack, but the build system doesn't automatically check JitPack for dependencies.

build.gradle


group = "com.petsegypt.convertedin"
version = "1.0-SNAPSHOT"

buildscript {
    ext.kotlin_version = "1.8.22"
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath("com.android.tools.build:gradle:8.1.0")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"

android {
    if (project.android.hasProperty("namespace")) {
        namespace = "com.petsegypt.convertedin"
    }

    compileSdk = 34

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    sourceSets {
        main.java.srcDirs += "src/main/kotlin"
        test.java.srcDirs += "src/test/kotlin"
    }

    defaultConfig {
        minSdk = 21
    }

    dependencies {
        testImplementation("org.jetbrains.kotlin:kotlin-test")
        testImplementation("org.mockito:mockito-core:5.0.0")
    }

    testOptions {
        unitTests.all {
            useJUnitPlatform()

            testLogging {
               events "passed", "skipped", "failed", "standardOut", "standardError"
               outputs.upToDateWhen {false}
               showStandardStreams = true
            }
        }
    }
}

dependencies {
    implementation 'com.github.convertedin:android-pixel-sdk:1.4.4'
}

I have tried the following:


Solution

  • You can either add maven { url 'https://jitpack.io' } directly to the build.gradle file of the project or include it to the plugin using the following approach:

    [rootProject, this].each {
        it.allprojects {
            repositories {
                maven { url 'https://jitpack.io' }
            }
        }
    }
    

    This setup will look like:

    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
    [rootProject, this].each {
        it.allprojects {
            repositories {
                maven { url 'https://jitpack.io' }
            }
        }
    }
    
    apply plugin: "com.android.library"
    apply plugin: "kotlin-android"
    

    ref: 1 2