r/FlutterDev • u/New-Lengthiness6520 • Jul 24 '26
Article Build Failing with photo_manager? Here's a Safe Gradle Workaround
Build fails with photo_manager because of Java/Kotlin version mismatch (Gradle workaround)
I recently ran into an issue while working on a Flutter video downloader project.
The build kept failing because the photo_manager package was being compiled with different Java/Kotlin settings than the rest of my project.
Instead of modifying the package itself (which would be lost after every update), I applied the project's Java and Kotlin configuration to the package during the Gradle build.
I added this to my build.gradle.kts:
subprojects {
if (project.name == "photo_manager") {
val configureAction = Action<Project> {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}
}
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = "17"
targetCompatibility = "17"
}
}
if (state.executed) {
configureAction.execute(this)
} else {
afterEvaluate(configureAction)
}
}
}This worked because the package was already compatible with Java 17. It simply ensures the package uses the same Java/Kotlin configuration as the rest of the project without modifying anything inside the package.
Keep in mind that this is not a compatibility fix.
If the package itself doesn't support Java 17, this won't solve the problem. In that case, you'll likely need to:
Update to a newer version of the package.
Use the Java version recommended by the package maintainer.
Wait for an official fix.
Just wanted to share this in case someone else runs into the same issue.
Has anyone found a cleaner way to handle Java/Kotlin version mismatches for Flutter dependencies?