skip to Main Content

I am creating a flutter pluggin for a native sdk.

So I added the android dependency in the plugin/android/build.gradle file like this

android {
    if (project.android.hasProperty("namespace")) {
        namespace = "com.xxxxxxx.xxxxxx_sdk"
    }

    compileSdk = 34

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

    defaultConfig {
        minSdk = 21
    }

    dependencies {
        testImplementation("junit:junit:4.13.2")
        testImplementation("org.mockito:mockito-core:5.0.0")

        implementation 'com.xxxxxx:xxxxx-xxx:x.x.x' // The dependency
    }

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

but not able to build when I tried to access the added dependency,

2

Answers


  1. Chosen as BEST ANSWER

    I was able to solve this issue by opening the example/android folder in the Android Studio


  2. If you’re having trouble building and accessing the dependency in your Flutter plugin project, here are some steps that could help:

    1- Double-check Dependency Inclusion: Ensure the dependency’s group:artifact:version string is correct. Any typo here would cause build issues.

    2- Build and Sync Gradle Files: Sometimes, simply syncing and rebuilding can solve issues with using android studio

    • Run flutter clean in the project root.
    • Go to the Android directory in your plugin project and run
      ./gradlew clean followed by ./gradlew build.

    3- Dependency Scope: Ensure that your dependency is being imported in the correct scope in your plugin code. You may need to import the SDK in the plugin’s main class, typically located under android/src/main/kotlin.

    4- Ensure Compatibility: Make sure that the dependency is compatible with the SDK version and min SDK version in your build.gradle.

    5- Examine Build Output: Sometimes, the error messages in the build output provide clues. Check for specific error lines indicating missing classes, incompatible Java versions, or build process issues.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search