我有一个有趣的问题。我有一个 react native expo 项目,最低限度,所以它不使用任何 expo 服务器和所有服务器,它的纯 react native 项目包含在 react-native-unimodules 中。所以现在我想在其中集成 react-native-firebase,IOS 是成功的,但在 android 上我面临多个问题,
让我们从头开始。
1:首先我尝试做react-native link firebase...
,然后我重新检查所有链接是否已完成,例如检查 settings.gradle、MainApplicaiton.java 等,一旦一切就绪,运行 react-native run-android
后.第一个问题我明白了
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.
好的,所以我研究了一下,在我看到的任何地方,都有一个解决方案,升级 gradle。
所以我将gradle升级到5.1.1,甚至尝试了其他几个,升级后我得到的错误是。
Cannot add task 'wrapper' as a task with that name already exists
所以我再次研究了一下,然后我尝试删除它或添加这个解决方案
Cannot add task 'wrapper' as a task with that name already exists
它有效(有点),现在我有另一个错误。
在这一切之后,
当我尝试编译时,我得到了这个。
ERROR: Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
我也尝试解决这个问题,添加
googlePlayServices, firebase
在我的分机等。但是没有任何效果。
所以现在我被困住了,将 react-native-firebase 与 unimodules 集成起来非常重要。
帮助将不胜感激。
我将在这里发布一些关于我的应用程序的信息,这个阶段将在我尝试集成任何东西之前。
安卓/build.gradle
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.5.2'
// 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")
//}
wrapper {
gradleVersion = '5.1'
distributionUrl = distributionUrl.replace("bin", "all")
}
我的依赖
dependencies {
implementation project(':@react-native-firebase_app')
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(':@sentry-react-native')
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()
}
react 原生信息
React Native Environment Info:
System:
OS: macOS 10.15.1
CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
Memory: 86.16 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 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5791312
Xcode: 11.2.1/11B53 - /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
最佳答案
由于您使用 expo bare-minimum 创建了项目,因此您的 react-native 版本是 0.59.10。现在这会给 RNFirebase 带来这种困难。我知道这一点,因为几天前我在同一个坑洼里。我的建议如下,现在将为您创造奇迹。
MainApplictaion.java
中添加一些准确的行文件。但请确保它可以完成。我已经做了。阅读它的文档,以便将其成功添加到您的项目中。 apply from: '../node_modules/react-native-unimodules/gradle.groovy'
includeUnimodulesProjects()
就在 rootProject.name =""
行之后classpath("com.android.tools.build:gradle:3.4.1")
classpath('com.google.gms:google-services:4.2.0')
在 dependencies{}
apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
addUnimodulesDependencies()
就在 implementation "com.facebook.react:react-native:+"
之后I know this is lot of work but this need to be done in order to get it to work. A lot of RN developer are suffering from this version pothole between expo - unimodules - RNFirebase.
关于android - react 原生 firebase 与 expo 裸应用程序的集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58862324/