flutter-dependenciesflutter-objectboxflutter-isar

Flutter builds fail consistently when attempting to work with Flutter databases


I'm learning Flutter and focusing on Databases but have been unable to use them. An error occurs after adding dependencies for Isar and ObjectBox databases, however Hive appears to work. After adding database dependencies to my pubspec.yaml I can no longer run my projects without getting an error like:

Execution failed for task ':objectbox_flutter_libs:parseDebugLocalResources'.

Could not resolve all files for configuration ':objectbox_flutter_libs:androidApis'. Failed to transform android.jar to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}. > Execution failed for PlatformAttrTransform: C:\Users\REDACTED\AppData\Local\Android\sdk\platforms\android-31\android.jar. > C:\Users\REDEACTED\AppData\Local\Android\sdk\platforms\android-31\android.jar

I am adding the dependencies following QuickStart guides and am placing them under the correct heading in pubspec and performing Flutter Pub Get. From that point I get the above error, even if I continue to create the database entities/classes with build runner and set the database up (I thought this might have been a cause initially).

Dependencies:

flutter:
    sdk: flutter

  cupertino_icons: ^1.0.8
  objectbox: ^4.0.2
  objectbox_flutter_libs: any

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter_lints: ^4.0.0
  build_runner: ^2.4.13
  objectbox_generator: any

I have searched for solutions and found many regarding android SDKs and Java.

I have android studio installed and have attempted changing and reloading android SDKs and Java versions through android studio, as Gradle is set to build through wrapper.

For Java, I have set my JAVA_HOME environmental variable as well as Java version within android studio to the same locations when attempting the use of different Java versions.

The JDK versions I have installed and tried include 17.0.12, 19.0.2 and 21.0.3 with no impact on the error.

I have checked dependency versions of Isar and ObjectBox to ensure they are up to date (I'm not using both in one project). My Dart, Flutter, Git, VS Code and Android Studio installations are up to date.

I have android 12, 14, 15 SDKs installed. Command line tools and SDK platform tools are installed. Flutter Version 3.24.3, Dart 3.5.3, Devtools 2.37.3. Android Studio Ladybug. Gradle is Android studio gradle 8.7.0.

Flutter doctor gives me an error for chrome only (I do not have chrome installed).

I have effectively installed and used Android studio, VS Code, Flutter/Dart following installation guides and am using guides for the databases (Isar or ObjectBox) when I attempt to use them.

I have not been able to find an answer to this particular issue and really appreciate your input.

Is there anything else that is obvious that I am overlooking?


Solution

  • The error indicates an issue with the Android SDK:

    Execution failed for PlatformAttrTransform: C:\Users\REDACTED\AppData\Local\Android\sdk\platforms\android-31\android.jar.
    

    You said you have tried "reloading android SDKs". Can you double-check you did it like suggested in a related Flutter issue: