flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[all] Flutter Android build fails with firebase dependencies.

Open erluxman opened this issue 7 years ago • 34 comments

I am using Android Studio 3.5 stable

java -version 1.8

and this is the issue :

I have project gradle like this :

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:4.3.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

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

App gradle like this :

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.takefun.android"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        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 {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    implementation 'com.android.support:multidex:1.0.3'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

& Pubspec.yaml like this :

name: Name
description: Expense.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
   flutter:
     sdk: flutter
  cupertino_icons: ^0.1.2
  image_picker: ^0.6.0+17
  cloud_firestore: ^0.12.9
  firebase_auth: ^0.14.0+2
  firebase_core: ^0.4.0+8
  google_sign_in: ^4.0.6
  fimber: ^0.3.2
  gradient_widgets: ^0.5.0
  flutter_svg: ^0.13.1
  flutter_vector_icons: ^0.2.0
  image_cropper: ^1.0.2
  firebase_storage: ^3.0.5
  stack_trace: ^1.9.3


dev_dependencies:
  flutter_test:
    sdk: flutter


My iOS builds runs well but my android build is failing with console output :

Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...

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 com.google.database.firebase:database.firebase-firestore:19.0.0.
     Required by:
         project :app > project :cloud_firestore
   > Could not find com.google.database.firebase:database.firebase-core:16.0.9.
     Required by:
         project :app > project :firebase_core

* 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 51s
Finished with error: Gradle task assembleDebug failed with exit code 1

Flutter doctor has the following output (just listed android and android studio related ones):


[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.6 18G87, locale en-US)
    • Flutter version 1.7.8+hotfix.4 at /Users/adventure/dev/flutter
    • Framework revision 20e59316b8 (5 weeks ago), 2019-07-18 20:04:33 -0700
    • Engine revision fee001c93f
    • Dart version 2.4.0

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/adventure/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio 3.5.app/Contents
    • Flutter plugin version 38.2.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 37.1.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

 

erluxman avatar Aug 23 '19 07:08 erluxman

Same here, when trying to actually run (not build, it does actually build) the _firebaseAuth.signInWithCustomToken(token: token) method, it goes like this:

W/BiChannelGoogleApi(19269): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzak@826aa86
E/JavaBinder(19269): *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
E/JavaBinder(19269): java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArrayMap;
E/JavaBinder(19269): 	at com.google.firebase.auth.internal.zzam.zzc(Unknown Source:22)
E/JavaBinder(19269): 	at com.google.firebase.auth.internal.zzam.zzde(Unknown Source:17)
E/JavaBinder(19269): 	at com.google.firebase.auth.internal.zzam.zzdd(Unknown Source:8)
E/JavaBinder(19269): 	at com.google.firebase.auth.internal.zzan.zzdf(Unknown Source:1)
E/JavaBinder(19269): 	at com.google.firebase.auth.internal.zzm.isAnonymous(Unknown Source:47)
E/JavaBinder(19269): 	at com.google.firebase.auth.internal.zzat.zzi(Unknown Source:57)
E/JavaBinder(19269): 	at com.google.firebase.auth.internal.zzat.zzg(Unknown Source:10)
E/JavaBinder(19269): 	at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source:62)
E/JavaBinder(19269): 	at com.google.firebase.auth.FirebaseAuth$zzb.zza(Unknown Source:5)
E/JavaBinder(19269): 	at com.google.firebase.auth.api.internal.zzcp.zzdx(Unknown Source:14)
E/JavaBinder(19269): 	at com.google.firebase.auth.api.internal.zzen.zzen(Unknown Source:35)
E/JavaBinder(19269): 	at com.google.firebase.auth.api.internal.zzen.zza(Unknown Source:41)
E/JavaBinder(19269): 	at com.google.firebase.auth.api.internal.zzep.zza(Unknown Source:9)
E/JavaBinder(19269): 	at com.google.firebase.auth.api.internal.zzdx.dispatchTransaction(Unknown Source:9)
E/JavaBinder(19269): 	at com.google.android.gms.internal.firebase_auth.zza.onTransact(Unknown Source:13)
E/JavaBinder(19269): 	at android.os.Binder.execTransactInternal(Binder.java:1021)
E/JavaBinder(19269): 	at android.os.Binder.execTransact(Binder.java:994)
E/JavaBinder(19269): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.util.ArrayMap" on path: DexPathList[[zip file "/data/app/com.app.myproject-NarLETRcOMNLCL2bBLZTdg==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.myproject-NarLETRcOMNLCL2bBLZTdg==/lib/arm64, /data/app/com.app.myproject-NarLETRcOMNLCL2bBLZTdg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
E/JavaBinder(19269): 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
E/JavaBinder(19269): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/JavaBinder(19269): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/JavaBinder(19269): 	... 17 more
E/AndroidRuntime(19269): FATAL EXCEPTION: Binder:19269_2
E/AndroidRuntime(19269): Process: com.app.myproject, PID: 19269
E/AndroidRuntime(19269): java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArrayMap;
E/AndroidRuntime(19269): 	at com.google.firebase.auth.internal.zzam.zzc(Unknown Source:22)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.internal.zzam.zzde(Unknown Source:17)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.internal.zzam.zzdd(Unknown Source:8)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.internal.zzan.zzdf(Unknown Source:1)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.internal.zzm.isAnonymous(Unknown Source:47)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.internal.zzat.zzi(Unknown Source:57)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.internal.zzat.zzg(Unknown Source:10)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source:62)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.FirebaseAuth$zzb.zza(Unknown Source:5)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.api.internal.zzcp.zzdx(Unknown Source:14)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.api.internal.zzen.zzen(Unknown Source:35)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.api.internal.zzen.zza(Unknown Source:41)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.api.internal.zzep.zza(Unknown Source:9)
E/AndroidRuntime(19269): 	at com.google.firebase.auth.api.internal.zzdx.dispatchTransaction(Unknown Source:9)
E/AndroidRuntime(19269): 	at com.google.android.gms.internal.firebase_auth.zza.onTransact(Unknown Source:13)
E/AndroidRuntime(19269): 	at android.os.Binder.execTransactInternal(Binder.java:1021)
E/AndroidRuntime(19269): 	at android.os.Binder.execTransact(Binder.java:994)
E/AndroidRuntime(19269): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.util.ArrayMap" on path: DexPathList[[zip file "/data/app/com.app.myproject-NarLETRcOMNLCL2bBLZTdg==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.myproject-NarLETRcOMNLCL2bBLZTdg==/lib/arm64, /data/app/com.app.myproject-NarLETRcOMNLCL2bBLZTdg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
E/AndroidRuntime(19269): 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
E/AndroidRuntime(19269): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(19269): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(19269): 	... 17 more
I/Process (19269): Sending signal. PID: 19269 SIG: 9
Lost connection to device.

On the other hand I can't even manage to build in iOS:

Xcode build done.                                           24.1s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **
Xcode's output:
↳
    /Users/aru/workspace/beyla/beylastaff/beylastaff/ios/Runner/GeneratedPluginRegistrant.m:6:9: fatal error: 'cloud_firestore/CloudFirestorePlugin.h' file not found
    #import <cloud_firestore/CloudFirestorePlugin.h>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.

arudp avatar Aug 24 '19 17:08 arudp

I am facing it as well. It stops recognizing the GradleException inside of a build.gradle

idurvesh avatar Aug 26 '19 02:08 idurvesh

I had a similar error. Adding this at the bottom of android/app/build.gradle solved the problem temporarily for me, maybe it will work for you too:

apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

ghost avatar Aug 26 '19 04:08 ghost

Hey @erluxman, try changing classpath 'com.google.gms:google-services:4.3.0' in your project gradle.build to classpath 'com.google.gms:google-services:3.2.1'

let me know if it worked for you

NoamDev avatar Aug 26 '19 09:08 NoamDev

I had a similar error. Adding this at the bottom of android/app/build.gradle solved the problem temporarily for me, maybe it will work for you too:

apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

I tried that but I get this error A problem occurred evaluating project ':app'.

No such property: config for class: com.google.gms.googleservices.GoogleServicesPlugin

erluxman avatar Aug 29 '19 03:08 erluxman

Hey @erluxman, try changing classpath 'com.google.gms:google-services:4.3.0' in your project gradle.build to classpath 'com.google.gms:google-services:3.2.1'

let me know if it worked for you

Did not work

erluxman avatar Aug 29 '19 03:08 erluxman

Yeah, I wasn't sure it'll work. I have another idea, try to add in the end of depndencies(){} those two lines

implementation 'firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-firestore:19.0.0'

NoamDev avatar Aug 29 '19 16:08 NoamDev

Yeah, I wasn't sure it'll work. I have another idea, try to add in the end of depndencies(){} those two lines

implementation 'firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-firestore:19.0.0'

Did not help :(

erluxman avatar Sep 11 '19 06:09 erluxman

I have similar problem with firebase_auth. On line await _auth.signInWithCredential(credential) app crashed with error java.lang.IllegalArgumentException: Unsupported value: null

Babiosik avatar Sep 11 '19 19:09 Babiosik

@erluxman I'm sorry, my mistake, could you try this instead? If it doesn't work, could publish the new android build log so I can know if the problem was partially solved?

implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-firestore:19.0.0'

NoamDev avatar Sep 17 '19 05:09 NoamDev

With same problem when import firebase_database classpath 'com.android.tools.build:gradle:3.2.1'
classpath com.google.gms:google-services:3.2.1

and in gradle.properties add android.useAndroidX=true android.enableJetifier=true

Seems everything goes to normal.

lakwsh01 avatar Sep 28 '19 13:09 lakwsh01

Hey @erluxman, try changing classpath 'com.google.gms:google-services:4.3.0' in your project gradle.build to classpath 'com.google.gms:google-services:3.2.1'

let me know if it worked for you

Cloned an old repo, and this really helped.

samdx avatar Oct 13 '19 01:10 samdx

Hi @erluxman did the proposed solution fix the issue? If didn't and you are still experiencing this issue with the latest version of Flutter and FlutterFire plugin can you please provide your updated flutter doctor -v and your and your flutter run --verbose/flutter build --verbose ? Also, to better address the issue, would be helpful if you could post a self contained app on github or the steps to reproduce it. Thank you

iapicca avatar Oct 23 '19 11:10 iapicca

Hi @erluxman does the proposed solution fix the issue?

iapicca avatar Oct 24 '19 13:10 iapicca

That solution fixed my issue even without having to put manual dependencies to app.gradle file.

Thanks a lot.

erluxman avatar Oct 25 '19 03:10 erluxman

Try changing the minimum target SDK version from v16 to v21.

wa11breaker avatar Oct 25 '19 15:10 wa11breaker

worked for me after adding these lines....

  1. Inside app folder in file build.gradle
  • add 'multiDexEnabled true' inside 'defaultConfig'
defaultConfig {
    multiDexEnabled true
}
  • Then,
dependencies {
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'com.google.firebase:firebase-firestore:19.0.0'
    implementation 'com.android.support:multidex:1.0.3'
}
  1. The main problem arises with dependency version added in the build.gradle file located outside of app folder...Generally firebase tells to add dependency like this:
dependencies {
        classpath 'com.google.gms:google-services:4.3.2'
    }

but the conflict is with the version 4.3.2 as the line before it in my project is classpath 'com.android.tools.build:gradle:3.2.1' So, it conflicts with this tools version.

  • So, change it to this:
dependencies {
        classpath 'com.google.gms:google-services:3.2.1'
    }
  1. If you're using android X, don't forget to add the following lines in gradle.properties file..
android.useAndroidX=true
android.enableJetifier=true

Now, I hope your project will run.

hridoy100 avatar Nov 15 '19 20:11 hridoy100

For me the issue with this error, and why it is so difficult to find a solution for it is that it is wrong. It took me weeks to resolve this issue because the error has absolutely 0 to do with firebase being incompatible with androidx and everything to do with my key file (your .jks file). For me, the file path was incorrect, and correcting this made everything work again like magic.

It is likely that if you are tearing your hair out over this issue, that this is not even an issue. Have a look at your key store file and make sure everything is correct with it. If the app runs perfectly fine, but will not build, there are only two files involved that are different. Your google-services.json and your keystore file.

Absolutely terrible error reporting.

ArtfulDodgerB92 avatar Nov 30 '19 00:11 ArtfulDodgerB92

For me the issue with this error, and why it is so difficult to find a solution for it is that it is wrong. It took me weeks to resolve this issue because the error has absolutely 0 to do with firebase being incompatible with androidx and everything to do with my key file (your .jks file). For me, the file path was incorrect, and correcting this made everything work again like magic.

It is likely that if you are tearing your hair out over this issue, that this is not even an issue. Have a look at your key store file and make sure everything is correct with it. If the app runs perfectly fine, but will not build, there are only two files involved that are different. Your google-services.json and your keystore file.

Absolutely terrible error reporting.

I share your sentiment <3

as1ndu avatar Dec 08 '19 00:12 as1ndu

Hi all are you still experiencing the issue with the latest stable version of flutter and the latest version of firebase? thank you

iapicca avatar Jan 28 '20 08:01 iapicca