I have used expo to start my project, but my project is not an expo project, it is a bare minimum project (with react native modules), I am not able to integrate react-native-firebase
on android.
I followed the docs and linked my project, after I run my project, I receive this error.
A problem occurred evaluating project ':@react-native-firebase_app'.
> Could not find method platform() for arguments
[com.google.firebase:firebase-bom:21.1.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
android/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 = 21
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
// 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"
}
maven { url 'https://maven.google.com' }
maven { url "https://www.jitpack.io" }
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.7'
distributionUrl = distributionUrl.replace("bin", "all")
}
android/app/build.gradle
:apply plugin: 'com.android.application'
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.1, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: "com.android.application"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
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-unimodules/gradle.groovy'
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 {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId "com.something.ver"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 2
versionName "1.1"
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", "arm64-v8a", "x86_64"
}
}
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, "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
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation project(':appcenter-crashes')
implementation project(':appcenter-analytics')
implementation project(':appcenter')
implementation project(':react-native-splash-screen')
implementation project(':react-native-sms-retriever')
implementation project(':react-native-image-crop-picker')
implementation project(path: ":@react-native-firebase_app")
// implementation 'com.android.support:design:28.0.0'
// implementation 'com.android.support:support-v4:28.0.0'
// implementation 'com.android.support:appcompat-v7:28.0.0'
implementation project(':react-native-config')
implementation project(':react-native-onesignal')
implementation project(':react-native-code-push')
implementation project(':@react-native-community_async-storage')
implementation project(':react-native-reanimated')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-vector-icons')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
compile 'com.google.android.gms:play-services-maps:8.1.0'
compile 'com.google.android.gms:play-services-plus:8.1.0'
addUnimodulesDependencies()
}
// 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/settings.gradle
:// N/A
MainApplication.java
:// N/A
Click To Expand
**`react-native info` output:**
React Native Environment Info:
System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
Memory: 108.02 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.6.0 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.10.2 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5791312
Xcode: 10.3/10G8 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.10 => 0.59.10
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-create-library: 3.1.2
react-native-git-upgrade: 0.2.7
- **Platform that you're experiencing the issue on**:
- [ ] iOS
- [x] Android
- [ ] **iOS** but have not tested behavior on Android
- [ ] **Android** but have not tested behavior on iOS
- [ ] Both
- **`react-native-firebase` version you're using that has this issue:**
- `e.g. 6.0.3`
- **`Firebase` module(s) you're using that has the issue:**
- `@react-native-firebase/app`
- **Are you using `TypeScript`?**
- `N0`
Tried this one as well, doesn't work
"tried this one as well" -> you did what exactly
That's a gradle method missing, and it's available on new gradle. Upgrade gradle, it works.
Alternatively, don't use the BOM (which uses platform()) on old gradle.
This has nothing to do with react-native-firebase.
I had same problem, and updating Gradle to 5.1.1 helped me. Thank you.
I can confirm it is not the react-native-firebase problem.
to anyone struggling to upgrade to Gradle 5.0 in a React Native project like I did:
android/gradle/gradle-wrapper.properties
:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
- then, in the project directory run
react-native run-android
Hi @sharoneh ! Gradle is actually up to 6.0.1 right now!
If you change the distributionUrl as you mention to 6.0.1 that will get the very latest stable, but I'm mostly writing to mention that after you do this you should cd android && ./gradlew wrapper
to update all of the wrapper scripts etc as well, otherwise the upgrade is only partial
https://gradle.org/install/#with-the-gradle-wrapper
Or to get the version and upgrade everything all at once (from the above link) -
./gradlew wrapper --gradle-version=6.0.1
in the android directory
cheers
Thanks for the response, @mikehardy!
So, I tried upgrading Gradle to version 6.0.1 in my project, but when I ran react-native run-android
after editing the distribution URL to this version, I got this warning:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Also, when I ran ./gradlew wrapper --gradle-version=6.0.1
, the distribution URL version kept updating to version 4.7 and this version doesn't have the features required for some dependencies in my project.
So the only working solution for me was upgrading to Gradle 5.0.
Thanks for the response, @mikehardy!
So, I tried upgrading Gradle to version 6.0.1 in my project, but when I ran
react-native run-android
after editing the distribution URL to this version, I got this warning:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
That is okay - deprecation stuff is just a warning for the future
Also, when I ran
./gradlew wrapper --gradle-version=6.0.1
, the distribution URL version kept updating to version 4.7 and this version doesn't have the features required for some dependencies in my project.
So the only working solution for me was upgrading to Gradle 5.0.
That is most strange - I just tested this in my project and at least starting from 6.0.1 (in my distribution url) if I run the same, afterwards, I'm still on 6.0.1 (which is what I'd expect).
gradle 5 certainly works so this probably a tangent to whatever useful feature(s) you are trying to add :-), but upgrading to 6 should work also. You can also just manually alter the distribution URL then run ./gradlew wrapper
twice (once to get the new gradle, once to upgrade the scripts) and that should work? Or just stay with 5 for now and ignore the mystery 4.7 self-downgrade it's doing
Cheers
@mikehardy I faced the same issue and it solved by upgrading gradle to 5.0-all ver. when I tried 6.0.1 version - some of third-party libraries throws errors
same issue, Any solution?
@ghasemikasra39 Gradle's on 6.4 right now. The gradle plugin is on 3.6.3, firebase BOM is 25.3.1 - get up to date and try again? It all works with current versions.
Thanks @sharoneh you fix works and also I needed to run ./gradlew wrapper
as @mikehardy said. I had another problem that was solved following this link
(https://stackoverflow.com/questions/53709282/cannot-add-task-wrapper-as-a-task-with-that-name-already-exists)
No works!
Most helpful comment
to anyone struggling to upgrade to Gradle 5.0 in a React Native project like I did:
android/gradle/gradle-wrapper.properties
: