invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.66k stars 2.21k forks source link

🔥 Error while generating the main dex list #1859

Closed lzwebc closed 5 years ago

lzwebc commented 5 years ago

Issue

I'm trying to move my app to react-native-firebase-starter so I initialized app with react-native-firebase-starter and installed packages with yarn add. When I try to run react-native run-android I get this error:

Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.

I've tried everything I could find and nothing helps.


Project Files

iOS

ios/Podfile:

# N/A

AppDelegate.m:

// N/A

Android

android/build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
  ext {
    buildToolsVersion = "28.0.2"
    minSdkVersion = 18
    compileSdkVersion = 27
    targetSdkVersion = 26
    supportLibVersion = "27.1.1"
  }
  repositories {
    google()
    jcenter()
    maven {
      url 'https://maven.fabric.io/public'
    }
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'com.google.gms:google-services:4.0.1'
    classpath 'com.google.firebase:firebase-plugins:1.1.5'
    classpath 'io.fabric.tools:gradle:1.25.4'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

allprojects {
  repositories {
    mavenLocal()
    google()
    jcenter()
    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.6'
  distributionUrl = distributionUrl.replace("bin", "all")
}

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

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

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

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

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
  lintOptions {
    disable 'GradleCompatible'
    disable 'InvalidPackage'
  }

  // because of firestore:
  dexOptions {
    javaMaxHeapSize "4g"
  }
  compileSdkVersion rootProject.ext.compileSdkVersion
  buildToolsVersion rootProject.ext.buildToolsVersion

  defaultConfig {
    applicationId "com.webcamera.webcameraski"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    ndk {
      abiFilters "armeabi-v7a", "x86"
    }
    // because of firestore:
    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
      }
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
  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"
      signingConfig signingConfigs.release
    }
    debug {
      minifyEnabled false
      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 {
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-video')
    implementation project(':react-native-photo-view')
    implementation project(':react-native-orientation')
    implementation project(':react-native-immersive')
    implementation project(':react-native-fs')
    implementation project(':react-native-firebase')
    implementation project(':react-native-fast-image')
  //noinspection GradleDynamicVersion
  implementation "com.facebook.react:react-native:+"
  implementation fileTree(dir: "libs", include: ["*.jar"])

/* ----------------------------
   *    REACT NATIVE FIREBASE
   * ---------------------------- */

  // Library as defined in settings.gradle
  implementation project(path: ':react-native-firebase', configuration: 'default')
  // Required dependencies
  //noinspection GradleCompatible
  implementation "com.google.firebase:firebase-core:16.0.6"
  implementation "com.google.android.gms:play-services-base:16.0.1"

  /* -------------------------
   *   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:16.1.0"
  // Analytics
  implementation "com.google.firebase:firebase-analytics:16.0.6"
  // Performance Monitoring
  implementation "com.google.firebase:firebase-perf:16.2.3"
  // Remote Config
  implementation "com.google.firebase:firebase-config:16.1.2"
  // Cloud Storage
  implementation "com.google.firebase:firebase-storage:16.0.5"
  // Invites
  implementation "com.google.firebase:firebase-invites:16.0.6"
  // Dynamic Links
  implementation "com.google.firebase:firebase-dynamic-links:16.1.5"
  // Real-time Database
  implementation "com.google.firebase:firebase-database:16.0.5"
  // Cloud Functions
  implementation "com.google.firebase:firebase-functions:16.1.3"
  // Cloud Firestore
  implementation "com.google.firebase:firebase-firestore:17.1.5"
  // Cloud Messaging / FCM
  implementation "com.google.firebase:firebase-messaging:17.3.4"
  // Crashlytics
  implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
    transitive = true
  }

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

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

  // For React Native Firebase Notifications
  implementation 'me.leolin:ShortcutBadger:1.1.21@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'

android/settings.gradle:

rootProject.name = 'WebCameraSki'
include ':react-native-firebase'
project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android')
include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')
include ':react-native-photo-view'
project(':react-native-photo-view').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-photo-view/android')
include ':react-native-orientation'
project(':react-native-orientation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation/android')
include ':react-native-immersive'
project(':react-native-immersive').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-immersive/android')
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android')
include ':react-native-fast-image'
project(':react-native-fast-image').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fast-image/android')

include ':app'

MainApplication.java:

// N/A

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webcamera.webcameraski"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

    <application
      android:name=".MainApplication"
      android:allowBackup="true"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
      <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
      </service>
      <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
        <intent-filter>
          <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
      </service>
    </application>

</manifest>

Environment


Think react-native-firebase is great? Please consider supporting the project with any of the below:

stale[bot] commented 5 years ago

Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

frostbyte3 commented 5 years ago

I'm having the exact same issue. Any updates?

rohit75 commented 5 years ago

Im also facing the same issue, can somebody please help

Vasundhara-Kurtkoti commented 5 years ago
frostbyte3 commented 5 years ago
  • What went wrong: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.

com.android.build.api.transform.TransformException: Error while generating the main dex list. Any solutions on this?

I got the issue fixed by running react-native unlink react-native-firebase to unlink firebase. I guess there's an issue when linking it for some reason.

NomanGul commented 5 years ago

Anyone plz help us :confused:

SevdaCimen commented 5 years ago

react-native unlink react-native-firebase

this works! thank you

stale[bot] commented 5 years ago

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

hindsricardo commented 5 years ago

I am facing the same issue. This seems to be the cause: > Task :app:transformClassesWithMultidexlistForDebug FAILED D8: Program type already present: io.invertase.firebase.database.RNFirebaseDatabase$5

nitinAct commented 5 years ago

Please tell me how to solve this issue. :(

mikehardy commented 5 years ago

I don't know, I can't reproduce it - see automated react-native-firebase example build here to make sure it works in your environment: https://github.com/mikehardy/rnfbdemo - you can fork that repo and add the database dependency if you like, and if you can demonstrate the failure we can try to fix it. But this is a stale issue so you might like to open a new one with full information filled in the template

mikehardy commented 5 years ago

Okay, I was working on react-native-firebase-starter today to upgrade it so it matches the current v5.5.4 release of react-native-firebase and I could finally reproduce this

It's a gradle cache issue, and if it happened for others the way it happened for me, you maybe tried to yarn android or somehow run the android gradle build before you did the yarn rename. Gradle cached some of the outputs and you end up with some pretty bizarre object collisions as gradle tries to merge the old build and the new build together to package it.

For me, I did rm -rf android/.gradle to clear out the project cache and that worked