In Flutter Plugin template, how can I add Android dependency?

47 views Asked by At

I created Flutter project with flutter create --platform=android --template=plugin flutter_tapjoy_sdk.

I want to add TapjoySDK dependency to my plugin so users of my plugin can use it without adding manually. So I add it to android/build.gradle.

group 'com.tapjoy.tapjoy_sdk'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://sdk.tapjoy.com/' }
    }
}

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

android {
    if (project.android.hasProperty("namespace")) {
        namespace 'com.tapjoy.tapjoy_sdk'
    }

    compileSdkVersion 33

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        minSdkVersion 19
    }

    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.tapjoy:tapjoy-android-sdk:13.2.1'
}

What I added are allprojects.repositories.maven and dependencies at the end of the file.

But if I run the build command in example directory of the project, I got error that it could not find the Tapjoy dependency. I think it does not check Tapjoy maven repository.

➜  example git:(main) ✗ flutter build apk


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkReleaseAarMetadata'.
> Could not resolve all files for configuration ':app:releaseRuntimeClasspath'.
   > Could not find com.tapjoy:tapjoy-android-sdk:13.2.1.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/tapjoy/tapjoy-android-sdk/13.2.1/tapjoy-android-sdk-13.2.1.pom
       - https://repo.maven.apache.org/maven2/com/tapjoy/tapjoy-android-sdk/13.2.1/tapjoy-android-sdk-13.2.1.pom
       - https://storage.googleapis.com/download.flutter.io/com/tapjoy/tapjoy-android-sdk/13.2.1/tapjoy-android-sdk-13.2.1.pom
     Required by:
         project :app > project :tapjoy_sdk

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
Running Gradle task 'assembleRelease'...                         2,883ms
Gradle task assembleRelease failed with exit code 1

I checked that the dependency is available from below link.

https://sdk.tapjoy.com/com/tapjoy/tapjoy-android-sdk/13.2.1/tapjoy-android-sdk-13.2.1.pom

ps. I've found that setting up a dependency directly on the example project works fine - example/android/app/build.gradle.

0

There are 0 answers