反应本机问题 firebase 消息传递
React native issue firebase messaging
我正在尝试将 React Native firebase 消息传递模块安装到我的项目中,以便我可以远程发送通知。
当我构建我的应用程序时 yarn android
/react-native build-android
我遇到了一个错误,过去 3 个小时我一直在尝试修复该错误。
build.gradle:
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services' // Google Services plugin
...
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation platform('com.google.firebase:firebase-bom:28.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation project(path: ":@react-native-firebase_app")
implementation project(path: ":@react-native-firebase_messaging")
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
settings.gradle:
rootProject.name = 'NerdeeMobile'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
include ':@react-native-firebase_app'
project(':@react-native-firebase_app').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/app/android')
include ':@react-native-firebase_messaging'
project(':@react-native-firebase_messaging').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/messaging/android')
MainApplication.java:
import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.ReactActivity;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import io.invertase.firebase.app.ReactNativeFirebaseAppPackage;
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage;
...
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new ReactNativeFirebaseMessagingPackage());
// return packages;
return packages;
}
Error/Output:
245 actionable tasks: 2 executed, 243 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeLibDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform classes.jar (project :@react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingWithClasspathTransform: C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar.
> Unable to read jar file C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar
> Failed to transform classes.jar (project :react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingWithClasspathTransform: C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar.
> Unable to read jar file C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeLibDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform classes.jar (project :@react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingWithClasspathTransform: C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar.
> Unable to read jar file C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar
> Failed to transform classes.jar (project :react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingWithClasspathTransform: C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar.
> Unable to read jar file C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
at makeError (C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\execa\index.js:174:9)
at C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:5)
at async Command.handleAction (C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-community\cli\build\index.js:186:9)
非常感谢任何帮助。
在 => import com.facebook.react.ReactApplication;
之后添加
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage;
删除:
packages.add(new ReactNativeFirebaseMessagingPackage());
我正在尝试将 React Native firebase 消息传递模块安装到我的项目中,以便我可以远程发送通知。
当我构建我的应用程序时 yarn android
/react-native build-android
我遇到了一个错误,过去 3 个小时我一直在尝试修复该错误。
build.gradle:
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services' // Google Services plugin
...
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation platform('com.google.firebase:firebase-bom:28.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation project(path: ":@react-native-firebase_app")
implementation project(path: ":@react-native-firebase_messaging")
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
settings.gradle:
rootProject.name = 'NerdeeMobile'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
include ':@react-native-firebase_app'
project(':@react-native-firebase_app').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/app/android')
include ':@react-native-firebase_messaging'
project(':@react-native-firebase_messaging').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/messaging/android')
MainApplication.java:
import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.ReactActivity;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import io.invertase.firebase.app.ReactNativeFirebaseAppPackage;
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage;
...
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new ReactNativeFirebaseMessagingPackage());
// return packages;
return packages;
}
Error/Output:
245 actionable tasks: 2 executed, 243 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeLibDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform classes.jar (project :@react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingWithClasspathTransform: C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar.
> Unable to read jar file C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar
> Failed to transform classes.jar (project :react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingWithClasspathTransform: C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar.
> Unable to read jar file C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeLibDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform classes.jar (project :@react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingWithClasspathTransform: C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar.
> Unable to read jar file C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar
> Failed to transform classes.jar (project :react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingWithClasspathTransform: C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar.
> Unable to read jar file C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-firebase\app\android\build\intermediates\runtime_library_classes_jar\debug\classes.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
at makeError (C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\execa\index.js:174:9)
at C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:5)
at async Command.handleAction (C:\xampp\htdocs\Projects\nerdee\NerdeeMobile\node_modules\@react-native-community\cli\build\index.js:186:9)
非常感谢任何帮助。
在 => import com.facebook.react.ReactApplication;
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage;
删除:
packages.add(new ReactNativeFirebaseMessagingPackage());