React Native中:aws-amplify_rtn-push-notification:compileDebugKotlin编译失败求助
问题描述
使用 aws-amplify 6.0.9、@aws-amplify/rtn-push-notification 1.1.11 配合 Amplify Pinpoint 实现推送通知,已按官方Android步骤配置并集成Firebase,但启动应用时出现编译失败,错误及环境信息如下:
环境信息
OS: macOS 13.3 CPU: (8) x64 Apple M1 Memory: 37.31 MB / 8.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.17.1 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.8.1 - ~/Documents/nueva-version/facebook-signin/node_modules/.bin/npm Watchman: 2023.05.08.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9014738 Xcode: 14.2/14C18 - /usr/bin/xcodebuild Languages: Java: 11.0.16.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.7 => 0.71.7 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found
错误日志
FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * 问题所在: Execution failed for task ':aws-amplify_rtn-push-notification:compileDebugKotlin'. > Compilation error. See log for more details * 建议尝试: > 使用--stacktrace选项获取堆栈跟踪。 > 使用--info或--debug选项获取更多日志输出。 > 使用--scan选项获取完整分析信息。 ============================================================================== 2: Task failed with an exception. ----------- * 问题所在: java.lang.StackOverflowError (无错误消息) * 建议尝试: > 使用--stacktrace选项获取堆栈跟踪。 > 使用--info或--debug选项获取更多日志输出。 > 使用--scan选项获取完整分析信息。 ============================================================================== * 获取更多帮助请访问https://help.gradle.org BUILD FAILED in 1m 30s at makeError (/Users/PUSH-NOTIFICATION-ANDROID/node_modules/execa/index.js:174:9) at /Users/PUSH-NOTIFICATION-ANDROID/node_modules/execa/index.js:278:16 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async runOnAllDevices (/Users/PUSH-NOTIFICATION-ANDROID/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:82:7) at async Command.handleAction (/Users/PUSH-NOTIFICATION-ANDROID/node_modules/@react-native-community/cli/build/index.js:108:9)
可能的解决方案
1. 匹配Kotlin版本兼容性
@aws-amplify/rtn-push-notification 对Kotlin版本有特定要求,React Native 0.71.x默认版本可能不兼容:
- 打开项目根目录的
android/build.gradle,在buildscript的ext块中指定适配的Kotlin版本(推荐1.8.20及以上):buildscript { ext { kotlinVersion = "1.8.20" // 其他配置项... } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" // 其他依赖... } }
2. 增加Gradle堆内存
StackOverflowError 大多是Gradle堆内存不足导致,修改配置提升内存:
- 打开
android/gradle.properties,添加或修改以下配置:org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
3. 清理缓存并重新构建
缓存冲突可能引发编译错误,执行以下步骤:
- 进入android目录清理项目:
cd android && ./gradlew clean - 删除本地依赖缓存:
rm -rf node_modules yarn.lock package-lock.json - 重新安装依赖:
yarn install或npm install - 重新构建应用:
npx react-native run-android
4. 检查Firebase配置完整性
确保Firebase配置文件和插件配置正确:
- 确认
google-services.json已放置在android/app目录下 - 检查
android/build.gradle中已添加Google服务插件依赖:dependencies { classpath 'com.google.gms:google-services:4.3.15' // 其他依赖... } - 确认
android/app/build.gradle末尾已应用插件:apply plugin: 'com.google.gms.google-services'
5. 升级Amplify依赖版本
尝试升级到最新兼容版本,避免版本不兼容问题:
- 将
@aws-amplify/rtn-push-notification升级到最新稳定版 - 确保
aws-amplify版本与推送插件版本匹配
内容的提问来源于stack exchange,提问作者edgar alfaro
相关产品推荐
相关产品推荐

