invertase / react-native-firebase-starter

DEPRECATED: For RNFB v5 only.
https://rnfirebase.io/docs
Other
1.17k stars 334 forks source link

Receiving error: package android.support.multidex does not exist #137

Closed dan-fein closed 4 years ago

dan-fein commented 4 years ago

Hi I've just recently used this starter code and despite all of the posts about this issue, none of the proposed solutions have worked for me. It seems Multidex was introduced to support legacy devices, but I'm using Pie with API 28 and it's causing issues.

Please do not refer me to demo scripts as those have not been helpful.

The main error I'm getting is:

/Users/danfein/Desktop/reviews/native/android/app/src/main/java/com/invertase/rnfirebasestarter/MainApplication.java:3: error: package android.supp
ort.multidex does not exist
import android.support.multidex.MultiDexApplication;

build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
        maven {
          url 'https://maven.fabric.io/public'
        }
}
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.google.firebase:perf-plugin:1.2.1'
        classpath 'io.fabric.tools:gradle:1.28.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

app/build.gradle

apply plugin: "com.android.application"
apply plugin: "com.google.firebase.firebase-perf"
apply plugin: 'io.fabric'

import com.android.build.OutputFile
project.ext.react = [
    entryFile: "index.js",

    bundleInDebug: project.hasProperty("bundleInDebug") ? project.getProperty("bundleInDebug") : false,
]

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

def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.invertase.rnfirebasestarter"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"

        // Needed to support API<21, though there is a small chance proguard shrinks things sufficiently
        multiDexEnabled true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    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, "arm64-v8a": 3, "x86_64": 4]
            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 {
    implementation project(':rn-fetch-blob')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-fs')
    implementation project(':react-native-fetch-blob')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-google-signin')
    implementation project(':@react-native-community_async-storage')
    implementation project(':react-native-firebase')
    implementation project(':react-native-reanimated')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation project(path: ':react-native-firebase')

    // Required dependencies
    //noinspection GradleCompatible
    implementation "com.google.firebase:firebase-core:16.0.9"
    implementation "com.google.android.gms:play-services-base:16.1.0"

    /* -------------------------
    *   OPTIONAL FIREBASE SDKS
    * ------------------------- */

    implementation('com.google.firebase:firebase-ads:15.0.1') {
      // exclude `customtabs` as the support lib version is out of date
      // we manually add it as a dependency below with a custom version
      exclude group: 'com.android.support', module: 'customtabs'
    }

    // Authentication
    implementation "com.google.firebase:firebase-auth:17.0.0"
    // Analytics
    implementation "com.google.firebase:firebase-analytics:16.5.0"
    // Performance Monitoring
    implementation "com.google.firebase:firebase-perf:17.0.0"
    // Remote Config
    implementation "com.google.firebase:firebase-config:17.0.0"
    // Cloud Storage
    implementation "com.google.firebase:firebase-storage:17.0.0"
    // Dynamic Links
    implementation "com.google.firebase:firebase-dynamic-links:17.0.0"
    // Real-time Database
    implementation "com.google.firebase:firebase-database:17.0.0"
    // Cloud Functions
    implementation "com.google.firebase:firebase-functions:17.0.0"
    // Cloud Firestore
    implementation "com.google.firebase:firebase-firestore:19.0.2"
    // Cloud Messaging / FCM
    implementation "com.google.firebase:firebase-messaging:18.0.0"
    // Crashlytics
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.9@aar') {
        transitive = true
    }

    /* --------------------------------
    *  OPTIONAL SUPPORT LIBS
    * -------------------------------- */

    // Needed to support API<21, though there is a small chance proguard shrinks things sufficiently
    implementation "com.android.support:multidex:1.0.3"

    // For Firebase Ads
    //noinspection GradleCompatible
    implementation "com.android.support:customtabs:27.1.1"

    // For React Native Firebase Notifications
    implementation 'me.leolin:ShortcutBadger:1.1.22@aar'

}

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

mainApplication.java

package com.invertase.rnfirebasestarter;

import android.support.multidex.MultiDexApplication;

import com.facebook.react.ReactApplication;
import com.RNFetchBlob.RNFetchBlobPackage;
import com.imagepicker.ImagePickerPackage;
import com.rnfs.RNFSPackage;
import com.RNFetchBlob.RNFetchBlobPackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import co.apptailor.googlesignin.RNGoogleSigninPackage;
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
import com.swmansion.reanimated.ReanimatedPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import io.invertase.firebase.RNFirebasePackage;
// optional packages - add/remove as appropriate
import io.invertase.firebase.admob.RNFirebaseAdMobPackage;
import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage;
import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import io.invertase.firebase.config.RNFirebaseRemoteConfigPackage;
import io.invertase.firebase.database.RNFirebaseDatabasePackage;
import io.invertase.firebase.fabric.crashlytics.RNFirebaseCrashlyticsPackage;
import io.invertase.firebase.firestore.RNFirebaseFirestorePackage;
import io.invertase.firebase.functions.RNFirebaseFunctionsPackage;
import io.invertase.firebase.instanceid.RNFirebaseInstanceIdPackage;
import io.invertase.firebase.links.RNFirebaseLinksPackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
import io.invertase.firebase.perf.RNFirebasePerformancePackage;
import io.invertase.firebase.storage.RNFirebaseStoragePackage;

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

public class MainApplication extends MultiDexApplication 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 RNFetchBlobPackage(),
            new ImagePickerPackage(),
            new RNFSPackage(),
            new RNFetchBlobPackage(),
            new RNGestureHandlerPackage(),
        new AsyncStoragePackage(),
        new VectorIconsPackage(),
        new RNGoogleSigninPackage(),
        new RNFirebasePackage(),
        new ReanimatedPackage(),
        // add/remove these packages as appropriate
        new RNFirebaseAdMobPackage(),
        new RNFirebaseAnalyticsPackage(),
        new RNFirebaseAuthPackage(),
        new RNFirebaseRemoteConfigPackage(),
        new RNFirebaseCrashlyticsPackage(),
        new RNFirebaseDatabasePackage(),
        new RNFirebaseFirestorePackage(),
        new RNFirebaseFunctionsPackage(),
        new RNFirebaseInstanceIdPackage(),
        new RNFirebaseLinksPackage(),
        new RNFirebaseMessagingPackage(),
        new RNFirebaseNotificationsPackage(),
        new RNFirebasePerformancePackage(),
        new RNFirebaseStoragePackage()
      );
    }

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

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

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}
dan-fein commented 4 years ago

For some reason this exists in the code:

import android.support.multidex.MultiDexApplication;

but needed to be replaced with:

import androidx.multidex.MultiDexApplication;

mikehardy commented 4 years ago

Not "for some reason", but because you've crossed the AndroidX boundary - a not-very-comfortable transition for the react-native ecosystem, c.f. https://github.com/mikehardy/jetifier

Not trying to fob you off on demo scripts or other things, but there is some real knowledge here that's worth ingesting. The react-native ecosystem is still dealing with this transition so you are likely to encounter it with other modules + dependencies as well.

mikehardy commented 4 years ago

For reference - you can see on this line in the PR upgrading the starter to RN60 that it has already been changed https://github.com/invertase/react-native-firebase-starter/pull/135/files#diff-dc46f9f5dfe204e394fb41395ccd03cfR251

Also, I know you hate seeing this link, but the RN60 version of the demo script similarly has the updated dependency https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh#L127