If you're using Chewie (a popular video player plugin for Flutter) along with wakelock_plus (a plugin to keep the screen awake), you might have encountered the following error:
Could not determine the dependencies of task ':wakelock_plus:generateReleaseLintModel'.
This error is often accompanied by a message like:
this and base files have different roots: D:\programs\xxxx\xxx-app\build\wakelock_plus and C:\Users\xxx\AppData\Local\Pub\Cache\hosted\pub.dev\wakelock_plus-1.2.10\android.
This issue occurs because the Gradle build system is trying to compare or merge files from two different directories:
- Your project's build directory:
D:\programs\xxxx\xxx-app\build\wakelock_plus
- The cached package directory:
C:\Users\xxx\AppData\Local\Pub\Cache\hosted\pub.dev\wakelock_plus-1.2.10\android
This is a common problem when using Chewie and wakelock_plus together, especially when the project and cached files are on different drives. In this blog, I'll walk you through the steps to fix this issue.
Why Does This Happen?
The error occurs because the Gradle build system is unable to resolve file paths correctly when the project and cached files are on different drives. This is a common issue in Flutter projects that rely on plugins with native Android dependencies.
How to Fix the Issue
There are two main ways to fix this issue:
- Move the project to the same drive as the AppData directory (e.g., C:\). However, this might not be feasible for everyone, especially if you have multiple drives on your development machine.
- Update your Gradle and Kotlin configurationsto ensure compatibility with the latest versions of chewie and wakelock_plus.
Below, I'll focus on the second solution, which is more practical for most developers.
1. Update android/app/build.gradle
Open your android/app/build.gradle file and update the Gradle and Kotlin versions:
android {
namespace = "com.xxx.xxx.xxxx_app"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
defaultConfig {
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode 1
versionName "1.0"
}
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
}
2. Update android/gradle/wrapper/gradle-wrapper.properties
Open android/gradle/wrapper/gradle-wrapper.properties and update the Gradle distribution URL:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
3. Update android/settings.gradle
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.3.2" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}
4. Clean and Rebuild the Project
After making the above changes, clean and rebuild your project:
flutter clean
flutter pub get
flutter build apk
Conclusion
The "Could not determine dependencies" error is a common issue when using Chewie and wakelock_plus in Flutter projects. By updating your Gradle and Kotlin configurations, cleaning your project, and ensuring compatibility between dependencies, you can resolve this issue and get back to building your app.If you've tried all the steps above and are still facing issues, feel free to leave a comment below or reach out to the Flutter community for further assistance. Happy coding!
Plugins and Versions Used in This Guide
- wakelock_plus: 1.2.10
- chewie: 1.10.0
- Flutter Version: 3.27.3
- Android Studio: 2024.2
- Open JDK: 21
This blog is brought to you by AARK Technology Hub – your trusted partner for innovative tech solutions and expert guidance in Flutter development and beyond. Stay tuned for more insights and tutorials to elevate your development journey!