我有一个React Native版本0.60.4
应用程序,其中我已经安装了react-native-firebase
版本"^5.2.3"
。现在,当我输入react-native run-android
时,将显示以下错误:
我无法链接react-native-firebase,因为react-native 0.60.4不支持它。我尝试运行cd android && gradlew clean && cd .. && react-native run-android
,但没有运气。这是我的android / app / build.gradle:
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js",
enableHermes: false,
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion 28
compileOptions {
sourceCompatibility '1.8'
targetCompatibility '1.8'
}
defaultConfig {
applicationId "com.movitpilot"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
// minifyEnabled true
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) {
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
packagingOptions {
pickFirst '**/armeabi-v7a/libc++_shared.so'
pickFirst '**/x86/libc++_shared.so'
pickFirst '**/arm64-v8a/libc++_shared.so'
pickFirst '**/x86_64/libc++_shared.so'
pickFirst '**/x86/libjsc.so'
pickFirst '**/armeabi-v7a/libjsc.so'
}
buildToolsVersion = '28.0.3'
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
if (enableHermes) {
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
apply plugin: 'com.google.gms.google-services'
任何帮助将不胜感激。
答案 0 :(得分:0)
尝试从implementation project(':react-native-firebase')
文件中删除build.gralde
。根据新的自动链接过程,无需在app/build.gradle
中实施项目。
还要确保没有settings.gradle
中链接的模块像这样:
rootProject.name = 'MyApp'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
如果有尝试通过react-native unlink react-native-firebase
断开模块链接的操作,则如果您使用的是react-native> = 0.60
答案 1 :(得分:0)
我的解决方案是重新安装
npm i react-native-firebase@5.2.3
您需要检查react-native-firebase
文件夹中的node_modules
是否存在
答案 2 :(得分:0)
当您从 node-modules 文件夹中删除软件包或在 package.json 中错误地声明了react-native-firebase时,可能会发生这种情况。 解决此问题:
npm I react-native-firebase
。
确保您的节点模块文件夹中没有具有相同规则的重复软件包。