Java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp
Asked Answered
S

13

23

Screenshot from Android StudioGoogle Play Services

This is React Native project. I have an error after successful build in Android Studio Emulator:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp

My files:

package.json:

...
"react-native": "^0.55.3",
"react-native-camera": "1.1.2",
"react-native-check-box": "^2.1.0",
"react-native-extended-stylesheet": "^0.8.1",
"react-native-firebase": "^4.2.0",
"react-native-geocoder": "^0.5.0",
"react-native-git-upgrade": "^0.2.7",
"react-native-htmlview": "^0.12.1",
"react-native-image-picker": "^0.26.10",
"react-native-linear-gradient": "^2.4.0",
"react-native-local-storage": "^1.5.2",
"react-native-maps": "^0.21.0",
"react-native-modal": "^5.4.0",
"react-native-modal-dropdown": "^0.6.1",
"react-native-read-more-text": "^1.0.0",
"react-native-router-flux": "^4.0.0-beta.27",
"react-native-svg-image": "^2.0.1",
"react-native-text-input-mask": "^0.7.0",
...

android/app/build.gradle:

...    
android {
    compileSdkVersion 27
    buildToolsVersion "27.0.1"

    defaultConfig {
        applicationId "com.something.anything"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        multiDexEnabled true
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    compile(project(':react-native-firebase')) {
        transitive = false
    }
    compile project(':react-native-geocoder')
    compile(project(':react-native-maps')) {
      exclude group: 'com.google.android.gms', module: 'play-services-base'
      exclude group: 'com.google.android.gms', module: 'play-services-maps'
      exclude group: 'com.google.android.gms', module: 'play-services-location'
    }

    compile 'com.google.android.gms:play-services-base:15.+'
    compile 'com.google.android.gms:play-services-maps:15.+'
    compile 'com.google.android.gms:play-services-location:15.+'
    compile (project(':react-native-camera')) {
    exclude group: "com.google.android.gms"
    compile 'com.android.support:exifinterface:25.+'
    compile ('com.google.android.gms:play-services-vision:12.0.1') {
        force = true
        }
    }
    compile project(':react-native-text-input-mask')
    compile project(':react-native-linear-gradient')
    compile project(':react-native-image-picker')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

subprojects {
  project.configurations.all {
     resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.android.support'
              && !details.requested.name.contains('multidex')
        ) {
           details.useVersion "27.1.0"
        }
     }
  }
}

I've tried a lot of solutions but nothing helped.

Schwing answered 30/5, 2018 at 15:13 Comment(2)
use same version of play-service libraries. Also dont use+ operator in dependencies. found versions services-base:15.+', vision:12.0.1Zelaya
@alex-khanenya did you find a solution? I have the same error. ThanksReplete
S
16

Faced the same issue. Then I found out that I missed an important set of instructions to integrate Firebase with Android project: https://firebase.google.com/docs/android/setup#add_firebase_to_your_app

Here is the summary of the steps in that documentation that helped in my case:

  1. Generate google-services.json and put it to your android/app/ directory.
  2. Add classpath 'com.google.gms:google-services:4.1.0' to buildscript -> dependencies section of your root-level build.gradle config; add google() to allprogects -> repositories section of the same file.
  3. Add implementation 'com.google.firebase:firebase-core:16.0.3' to dependencies section of your app module's build.gradle file; add apply plugin: 'com.google.gms.google-services' at the very bottom of the same file.
  4. Sync and rebuild. Now it should work.
Solarium answered 4/9, 2018 at 19:8 Comment(0)
P
6

On your android/app/build.gradle add one more implementation on dependeces:

...
dependencies {
    implementation "com.google.firebase:firebase-auth:17.0.0"
    ...
}
Pages answered 15/9, 2019 at 15:29 Comment(0)
G
4

There is probably some problem with the dependencies involved.

In my case, making the following changes worked perfectly in the app level build.gradle

dependencies{
     implementation 'com.google.firebase:firebase-auth:17.0.0'
     implementation 'com.firebaseui:firebase-ui-database:6.0.2'
     ...
}
Granville answered 2/11, 2019 at 20:26 Comment(0)
V
3

changed latest firebase-messaging google dependencies and modified other dependencies also in a same version in app gradle file. working fine now

dependencies version detail you can refer here

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
    implementation 'com.google.firebase:firebase-auth:17.0.0'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'
}
Vaudeville answered 14/6, 2019 at 9:5 Comment(0)
E
2

In my case I forgot to comment Database Package in MainApplication.java

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
            new AsyncStoragePackage(),
            new RNCameraPackage(),
            new VectorIconsPackage(),
            new RNGestureHandlerPackage(),
        new RNFirebasePackage(),
        // add/remove these packages as appropriate
        //new RNFirebaseAdMobPackage(),
        new RNFirebaseAnalyticsPackage(),
        //new RNFirebaseAuthPackage(),
        // new RNFirebaseRemoteConfigPackage(),
        new RNFirebaseCrashlyticsPackage(),
        // new RNFirebaseDatabasePackage(), <==== Comment this package
       // new RNFirebaseFirestorePackage(),
        // new RNFirebaseFunctionsPackage(),
        new RNFirebaseInstanceIdPackage(),
       // new RNFirebaseInvitesPackage(),
        new RNFirebaseLinksPackage(),
        new RNFirebaseMessagingPackage(),
        new RNFirebaseNotificationsPackage(),
        new RNFirebasePerformancePackage()
       // new RNFirebaseStoragePackage()
      );
    }
Eri answered 13/7, 2019 at 10:15 Comment(0)
G
2

If your are facing this issue in Flutter, Add this dependency in your android/app/build.gradle. And run your main.dart. No need to add any type of controller in ListView. If you are using listview on that page. If you are using Firebase please add this in depencdencies.

implementation "com.google.firebase:firebase-auth:19.3.0"

Gerous answered 16/4, 2020 at 9:43 Comment(0)
P
1

I have faced the same issues. You have to change the react-native-firebase version in pakage.json file. I found the solution from here

here

Pargeting answered 21/8, 2019 at 12:54 Comment(0)
A
1

what worked for me was just to remove the .android/ package completely from my project and then run

npx expo prebuild

in the root folder and it created a new android folder with a few changes (could see there are some because of GitHub addon in my VSCode), then when I ran the folder in my Android Studio it ran completely fine without any errors whatsoever.

Advance answered 22/9, 2023 at 8:3 Comment(0)
T
0
implementation("com.google.firebase:firebase-iid")
Through answered 23/11, 2021 at 6:6 Comment(1)
While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. You can find more information on how to write good answers in the help center: stackoverflow.com/help/how-to-answer . Good luck 🙂Lifetime
W
0

Solution 1:

Add one more implementation on dependeces in your android/app/build.gradle file.

dependencies {
    implementation "com.google.firebase:firebase-auth:17.0.0"
    ...
}

Solution 2:

  • Generate google-services.json and put it to your android/app/ directory.

  • Add classpath 'com.google.gms:google-services:4.1.0' to buildscript -> dependencies section of your root-level build.gradle config and add google() as first entry to allprogects -> repositories section of the same file.

      buildscript {
          repositories {
              google()
              jcenter()
          }
          dependencies {
              ...
              classpath 'com.google.gms:google-services:4.1.0'
          }
      }
      allprojects {
          repositories {
              google()
              ...
          }
      }
    
  • Add implementation 'com.google.firebase:firebase-core:16.0.3' to dependencies section of your app module's build.gradle file and add apply plugin: 'com.google.gms.google-services' at the very bottom of the same file.

    dependencies {
        ...
        implementation 'com.google.firebase:firebase-core:16.0.3'
    } 
    apply plugin: 'com.google.gms.google-services'
    
  • Sync and rebuild.

Whistle answered 23/11, 2021 at 16:59 Comment(0)
F
0

The only solution that worked for me is to upgrade all firebase dependencies and don't forget this one below cause Android Studio may not notify you about it.

implementation platform('com.google.firebase:firebase-bom:31.2.0')`
Fagin answered 13/2, 2023 at 22:55 Comment(0)
S
-1

UPDATE YOUR FIREBASE LIBRARIES!!!!

Eg. if your app uses firebase auth, Google for it, in its documentation they provide with the latest version, paste it to your build.gradle

The libraries added by your Firebase Assistant in Android Studio are usually old.

Synergy answered 1/6, 2020 at 18:52 Comment(0)
A
-3

In the gradle.properties file, try adding::

android.enableJetifier = true
android.useAndroidX = true
Automation answered 5/12, 2019 at 18:56 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.