关于构建应用程序的 react-native-push-notification 问题

问题描述

有人可以帮助我吗。我现在正在开发一个应用程序,它可以在我的几个小时内运行,但现在我收到一条错误消息。 我还尝试在不同版本上更新 EXT{}

"react": "16.13.1","react-native": "0.63.2","react-native-push-notification": "^7.2.3",ext {
                   googlePlayServicesversion = "+" // default: "+"
                firebaseMessagingVersion = "+" // default: "+"
                buildToolsversion = "28.0.3"
                minSdkVersion = 16
                compileSdkVersion = 29
                targetSdkVersion = 29
                 supportLibVersion = "23.1.1"
            }
     dependencies {
            classpath("com.android.tools.build:gradle:3.5.3")
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }

我试过了

  1. ./gradlew assembleRelease --warning-mode 全部
  2. ./gradlew :app:bundleRelease
  3. ./gradlew 干净
  4. 同时删除 node_modules 并重新安装

但还是一样

这里是错误

> Task :react-native-push-notification:compileDebugJavaWithJavac Failed

Deprecated Gradle features were used in this build,making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
118 actionable tasks: 109 executed,9 up-to-date
Note: C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\@react-native-picker\picker\android\src\main\java\com\reactnativecommunity\picker\ReactPickerManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\react-native-bluetooth-escpos-printer\android\src\main\java\cn\jystudio\bluetooth\tsc\TscCommand.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: [2] Wrote GeneratedAppGlideModule with: [com.bumptech.glide.integration.okhttp3.OkHttpLibraryGlideModule,com.dylanvann.fastimage.FastimageOkHttpProgressGlideModule]
Note: C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\react-native-fs\android\src\main\java\com\rnfs\RNFSManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotification.java:39: error: cannot find symbol
import com.google.firebase.iid.FirebaseInstanceId;
                              ^
  symbol:   class FirebaseInstanceId
  location: package com.google.firebase.iid
C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotification.java:40: error: cannot find symbol
import com.google.firebase.iid.InstanceIdResult;
                              ^
  symbol:   class InstanceIdResult
  location: package com.google.firebase.iid
C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotification.java:143: error: cannot find symbol
              .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
                                                            ^
  symbol:   class InstanceIdResult
  location: class RNPushNotification
C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotification.java:145: error: cannot find symbol
                  public void onComplete(@NonNull Task<InstanceIdResult> task) {
                                                       ^
  symbol: class InstanceIdResult
C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotification.java:142: error: cannot find symbol
      FirebaseInstanceId.getInstance().getInstanceId()
      ^
  symbol:   variable FirebaseInstanceId
  location: class RNPushNotification
C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotification.java:289: error: cannot find symbol
                  FirebaseInstanceId.getInstance().deleteInstanceId();
                  ^
  symbol: variable FirebaseInstanceId
Note: C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotificationHelper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotification.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors

FAILURE: Build Failed with an exception.

* What went wrong:
Execution Failed for task ':react-native-push-notification:compileDebugJavaWithJavac'.
> Compilation Failed; see the compiler error output for details.

* 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 59s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command Failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
Note: C:\Users\SBPC\offline_hotel\new\staff\realm-tutorial-react-native\node_modules\@react-native-picker\picker\android\src\main\java\com\reactnativecommunity\picker\ReactPickerManager.java uses or overrides a deprecated API.

解决方法

这似乎是最近影响很多开发人员的问题。我也面临同样的问题。以下解决方案对我有用。

  1. 将 react-native-push-notification 版本更改为 ^7.3.0。这解决了我的一个项目中的构建问题。

OR

  1. 进行下面提到的更改。

在 android/app/build.gradle 中,将以下代码添加到依赖项:

implementation 'com.google.firebase:firebase-messaging:21.1.0'

在 android/build.gradle 中,进行以下更改:

buildscript {
  ext {
    buildToolsVersion = "28.0.3"
    ...rest of your code
  }
  ...rest of your code
}

这在另一个项目中也对我有用。试一试,并提及其中任何一项是否适合您!