1

I have a new flutter application (Nothing added or changed except following). I need to use these packages url_launcher, permission_handler and firebase_auth. But as soon as I import these packages in my main.dart file (after adding in pubsec.yaml)

import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:permission_handler/permission_handler.dart';

It fails to compile and shows following error.

D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
  Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
BUILD FAILED in 7s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See (this link will be in the comment) for more information on the problem and how to fix it.
*******************************************************************************************
Finished with error: Gradle task assembleDebug failed with exit code 1

What can I do to use all these three packages in same project. (I assumed it is because of androidX compatibility)

After adding following to gradlew.properties and setting compilerSdkVersion 28 in build gradle

android.useAndroidX=true
android.enableJetifier=true
android {
    compileSdkVersion 28
..

Now I get following error.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0-rc01) and runtime (1.1.0) classpath. You should manually set the same version via DependencyResolution
Kshitij Dhakal
  • 816
  • 12
  • 24

1 Answers1

2

Need to migrate your project to AndroidX. because permission_handler package have used AndroidX and you have used Support libraries in gradle.

check here.

As @Kshitij Dhakal suggested, you need to also apply dependency resolution when version of same library is different in different packages.

Like, This solution is taken from flutter issues.

subprojects {
    project.configurations.all {
    resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'androidx.core' 
                       && !details.requested.name.contains('androidx')) {
                  details.useVersion "1.0.1"
            }
       }
    }    
}
Abhay Koradiya
  • 2,068
  • 2
  • 15
  • 40