React-native-firebase: ERROR: Failed to resolve: com.android.support:multidex:26.1.0

Created on 6 Apr 2019  路  17Comments  路  Source: invertase/react-native-firebase

After installing FCM library, I'm getting the following error:

ERROR: Failed to resolve: com.android.support:multidex:26.1.0
Show in Project Structure dialog
Affected Modules: app, react-native-firebase

Removing the library everything works as expected. I tried to add into my app/build.gradle

    defaultConfig {
        ...
        multiDexEnabled true
    }
    implementation "com.android.support:multidex:26.1.0"

But didn't work

Those are my files:

app/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false


def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion


    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.example.project"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        multiDexEnabled true

    }
    dexOptions {
        jumboMode true  // This for string limit
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        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
    }
    implementation project(':react-native-contacts')
    compile project(':rn-fetch-blob')
    compile project(':react-native-bottom-action-sheet')
    compile project(':react-native-svg')
    compile project(':react-native-localize')
    compile project(':react-native-gesture-handler')
    compile project(':react-native-snackbar')
    compile project(':react-native-video')
    compile project(':react-native-vector-icons')
    compile project(':react-native-share')
    compile project(':react-native-os')
    compile project(':react-native-image-picker')
    compile project(':react-native-fs')
    compile project(':react-native-facebook-account-kit')
    compile project(':react-native-exception-handler')
    compile project(':react-native-device-info')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation "com.android.support:multidex:26.1.0"

    implementation "com.google.android.gms:play-services-base:15.0.0"
    implementation "com.google.firebase:firebase-core:15.0.2"
    implementation "com.google.firebase:firebase-messaging:15.0.2"

}

// 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'
}

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

build.gradle (project)

buildscript {
    ext {
        buildToolsVersion = "27.0.0"
        minSdkVersion = 21
        compileSdkVersion = 27
        targetSdkVersion = 28
        supportLibVersion = "27.1.1"
        googlePlayServicesVersion = "15.0.1"
    }
    repositories {
        google()
        jcenter()
        maven { url "https://maven.google.com" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath 'com.google.gms:google-services:3.2.1'
    }

    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support') {
                    details.useVersion "26.1.0"
                }
            }
        }
    }
}

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

task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

MainActivity.java

package com.example.project;

import com.facebook.react.ReactActivity;
import com.facebook.react.modules.core.PermissionListener;
import com.imagepicker.permissions.OnImagePickerPermissionsCallback;

public class MainActivity extends ReactActivity implements OnImagePickerPermissionsCallback {
    private PermissionListener listener;

    @Override
    protected String getMainComponentName() {
        return "example";
    }

    @Override
    public void setPermissionListener(PermissionListener listener)
    {
        this.listener = listener;
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
    {
        if (listener != null)
        {
            listener.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

MainApplication.java

package com.example.project;

import android.app.Application;
import android.content.Context;

import com.facebook.react.ReactApplication;
import com.reactnativecommunity.netinfo.NetInfoPackage;
import com.rt2zz.reactnativecontacts.ReactNativeContacts;
import com.RNFetchBlob.RNFetchBlobPackage;

import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
import ui.bottomactionsheet.RNBottomActionSheetPackage;
import com.horcrux.svg.SvgPackage;
import com.reactcommunity.rnlocalize.RNLocalizePackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import com.azendoo.reactnativesnackbar.SnackbarPackage;
import com.brentvatne.react.ReactVideoPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import cl.json.RNSharePackage;
import com.peel.react.rnos.RNOSModule;
import com.imagepicker.ImagePickerPackage;
import com.rnfs.RNFSPackage;
import io.underscope.react.fbak.RNAccountKitPackage;
import com.masteratul.exceptionhandler.ReactNativeExceptionHandlerPackage;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
            new ReactNativeContacts(),
            new RNFetchBlobPackage(),
            new RNBottomActionSheetPackage(),
            new SvgPackage(),
            new RNLocalizePackage(),
            new RNGestureHandlerPackage(),
            new SnackbarPackage(),
              new ReactVideoPackage(),
              new VectorIconsPackage(),
              new RNSharePackage(),
              new RNOSModule(),
              new ImagePickerPackage(),
              new RNFSPackage(),
              new RNAccountKitPackage(),
              new ReactNativeExceptionHandlerPackage(),
              new RNDeviceInfo(),
              new RNFirebasePackage(),
              new RNFirebaseMessagingPackage(),
              new RNFirebaseNotificationsPackage()
      );
    }



    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

If you need more files, please let me know.

Thanks

Most helpful comment

@fgagneten I think I just solved. I have RNN and RNB library on my project.
The step that I have done are:

  1. Delete implementation "com.android.support:multidex:26.1.0" and similiar, on me was implementation "com.android.support:multidex-instrumentation:1.0.3"
  2. Then, on android/build.graddle, replace
resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support') {
                    details.useVersion "26.1.0"
                }
            }

with this one

resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                    def requested = details.requested

                    if (requested.group == 'com.android.support') {
                        if (!requested.name.startsWith("multidex")) {
                            details.useVersion "${rootProject.ext.supportLibVersion}"
                        }
                    }

                }

It seems that there is no version from multidex:26.x.x or multidex:28.x.x,
This code details.useVersion "26.1.0" was like forcing all of our Android library into version 26.1.0. So That's why error Failed to resolve: com.android.support:multidex:26.1.0 appear.

After I did two steps up there, I build release version successfully.
Good luck with yours.

All 17 comments

Have you verified the example works: https://github.com/invertase/react-native-firebase-starter ?

Once you are sure the example works, I would very carefully examine any difference between your gradle setup and the examples and I'd move towards the examples - it's a pretty clean Android gradle setup and not a bad thing to start with / add on to

Thanks @mikehardy, but it didn't work. Now I'm having another error related to this issue: https://github.com/invertase/react-native-firebase/issues/1939

If I clean the solution I get:

Failed to resolve: com.android.support:multidex:26.1.0

Thanks

The problem happens using react-native-firebase > 4.0.0 (Probably because more internal libraries were added in that version)

Thanks @mikehardy, but it didn't work. Now I'm having another error related to this issue: #1939

@fgagneten Wait, you are telling me the example did not work? I asked if the example worked and you are saying it did not. Is that correct? Because it worked for me out of the box, so I am surprised

didn't work implementing the example build.gradle into my project.

I found a workaround and was removing
multiDexEnabled true
from react-native-firebase library

image

I know I shouldn't do that, but it was the only way I found. So I won't close the issue.

https://github.com/mikehardy/react-native-firebase-starter/blob/camera-test/android/app/build.gradle#L221

multidex has no such library version. most recent is 1.0.3

Don't forget to alter your application to extend MultiDexApplication or you'll fail on early APIs as well in debug mode

https://github.com/mikehardy/react-native-firebase-starter/blob/camera-test/android/app/src/main/java/com/kullki/rnfirebasetest/MainApplication.java#L35

It's really weird. I tried to extend from MultiDexApplication but the problem it is never recognized because couldn't load before the multidex ( Failed to resolve: com.android.support:multidex:26.1.0)

Of course it didn't. Because your referenced multidex library version didn't exist. I showed you the line of the gradle implementation declaration you should use. Did you use it? You should. It will work. I won't have time to respond to this issue anymore but I've give referenced what you need. Good luck

I tried, It didn't work. I don't have com.android.support:multidex:26.1.0 in my project. I think some other library is using that, but I used the finder and nothing.

Anyway I will wait someone has the same error.

@fgagneten have you solve the issue? Because I have something similar issue. When trying to run ./gradlew app:assembleRelease and get error Could not find com.android.support:multidex-instrumentation:28.0.0.

Nop, I couldn't. Let me know if you can solve the problem

Which library do you have in common with me?

@fgagneten I think I just solved. I have RNN and RNB library on my project.
The step that I have done are:

  1. Delete implementation "com.android.support:multidex:26.1.0" and similiar, on me was implementation "com.android.support:multidex-instrumentation:1.0.3"
  2. Then, on android/build.graddle, replace
resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support') {
                    details.useVersion "26.1.0"
                }
            }

with this one

resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                    def requested = details.requested

                    if (requested.group == 'com.android.support') {
                        if (!requested.name.startsWith("multidex")) {
                            details.useVersion "${rootProject.ext.supportLibVersion}"
                        }
                    }

                }

It seems that there is no version from multidex:26.x.x or multidex:28.x.x,
This code details.useVersion "26.1.0" was like forcing all of our Android library into version 26.1.0. So That's why error Failed to resolve: com.android.support:multidex:26.1.0 appear.

After I did two steps up there, I build release version successfully.
Good luck with yours.

@vivevio Worked like a charm!

Nice, this thread should be closed then.

I was using wix navigation library, and had to do this change here: https://medium.com/@lukebrandonfarrell/using-multidex-and-react-native-navigation-63bf4245e5e9

Was this page helpful?
0 / 5 - 0 ratings