aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.11k forks source link

Can not build React Native app on Android any more since package upgrade - error "local variable mReactInstanceManager is accessed from within inner class; needs to be declared final" #9274

Closed the-smart-home-maker closed 2 years ago

the-smart-home-maker commented 2 years ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Analytics, Push Notifications

Amplify Categories

analytics, notifications

Environment information

``` # Put output below this line System: OS: macOS 12.0.1 CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz Memory: 421.47 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.10.0 - /usr/local/bin/node Yarn: 1.22.11 - /usr/local/bin/yarn npm: 7.24.0 - /usr/local/bin/npm Watchman: 2021.09.13.00 - /usr/local/bin/watchman Browsers: Chrome: 95.0.4638.69 Safari: 15.1 npmPackages: @aws-amplify/pushnotification: ^4.3.5 => 4.3.5 @babel/core: ^7.12.9 => 7.16.0 @babel/preset-env: ^7.11.0 => 7.16.4 @babel/runtime: ^7.12.5 => 7.16.3 @gorhom/bottom-sheet: ^4 => 4.1.4 @nartc/react-native-barcode-mask: ^1.2.0 => 1.2.0 @react-native-async-storage/async-storage: ^1.15.5 => 1.15.11 @react-native-community/checkbox: ^0.5.5 => 0.5.9 @react-native-community/eslint-config: ^2.0.0 => 2.0.0 @react-native-community/image-editor: ^2.3.0 => 2.3.0 @react-native-community/masked-view: ^0.1.10 => 0.1.11 @react-native-community/netinfo: ^6.0.0 => 6.2.1 @react-native-community/picker: ^1.8.1 => 1.8.1 @react-native-community/push-notification-ios: ^1.10.1 => 1.10.1 (1.0.3) @react-native-community/toolbar-android: ^0.1.0-rc.2 => 0.1.0-rc.2 @react-native-community/viewpager: ^5.0.11 => 5.0.11 (2.0.2) @react-navigation/bottom-tabs: ^5.5.2 => 5.11.15 @react-navigation/devtools: ^6.0.1 => 6.0.4 @react-navigation/drawer: 5.12.9 => 5.12.9 @react-navigation/native: ^5.1.7 => 5.9.8 @react-navigation/stack: ^5.2.14 => 5.14.9 @sentry/react-native: 3.2.1 => 3.2.1 HelloWorld: 0.0.1 amazon-cognito-identity-js: ^5.0.2 => 5.2.3 aws-amplify: ^4.3.8 => 4.3.8 aws-amplify-react-native: ^5.0.1 => 5.0.5 axios: ^0.20.0 => 0.20.0 (0.21.4) babel-eslint: ^10.1.0 => 10.1.0 babel-jest: ^26.6.3 => 26.6.3 babel-plugin-transform-remove-console: ^6.9.4 => 6.9.4 eslint: ^7.14.0 => 7.32.0 eslint-plugin-react: ^7.19.0 => 7.27.1 eslint-plugin-react-native: ^3.8.1 => 3.11.0 hermes-inspector-msggen: 1.0.0 husky: ^0.13.4 => 0.13.4 intl: ^1.2.5 => 1.2.5 jest: ^26.6.3 => 26.6.3 lodash: ^4.17.20 => 4.17.21 metro-react-native-babel-preset: ^0.64.0 => 0.64.0 moment: ^2.29.1 => 2.29.1 native-base: ^2.13.12 => 2.15.2 object-hash: ^2.2.0 => 2.2.0 react: 17.0.2 => 17.0.2 react-native: 0.64.2 => 0.64.2 react-native-app-intro-slider: ^4.0.4 => 4.0.4 react-native-autocomplete-input: ^4.1.0 => 4.2.0 react-native-camera: ^3.23.1 => 3.44.3 react-native-circle-slider: ^2.7.0 => 2.9.0 react-native-codegen: ^0.0.7 => 0.0.7 (0.0.6) react-native-collapsible: ^1.6.0 => 1.6.0 react-native-date-picker: ^3.2.3 => 3.4.3 react-native-dialog-input: ^1.0.8 => 1.0.8 react-native-dropdown-picker: ^3.0.4 => 3.8.3 react-native-elements: ^2.0.2 => 2.3.2 react-native-flipper: ^0.107.0 => 0.107.0 react-native-geolocation-service: ^5.0.0 => 5.2.0 react-native-gesture-handler: ^1.10.3 => 1.10.3 react-native-image-base64: ^0.1.4 => 0.1.4 react-native-image-picker: ^4.2.0 => 4.3.0 react-native-image-resizer: ^1.4.2 => 1.4.5 react-native-in-app-notification: ^3.1.0 => 3.2.0 react-native-interactable: ^2.0.1 => 2.0.1 react-native-keychain: ^6.0.0 => 6.2.0 react-native-languages: ^3.0.2 => 3.0.2 react-native-localization: ^2.1.6 => 2.1.7 react-native-localize: ^1.4.0 => 1.4.3 react-native-modal: ^11.5.6 => 11.10.0 react-native-picker-select: ^8.0.4 => 8.0.4 react-native-popup-menu: ^0.15.9 => 0.15.11 react-native-reanimated: ^2.0.0 => 2.2.4 react-native-safe-area-context: ^3.1.9 => 3.3.2 react-native-screens: ^2.7.0 => 2.18.1 react-native-scrollable-tab-view: ^1.0.0 => 1.0.0 react-native-side-menu-updated: ^1.3.2 => 1.3.2 react-native-snap-carousel: ^3.9.1 => 3.9.1 react-native-splash-screen: ^3.2.0 => 3.2.0 react-native-status-bar-height: ^2.6.0 => 2.6.0 react-native-svg: ^12.1.0 => 12.1.1 react-native-text-ticker: ^1.12.0 => 1.14.0 react-native-toast-message: ^1.4.9 => 1.6.0 react-native-user-avatar: ^1.0.7 => 1.0.7 react-native-vector-icons: ^6.6.0 => 6.7.0 (7.1.0) react-native-version-info: ^1.1.0 => 1.1.1 react-native-webview: ^10.7.0 => 10.10.2 react-redux: ^7.2.0 => 7.2.6 react-test-renderer: 17.0.1 => 17.0.1 redux: ^4.0.5 => 4.1.2 redux-actions: ^2.6.5 => 2.6.5 redux-devtools-extension: ^2.13.8 => 2.13.9 redux-flipper: ^2.0.0 => 2.0.1 redux-persist: ^6.0.0 => 6.0.0 redux-persist/integration/react: undefined () redux-promise: ^0.6.0 => 0.6.0 redux-thunk: ^2.3.0 => 2.4.0 victory-native: ^35.0.0 => 35.5.5 npmGlobalPackages: @aws-amplify/cli: 4.32.0 detox-cli: 18.20.1 npm: 7.24.0 react-native-cli: 2.0.1 serverless: 2.10.0 ```

Describe the bug

After upgrading my packages with yarn upgrade, I am not able to build my React Native app on Android any more - I am receiving the following build error which seems to be caused by the aws-amplify/pushnotification package:

/node_modules/@aws-amplify/pushnotification/android/src/main/java/com/amazonaws/amplify/pushnotification/RNPushNotificationMessagingService.java:199: error: local variable mReactInstanceManager is accessed from within inner class; needs to be declared final
                            mReactInstanceManager.removeReactInstanceEventListener(this);
                            ^
Note: /Users/dani/Coding/smopp/smopp-app/node_modules/@aws-amplify/pushnotification/android/src/main/java/com/amazonaws/amplify/pushnotification/modules/RNPushNotificationHelper.java uses or overrides a deprecated API.

Expected behavior

Build should work without an error message

Reproduction steps

Install the aws-amplify packages in the following versions:

├─ @aws-amplify/pushnotification@4.3.5 ├─ @react-native-community/push-notification-ios@1.10.1 └─ aws-amplify@4.3.8

Then try to build on Android

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

const awsmobile = {
    "aws_project_region": "eu-west-1",
    "aws_cognito_identity_pool_id": "eu-west-1:XXXXXXX",
    "aws_cognito_region": "eu-west-1",
    "aws_user_pools_id": "eu-west-1_XXXXXXX",
    "aws_user_pools_web_client_id": "XXXXXXX",
    "oauth": {},
    "aws_mobile_analytics_app_id": "9fd3eacf79a3478a8887f4944b680709",
    "aws_mobile_analytics_app_region": "eu-west-1"
};

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

dylan-westbury commented 2 years ago

Also getting

node_modules/@aws-amplify/pushnotification/android/src/main/java/com/amazonaws/amplify/pushnotification/RNPushNotificationMessagingService.java:199: error: local variable mReactInstanceManager is accessed from within inner class; needs to be declared final
                            mReactInstanceManager.removeReactInstanceEventListener(this);

Temporary fix to allow android build

in file node_modules/@aws-amplify/pushnotification/android/src/main/java/com/amazonaws/amplify/pushnotification/RNPushNotificationMessagingService.java

Add final to line 74 & 189.

ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();

Changes to

final ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();

ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();

Changes to

final ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();

the-smart-home-maker commented 2 years ago

Hi @dylan-westbury,

thank you! I can confirm that this quick fix works and allows me to build again. But I think this should be integrated into the master branch as well.

Best, the_smart_home_maker

Samaritan1011001 commented 2 years ago

Hi @the-smart-home-maker, thanks for opening the issue. I was not able to reproduce it. Can you please tell me which react-native version you are using?

dylan-westbury commented 2 years ago

@Samaritan1011001 0.63.4 for us

the-smart-home-maker commented 2 years ago

@Samaritan1011001 I am using react-native 0.64.2

the-smart-home-maker commented 2 years ago

@Samaritan1011001 same issue occured with react-native 0.66.3 (I had just upgraded)

Samaritan1011001 commented 2 years ago

@the-smart-home-maker Thank you for the info. Please try the latest aws-amplify version and let me know if that solved the issue. Thanks!

the-smart-home-maker commented 2 years ago

Hi @Samaritan1011001,

I tried with yarn upgrade aws-amplify, but the problem persists. Do I have to specify a specific version number?

Best, @the-smart-home-maker

Samaritan1011001 commented 2 years ago

Hi @the-smart-home-maker. Apologies. You should upgrade the @aws-amplify/pushnotification package to 4.3.9 for the fix. Nothing to do with aws-amplify

the-smart-home-maker commented 2 years ago

Hi @Samaritan1011001 yes, you are right. Now that I have upgraded @aws-amplify/pushnotification, the problem seems to be solved. Great, thanks!

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.