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
I was able to solve this issue by opening the
example/android
folder in the Android StudioIf 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
./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.