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

react-native-push-notification issue on building app

有人可以帮忙 me.I 我现在正在开发一个应用程序,它可以在我的几个小时内运行,但现在我收到一条错误消息。 我也尝试更新不同版本的 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 all
  2. ./gradlew :app:bundleRelease
  3. ./gradlew clean
  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。这解决了我的一个项目中的构建问题。

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

在android/app/build.gradle中,添加如下代码到dependencies:

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
}

这在另一个项目中也对我有用。如果其中任何一个对您有用,请尝试一下并提及!