realm-dart icon indicating copy to clipboard operation
realm-dart copied to clipboard

Build fails after upgrading Realm to 20.2.0 due to analyzer_plugin type conflicts

Open gauravkatkar4242 opened this issue 2 months ago • 3 comments

What happened?

After upgrading the Realm Flutter package, our project fails to build with the following errors related to analyzer_plugin and type conflicts between Element and Element2. It seems like some dependencies are incompatible with the current analyzer version.

Repro steps

Upgrade Realm in pubspec.yaml to the latest version.

Run flutter pub get.

Run flutter pub run build_runner build (or any build using build_runner).

Version

3.29.3

What Atlas Services are you using?

Local Database only

What type of application is this?

Flutter Application

Client OS and version

Code snippets

No response

Stacktrace of the exception/crash you're getting

Building package executable... (5.5s)
Built build_runner:build_runner.
[INFO] Generating build script completed, took 750ms
[WARNING] ../../../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:2133:32: Error: The argument type 'Element' can't be assigned to the parameter type 'Element2'.
 - 'Element' is from 'package:analyzer/dart/element/element.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.6.0/lib/dart/element/element.dart').
 - 'Element2' is from 'package:analyzer/dart/element/element2.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.6.0/lib/dart/element/element2.dart').
            .publiclyExporting(element, resultCache: resultCache) ??
                               ^
../../../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:2133:54: Error: The argument type 'Map<Element, LibraryElement?>?' can't be assigned to the parameter type 'Map<Element2, LibraryElement2?>?'.
 - 'Map' is from 'dart:core'.
 - 'Element' is from 'package:analyzer/dart/element/element.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.6.0/lib/dart/element/element.dart').
 - 'LibraryElement' is from 'package:analyzer/dart/element/element.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.6.0/lib/dart/element/element.dart').
 - 'Element2' is from 'package:analyzer/dart/element/element2.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.6.0/lib/dart/element/element2.dart').
 - 'LibraryElement2' is from 'package:analyzer/dart/element/element2.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.6.0/lib/dart/element/element2.dart').
            .publiclyExporting(element, resultCache: resultCache) ??
                                                     ^
../../../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:2137:40: Error: The getter 'source' isn't defined for the class 'Object'.
 - 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'source'.
    var uriToImport = libraryToImport?.source.uri;
                                       ^^^^^^
../../../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:2150:58: Error: The argument type 'Object?' can't be assigned to the parameter type 'LibraryElement?'.
 - 'Object' is from 'dart:core'.
 - 'LibraryElement' is from 'package:analyzer/dart/element/element.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.6.0/lib/dart/element/element.dart').
      _removeUnnecessaryPendingElementImports(newImport, libraryToImport);
                                                         ^
../../../.pub-cache/hosted/pub.dev/analyzer_plugin-0.12.0/lib/src/utilities/change_builder/change_builder_dart.dart:2182:14: Error: The method 'publiclyExporting2' isn't defined for the class 'TopLevelDeclarations'.
 - 'TopLevelDeclarations' is from 'package:analyzer/src/services/top_level_declarations.dart' ('../../../.pub-cache/hosted/pub.dev/analyzer-7.6.0/lib/src/services/top_level_declarations.dart').
Try correcting the name to the name of an existing method, or defining a method named 'publiclyExporting2'.
            .publiclyExporting2(element, resultCache: resultCache) ??
             ^^^^^^^^^^^^^^^^^^
[INFO] Precompiling build script... completed, took 8.2s
[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.

Relevant log output


gauravkatkar4242 avatar Oct 10 '25 06:10 gauravkatkar4242

Just following up on this issue. The upcoming Google deadline to update the page size to 16KB is approaching, and this build failure after upgrading to Realm 20.2.0 due to analyzer_plugin type conflicts is blocking progress.

Any updates, guidance, or temporary workarounds would be greatly appreciated.

Thank you!

gauravkatkar4242 avatar Oct 13 '25 06:10 gauravkatkar4242

20.2.0 had to pin the version of the build dependency due to incompatibilities introduced in later versions. I am not sure if that's the reason for the conflict, but considering nothing else has changed, it's very likely to be the case. My advice would be to either identify the package that has a conflicting build dependency and find a version that's compatible with Realm or try to upgrade build in the Realm generator packages and put up a PR to unblock the upgrade.

nirinchev avatar Oct 13 '25 09:10 nirinchev

Realm Android Compilation Issue with SDK 36+

Observing the problem here and seeking a solution with the help of AI, I came to the conclusion that the problem is as follows:

When building a Flutter Android application using Realm 20.2.0, the build fails during the Gradle checkDebugAarMetadata task with multiple dependency compatibility errors.

What went wrong:

Execution failed for task ':realm:checkDebugAarMetadata'.

A problem was found when checking AAR metadata:

Dependency 'androidx.fragment:fragment:1.7.1' requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs.

:realm is currently compiled against android-31.

The error is repeated for 19 different AndroidX dependencies (androidx.window, androidx.activity, androidx.lifecycle, androidx.core, androidx.savedstate, androidx.annotation, etc.), all requiring compileSdkVersion 34+ but the Realm module is compiled against android-31.

Root Cause

The Realm Android AAR (Android Archive Library) distributed in version 20.2.0 via pub.dev was pre-compiled with compileSdkVersion 31, which is incompatible with modern AndroidX dependencies that require compileSdkVersion 34 or higher.

Location of issue: /Users/Zeca/.pub-cache/hosted/pub.dev/realm-20.2.0/android/build.gradle

android {
    compileSdkVersion 31  // ❌ Too old - causes incompatibility
}

Environment Details

Flutter Version: 3.38.4 Dart Version: 3.10.3 Realm Version: 20.2.0 Target Android SDK: 36 Target compileSdkVersion: 36 Kotlin Version: 1.9.0 Build System: Gradle with AndroidX dependencies Workaround Applied The issue was resolved by manually updating the compileSdkVersion in the cached Realm AAR:

sed -i '' 's/compileSdkVersion 31/compileSdkVersion 36/g'
/Users/Zeca/.pub-cache/hosted/pub.dev/realm-20.2.0/android/build.gradle

After this change and clearing the Gradle cache, the APK compiled successfully.

Expected Solution The Realm team should rebuild and redistribute the Android AAR for version 20.2.0 (or later) with compileSdkVersion 34 or higher to ensure compatibility with modern AndroidX dependencies.

Verification After applying the workaround:

✅ APK builds successfully with flutter build apk --debug ✅ All unit tests pass (5/5) ✅ No runtime errors reported Recommendations Rebuild Realm 20.2.0 (or create a patch release) with compileSdkVersion 34+ Update CI/CD pipeline to compile against Android SDK 34 or higher Test against latest AndroidX dependency versions before release

Zeca-dev avatar Dec 09 '25 03:12 Zeca-dev

Realm Android Compilation Issue with SDK 36+

Observing the problem here and seeking a solution with the help of AI, I came to the conclusion that the problem is as follows:

When building a Flutter Android application using Realm 20.2.0, the build fails during the Gradle checkDebugAarMetadata task with multiple dependency compatibility errors.

What went wrong:

Execution failed for task ':realm:checkDebugAarMetadata'.

A problem was found when checking AAR metadata:

Dependency 'androidx.fragment:fragment:1.7.1' requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs.

:realm is currently compiled against android-31.

The error is repeated for 19 different AndroidX dependencies (androidx.window, androidx.activity, androidx.lifecycle, androidx.core, androidx.savedstate, androidx.annotation, etc.), all requiring compileSdkVersion 34+ but the Realm module is compiled against android-31.

Root Cause

The Realm Android AAR (Android Archive Library) distributed in version 20.2.0 via pub.dev was pre-compiled with compileSdkVersion 31, which is incompatible with modern AndroidX dependencies that require compileSdkVersion 34 or higher.

Location of issue: /Users/Zeca/.pub-cache/hosted/pub.dev/realm-20.2.0/android/build.gradle

android { compileSdkVersion 31 // ❌ Too old - causes incompatibility }

Environment Details

Flutter Version: 3.38.4 Dart Version: 3.10.3 Realm Version: 20.2.0 Target Android SDK: 36 Target compileSdkVersion: 36 Kotlin Version: 1.9.0 Build System: Gradle with AndroidX dependencies Workaround Applied The issue was resolved by manually updating the compileSdkVersion in the cached Realm AAR:

sed -i '' 's/compileSdkVersion 31/compileSdkVersion 36/g' /Users/Zeca/.pub-cache/hosted/pub.dev/realm-20.2.0/android/build.gradle

After this change and clearing the Gradle cache, the APK compiled successfully.

Expected Solution The Realm team should rebuild and redistribute the Android AAR for version 20.2.0 (or later) with compileSdkVersion 34 or higher to ensure compatibility with modern AndroidX dependencies.

Verification After applying the workaround:

✅ APK builds successfully with flutter build apk --debug ✅ All unit tests pass (5/5) ✅ No runtime errors reported Recommendations Rebuild Realm 20.2.0 (or create a patch release) with compileSdkVersion 34+ Update CI/CD pipeline to compile against Android SDK 34 or higher Test against latest AndroidX dependency versions before release

Hi can you help me I am getting the issue but don't know about the sed-i command that you have used how can i use that one

Zaini-android avatar Dec 18 '25 12:12 Zaini-android

Realm Android Compilation Issue with SDK 36+

Observing the problem here and seeking a solution with the help of AI, I came to the conclusion that the problem is as follows:

When building a Flutter Android application using Realm 20.2.0, the build fails during the Gradle checkDebugAarMetadata task with multiple dependency compatibility errors.

What went wrong:

Execution failed for task ':realm:checkDebugAarMetadata'.

A problem was found when checking AAR metadata:

Dependency 'androidx.fragment:fragment:1.7.1' requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs.

:realm is currently compiled against android-31.

The error is repeated for 19 different AndroidX dependencies (androidx.window, androidx.activity, androidx.lifecycle, androidx.core, androidx.savedstate, androidx.annotation, etc.), all requiring compileSdkVersion 34+ but the Realm module is compiled against android-31.

Root Cause

The Realm Android AAR (Android Archive Library) distributed in version 20.2.0 via pub.dev was pre-compiled with compileSdkVersion 31, which is incompatible with modern AndroidX dependencies that require compileSdkVersion 34 or higher.

Location of issue: /Users/Zeca/.pub-cache/hosted/pub.dev/realm-20.2.0/android/build.gradle

android { compileSdkVersion 31 // ❌ Too old - causes incompatibility }

Environment Details

Flutter Version: 3.38.4 Dart Version: 3.10.3 Realm Version: 20.2.0 Target Android SDK: 36 Target compileSdkVersion: 36 Kotlin Version: 1.9.0 Build System: Gradle with AndroidX dependencies Workaround Applied The issue was resolved by manually updating the compileSdkVersion in the cached Realm AAR:

sed -i '' 's/compileSdkVersion 31/compileSdkVersion 36/g' /Users/Zeca/.pub-cache/hosted/pub.dev/realm-20.2.0/android/build.gradle

After this change and clearing the Gradle cache, the APK compiled successfully.

Expected Solution The Realm team should rebuild and redistribute the Android AAR for version 20.2.0 (or later) with compileSdkVersion 34 or higher to ensure compatibility with modern AndroidX dependencies.

Verification After applying the workaround:

✅ APK builds successfully with flutter build apk --debug ✅ All unit tests pass (5/5) ✅ No runtime errors reported Recommendations Rebuild Realm 20.2.0 (or create a patch release) with compileSdkVersion 34+ Update CI/CD pipeline to compile against Android SDK 34 or higher Test against latest AndroidX dependency versions before release

Hi can you help me I am getting the issue but don't know about the sed-i command that you have used how can i use that one

Hi, as I mentioned, the adjustment was made by an AI assistant. I'm not familiar with that command either. If you have an AI assistant available, put it in our Agent and give it that instruction; the chances of it solving the problem are very good.

Zeca-dev avatar Dec 18 '25 19:12 Zeca-dev

I actually soved the problem through the command thanks @Zeca-dev

Zaini-android avatar Dec 19 '25 06:12 Zaini-android