skip to Main Content

I am developing a flutter app for Android. For that I am using a realm database and I am using the realm dependency for flutter https://realm.io/realm-flutter/ to read data from it. This realm database is generated by some android library com.my_realm_generating_library.

My problem is now, that com.my_realm_generating_library imports the realm library for kotlin https://realm.io/realm-kotlin/ and because I am importing the realm library for flutter, the kotlin library is included a second time.

When I run flutter build apk I get this result:


Running Gradle task 'assembleRelease'...
Realm binaries for [email protected]+rc already downloaded
Realm install command finished.
ERROR:/home/user/.gradle/caches/transforms-3/c90739e9642326489e851a982778d55f/transformed/jetified-realm-android-library-10.6.1-runtime.jar: R8: Type io.realm.BuildConfig is defined multiple times: /home/user/.gradle/caches/transforms-3/c90739e9642326489e851a982778d55f/transformed/jetified-realm-android-library-10.6.1-runtime.jar:io/realm/BuildConfig.class, /home/user/projectname/build/realm/intermediates/runtime_library_classes_jar/release/classes.jar:io/realm/BuildConfig.class

FAILURE: Build failed with an exception.

* What went wrong:
  Execution failed for task ':app:minifyReleaseWithR8'.

> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
> Compilation failed to complete, origin: /home/user/.gradle/caches/transforms-3/c90739e9642326489e851a982778d55f/transformed/jetified-realm-android-library-10.6.1-runtime.jar:io/realm/BuildConfig.class

* Try:

> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s
Running Gradle task 'assembleRelease'...                            9,2s
Gradle task assembleRelease failed with exit code 1

When I remove the realm library from my pubspec.yaml, everything compiles. But I need access to my realm file from my kotlin code and my dart/flutter code. Is there some way to fix such dependency conflicts, where flutter uses a library and kotlin the same and in the end none of them work?

What I tried so far:

I removed realm: ^0.8.0+rc from the dependencies section of my pubspec.yaml. Then everything compiles. This is not an option because I need this library in my dart code.

I could also remove implementation "com.my_realm_generating_library" from android/app/build.gradle. But I also need this library in my kotlin code to generate my realm database. Therefor this is also no option.

2

Answers


  1. Chosen as BEST ANSWER

    Amazingly I was able to find an answer for my question, although I was unable to find one anywhere online so far. Hopefully this helps some people who get into the same trouble as I have.

    1. Firstly, I navigated into my projectname/android and ran ./gradlew app:dependencies --console=rich to find all the dependencies of com.my_realm_generating_library.
    2. In my case, the only dependency of com.my_realm_generating_library was io.realm:realm-android-library:10.13.0. I knew that this package will be provided by the realm-flutter dependency. Therefor I knew, that I can just force disable all transitive dependencies of com.my_realm_generating_library.

    The code I put in my build.gradle under the dependencies section was this:

    implementation("com.my_realm_generating_library") {
        transitive = false
    }
    

    Now everything works. Hope this helps!


  2. I got this problem when I was transferring a project from one PC to another.

    The following actions helped me:

    1. Delete the build folder

    2. Run

    flutter build apk

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search