invertase / react-native-firebase-starter

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

Android build failed #100

Closed dreamdev21 closed 5 years ago

dreamdev21 commented 5 years ago

I am running current version, but can't build android.

Here is my 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 = 21
    compileSdkVersion = 28
    targetSdkVersion = 28
    supportLibVersion = "27.1.1"
    multiDexEnabled = true

  }
  repositories {
    google()
    jcenter()
    maven {
      url 'https://maven.fabric.io/public'
    }
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0'
    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")
}

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.xxx.xxx"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    ndk {
      abiFilters "armeabi-v7a", "x86"
    }
    // because of firestore:
    multiDexEnabled true
  }
  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"
    }
    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 'com.android.support:multidex:1.0.3'
  implementation 'com.android.support:design:27.1.0'

  implementation project(':react-native-gesture-handler')
  implementation project(':react-native-firebase')
  implementation project(':react-native-fast-image')
  implementation project(':react-native-vector-icons')
  //noinspection GradleDynamicVersion
  implementation "com.facebook.react:react-native:+"
  implementation fileTree(dir: "libs", include: ["*.jar"])
  implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
/* ----------------------------
   *    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'
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

package.json

{
  "name": "xxx",
  "version": "5.1.0",
  "private": true,
  "devDependencies": {
    "babel-eslint": "9.0.0",
    "babel-jest": "23.6.0",
    "eslint": "5.6.0",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-react-native": "^3.6.0",
    "fs-extra": "^6.0.1",
    "husky": "^1.3.1",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.49.2",
    "react-test-renderer": "16.7.0",
    "replace-in-file": "^3.4.2",
    "prettier": "^1.15.2",
    "pretty-quick": "^1.8.0"
  },
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios --simulator=\"iPhone X\"",
    "build-ios": "react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios",
    "apk": "cd android && ./gradlew assembleRelease",
    "rename": "node ./bin/rename.js",
    "start": "react-native start",
    "test": "jest",
    "lint": "node_modules/.bin/eslint *.js **/*.js --fix",
    "precommit": "npm run lint",
    "prepush": "npm run lint"
  },
  "jest": {
    "preset": "react-native"
  },
  "dependencies": {
    "moment": "^2.24.0",
    "prop-types": "^15.6.2",
    "react": "16.6.3",
    "react-native": "^0.58.6",
    "react-native-dom": "^0.5.0",
    "react-native-elements": "^1.1.0",
    "react-native-fast-image": "^5.1.3",
    "react-native-firebase": "^5.2.0",
    "react-native-gesture-handler": "^1.1.0",
    "react-native-keyboard-aware-scroll-view": "^0.8.0",
    "react-native-simple-radio-button": "^2.7.3",
    "react-native-vector-icons": "^6.3.0",
    "react-navigation": "^3.1.4"
  },
  "husky": {
    "hooks": {
      "pre-commit": "pretty-quick --staged"
    }
  },
  "prettier": {
    "singleQuote": true,
    "arrowParens": "always"
  }
}

Build log is here.https://ghostbin.com/paste/re76v

 React Native Environment Info:
    System:
      OS: macOS 10.14.3
      CPU: (4) x64 Intel(R) Core(TM) i5-4570S CPU @ 2.90GHz
      Memory: 1.44 GB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.15.1 - /usr/local/bin/node
      Yarn: 1.13.0 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 25, 26, 27, 28
        Build Tools: 27.0.3, 28.0.2, 28.0.3
        System Images: android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5264788
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: ^0.58.6 => 0.58.6 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Any ideas?

rohit75 commented 5 years ago

Im facing the same issue too. Any solutions?

dreamdev21 commented 5 years ago

Yes, I have fixed. Here is my current configurations.

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.invertase.rnfirebasestarter"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    ndk {
      abiFilters "armeabi-v7a", "x86"
    }
    // because of firestore:
    multiDexEnabled true
  }
  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"
    }
    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 'com.android.support:multidex:1.0.3'
  implementation 'com.android.support:design:27.1.0'

  implementation project(':react-native-gesture-handler')
  implementation project(':react-native-firebase')
  implementation project(':react-native-fast-image')
  implementation project(':react-native-vector-icons')

  //noinspection GradleDynamicVersion
  implementation "com.facebook.react:react-native:+"
  implementation fileTree(dir: "libs", include: ["*.jar"])

   implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"

/* ----------------------------
   *    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'
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
  ext {
    buildToolsVersion = "28.0.2"
    minSdkVersion = 21
    compileSdkVersion = 28
    targetSdkVersion = 26
    supportLibVersion = "27.1.0"
    multiDexEnabled = true
  }
  repositories {
    google()
    jcenter()
    maven {
      url 'https://maven.fabric.io/public'
    }
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0'
    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")
}
dan-fein commented 4 years ago

What was the actual solution here?

mikehardy commented 4 years ago

I'm not sure I would base work off what's in master here right now as it will leave you with a react-native 0.59 project (and an immediate backlog of tasks to upgrade that to react-native 0.60, which is not the easiest upgrade). Cloning the fork and using the branch for the PR upgrading it to RN60 might be a better alternative https://github.com/invertase/react-native-firebase-starter/pull/135