1

I tried implementing all required things for Android, but while the App works on iOS it doesn't work on Android. Can someone please tell me what is going wrong and how to fix this issue.

  Plugin project :firebase_core_web not found. Please update settings.gradle.
Plugin project :google_sign_in_web not found. Please update settings.gradle.

FAILURE: Build failed with an exception.                                

* What went wrong:                                                      
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not find firebase-core:16.0.9:.                              
     Required by:                                                       
         project :app                                                   

* 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 1s                                                      
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                         2.2s
Exception: Gradle task assembleDebug failed with exit code 1

I added all dependencies as needed in the pubspec.yaml, since this app is already working on iOS and I just want to also have Android users. My pubspec.yaml file:

 name: example
description: A new Flutter project.


version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:


  flutter:
    sdk: flutter


  cupertino_icons: ^0.1.2
  firebase_core: ^0.4.0+9
  firebase_analytics: ^5.0.2
  firebase_auth: ^0.14.0+5
  cloud_firestore: ^0.12.9+5
  rflutter_alert: ^1.0.3
  modal_progress_hud: ^0.1.3
  flutter_auth_buttons: ^0.8.0
  google_sign_in: ^4.4.1


dev_dependencies:
  flutter_test:
    sdk: flutter






  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

This is my build.gradle in the android directory:

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
         google()  // Google's Maven repository
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'  // Google Services plugin
    }
}

allprojects {
    repositories {
        google()  // Google's Maven repository
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Thats the new error message:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugGoogleServices'.
> No matching client found for package name 'com.example.list'

* 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 1s
26 actionable tasks: 24 executed, 2 up-to-date

new error message after editing settings.gradle:

Launching lib/main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...
D8: Cannot fit requested classes in a single dex file (# methods: 87571 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
    at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:132)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:119)
    at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:102)
    at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:445)
    at com.android.build.gradle.internal.tasks.Workers$ActionFacade.run(Workers.kt:348)
    at org.gradle.workers.internal.AdapterWorkAction.execute(AdapterWorkAction.java:50)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:47)
    at 

org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:65)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:61)
    at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:98)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.execute(NoIsolationWorkerFactory.java:61)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at 

org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:56)
    at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:215)
    at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:210)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
    at 

org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.lang.Thread.run(Thread.java:748)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
    at com.android.tools.r8.utils.O.a(:65)
    at com.android.tools.r8.D8.run(:11)
    at 

com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:117)
    ... 34 more
Caused by: com.android.tools.r8.utils.b: Error: null, Cannot fit requested classes in a single dex file (# methods: 87571 > 65536)
    at com.android.tools.r8.utils.y0.a(:21)
    at com.android.tools.r8.dex.K.a(:56)
    at com.android.tools.r8.dex.K$h.a(:5)
    at com.android.tools.r8.dex.b.b(:15)
    at com.android.tools.r8.dex.b.a(:38)
    at com.android.tools.r8.D8.d(:87)
    at com.android.tools.r8.D8.b(:1)
    at com.android.tools.r8.utils.O.a(:30)
    ... 36 more


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
     The number of method references in a .dex file cannot exceed 64K.
     Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

* 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 7s
[!] The shrinker may have failed to optimize the Java bytecode.
    To disable the shrinker, pass the `--no-shrink` flag to this command.
    To learn more, see: https://developer.android.com/studio/build/shrink-code
Exception: Gradle task assembleDebug failed with exit code 1
Felix
  • 113
  • 2
  • 10

3 Answers3

3

you multidex support for your app. change app/build.gradle add two lines of code and you are golden.

 defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.example.app"
            minSdkVersion 16
            targetSdkVersion 29
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
    //add this to resolve dex error
            multiDexEnabled true
        }

        buildTypes {
            release {
                // TODO: Add your own signing config for the release build.
                // Signing with the debug keys for now, so `flutter run --release` works.
                signingConfig signingConfigs.debug
            }
        }
    }

    flutter {
        source '../..'
    }

    dependencies {
    //add this to resolve dex error
        implementation 'androidx.multidex:multidex:2.0.1'
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"


    }
Hardik
  • 56
  • 1
  • OMG it finally works! Thanks a lot - you saved my ass! – Felix May 06 '20 at 16:17
  • For everyone else seeing this include the code and afterward do flutter pub cache repair and then sync it in Android Studio (click on open Android Project to sync). After that, you can try to run it! – Felix May 06 '20 at 16:19
1

Change settings.gradle to this:

include ':app'

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}

plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    include ":$name"
    project(":$name").projectDir = pluginDirectory
}
Hardik
  • 56
  • 1
0

Do flutter pub cache repair to fix issues with your flutter packages / plugins in cache directory (that might sometime re-downloads every package in the cache).

Clearing the ~/.pub-cache directory will work too. In my system this directory located at C:\Users\BLiyanage\AppData\Roaming\Pub\Cache\hosted (This location may differ for you).

For IOS .pub-cache exists at: Users/someuser/.pub-cache/hosted/pub.dartlang.org

Read more here for fixing issues similar to this. And similar issue ticker.

Blasanka
  • 21,001
  • 12
  • 102
  • 104
  • Thanks for that quick response, but I tried some of them and it didn't work. I even tried deleting the whole android folder and creating a new one and setting up Firebase again. – Felix Apr 28 '20 at 15:04
  • Did you try `flutter pub cache repair`? and all packages installed successfully? – Blasanka Apr 28 '20 at 15:05
  • @Felix And can you tell me the `classpath` in your android directory build.gradle? – Blasanka Apr 28 '20 at 15:08
  • yes I tried flutter pub cache repair and everything went successfully. But it still shows the same issue – Felix Apr 28 '20 at 15:11
  • Can you try changing your `classpath` to `classpath com.google.gms:google-services:4.0.2` or it will be easy for you to change to this `classpath com.google.gms:google-services:3.2.1` and let me know? – Blasanka Apr 28 '20 at 15:15
  • @Felix Note that you must open `android` directory in android studio and after change gradle file you must sync it / gradle build. Also try `classpath 'com.android.tools.build:gradle:3.5.0'` to `classpath 'com.android.tools.build:gradle:3.4.2'` – Blasanka Apr 28 '20 at 16:05
  • Wait how can I sync it ? – Felix Apr 28 '20 at 18:04
  • @Felix If you open flutter project -> android directory in android studio and did those changes Anrdoid Stdio will ask to sync in the top of the editor. – Blasanka Apr 28 '20 at 18:21
  • when I press sync now it says: > Configure project :app Plugin project :firebase_core_web not found. Please update settings.gradle. Plugin project :google_sign_in_web not found. Please update settings.gradle. CONFIGURE SUCCESSFUL in 2s – Felix Apr 28 '20 at 18:58