wix / react-native-notifications

React Native Notifications
MIT License
3.25k stars 765 forks source link

NotificationService: Indirect notification activity start (trampoline) from com.xxx.xxx blocked #884

Closed oliviermtl closed 2 years ago

oliviermtl commented 2 years ago

On Android 12, when app is killed or in background, tapping the notification does not open the app. Adb logcat shows : NotificationService: Indirect notification activity start (trampoline) from com.xxx.xxx blocked Turning off _NOTIFICATION_TRAMPOLINEBLOCK in App Compatibility Changes makes the app open after tapping the notification.

"react-native-notifications": "^4.3.1" "react-native": "0.68.2"

  "dependencies": {
    "@apollo/client": "^3.3.19",
    "@datadog/mobile-react-native": "^1.0.0-rc9",
    "@datadog/mobile-react-navigation": "^1.0.0-rc9",
    "@formatjs/intl-datetimeformat": "^6.0.2",
    "@formatjs/intl-getcanonicallocales": "^2.0.2",
    "@formatjs/intl-locale": "^3.0.2",
    "@formatjs/intl-numberformat": "^8.0.2",
    "@formatjs/intl-pluralrules": "^5.0.2",
    "@gorhom/bottom-sheet": "^4.2.2",
    "@mapbox/polyline": "^1.1.1",
    "@react-native-async-storage/async-storage": "^1.17.3",
    "@react-native-community/blur": "^3.6.0",
    "@react-native-community/clipboard": "^1.5.1",
    "@react-native-community/datetimepicker": "^3.4.7",
    "@react-native-community/geolocation": "^2.0.2",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-native-community/progress-bar-android": "^1.0.4",
    "@react-native-firebase/analytics": "11.5.0",
    "@react-native-firebase/app": "11.5.0",
    "@react-native-firebase/iid": "^11.5.0",
    "@react-navigation/bottom-tabs": "^6.3.1",
    "@react-navigation/elements": "^1.3.3",
    "@react-navigation/material-top-tabs": "^6.2.1",
    "@react-navigation/native": "^6.0.10",
    "@react-navigation/stack": "^6.2.1",
    "@rnhooks/keyboard": "^1.1.0",
    "@sayem314/react-native-keep-awake": "^1.1.0",
    "@stripe/stripe-react-native": "^0.12.0",
    "card-validator": "^8.1.0",
    "country-telephone-data": "^0.6.2",
    "date-fns": "2.28.0",
    "date-fns-tz": "1.3.4",
    "detox": "19.6.0",
    "email-validator": "^2.0.4",
    "fluxible-js": "^6.0.8",
    "graphql": "^15.5.0",
    "i18n-js": "^3.8.0",
    "libphonenumber-js": "^1.9.17",
    "lodash": "^4.17.21",
    "lodasync": "^1.0.7",
    "lottie-ios": "3.2.3",
    "lottie-react-native": "^5.0.1",
    "password-validator": "^5.0.3",
    "patch-package": "^6.4.7",
    "paynowqr": "^1.1.2",
    "postinstall-postinstall": "^2.1.0",
    "qs": "^6.10.1",
    "react": "17.0.2",
    "react-airplay": "^1.1.2",
    "react-countdown": "^2.3.2",
    "react-dom": "^17.0.2",
    "react-fluxible": "^6.0.4",
    "react-interval-hook": "^1.1.3",
    "react-native": "0.68.2",
    "react-native-appstate-hook": "^1.0.5",
    "react-native-avoid-softinput": "^2.4.4",
    "react-native-background-fetch": "^4.1.0",
    "react-native-background-geolocation": "^4.8.0",
    "react-native-blob-util": "^0.13.16",
    "react-native-calendars": "^1.1284.0",
    "react-native-config": "^1.4.5",
    "react-native-country-picker-modal": "^2.0.0",
    "react-native-device-info": "^8.7.1",
    "react-native-document-picker": "^6.0.4",
    "react-native-fast-image": "^8.5.11",
    "react-native-flags": "^1.0.0",
    "react-native-gesture-handler": "^2.3.2",
    "react-native-headphone-detection": "^1.3.0",
    "react-native-hyperlink": "^0.0.19",
    "react-native-image-crop-picker": "^0.37.3",
    "react-native-image-pan-zoom": "^2.1.12",
    "react-native-inappbrowser-reborn": "^3.6.3",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-loading-spinner-overlay": "^2.0.0",
    "react-native-localize": "^2.1.5",
    "react-native-maps": "^0.30.1",
    "react-native-modal": "^11.10.0",
    "react-native-modal-datetime-picker": "^9.2.3",
    "react-native-notifications": "^4.3.1",
    "react-native-pager-view": "^5.4.15",
    "react-native-parsed-text": "^0.0.22",
    "react-native-permissions": "^3.3.1",
    "react-native-picker-scrollview": "^1.0.1",
    "react-native-qrcode-svg": "^6.1.1",
    "react-native-reanimated": "^2.8.0",
    "react-native-safe-area-context": "^4.2.4",
    "react-native-screens": "^3.13.1",
    "react-native-snap-carousel": "^4.0.0-beta.6",
    "react-native-svg": "^12.1.1",
    "react-native-swipe-gestures": "^1.0.5",
    "react-native-tab-view": "^3.1.1",
    "react-native-toast-message": "^2.1.5",
    "react-native-twilio-programmable-voice": "https://github.com/hoxfon/react-native-twilio-programmable-voice#feat/twilio-android-sdk-5",
    "react-native-twilio-video-webrtc": "2.1.0",
    "react-native-version-check": "^3.4.2",
    "react-native-view-pdf": "^0.13.2",
    "react-native-webview": "^11.18.2",
    "react-navigation-backhandler": "^2.0.1",
    "react-timer-hook": "^3.0.2",
    "react-use-websocket": "^3.0.0",
    "regex-escape": "^3.4.10",
    "styled-components": "^5.3.5",
    "timekeeper": "^2.2.0",
    "timezone-mock": "^1.3.2",
    "urijs": "^1.19.11",
    "use-async-effect": "^2.2.3",
    "yup": "^0.32.11"
  },

build.gradle

import org.apache.tools.ant.taskdefs.condition.Os

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        googlePlayServicesLocationVersion = "17.0.0"
        ndkVersion = "20.1.5948944"
        googlePlayServicesVersion = "+" // default: "+"
        firebaseMessagingVersion = "21.1.0"
        buildToolsVersion = "31.0.0"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
        androidXBrowser = "1.3.0"
        kotlinVersion = '1.6.0'
        appCompatVersion = "1.1.0" 

        if (System.properties['os.arch'] == "aarch64") {
            // For M1 Users we need to use the NDK 24 which added support for aarch64
            ndkVersion = "24.0.8215888"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }
    }
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.0.4")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:4.1.2")
        classpath 'com.google.gms:google-services:4.3.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        mavenCentral {
            // We don't want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup "com.facebook.react"
            }
        }

        maven {
            // Required for react-native-background-geolocation
             url("${project(':react-native-background-geolocation').projectDir}/libs")
         }
         maven {
            // Required for react-native-background-fetch
            url("${project(':react-native-background-fetch').projectDir}/libs")
         }
        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
        maven {
            // All of Detox' artifacts are provided via the npm module
            url "$rootDir/../node_modules/detox/Detox-android"
        }
    }
}

manifest `<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.xxx.xxx">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MICROPHONE" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />
<uses-feature
    android:name="android.hardware.microphone"
    android:required="false" />

<application
    android:name=".MainApplication"
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:requestLegacyExternalStorage="true"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme">
    <meta-data android:name="com.transistorsoft.locationmanager.license" android:value="@string/TRANSISTORSOFT_GEOLOCATION_APIKEY" />

    <!-- Twilio Voice -->
    <!-- [START fcm_listener] -->
    <service
        android:name="com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseMessagingService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <!-- [END fcm_listener] -->

    <receiver
        android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
        android:protectionLevel="signature"
        android:permission="com.google.android.c2dm.permission.SEND"
        tools:replace="android:protectionLevel">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </receiver>
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:exported="false"
        android:resource="@mipmap/ic_notification" />
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:exported="false"
        android:value="@string/GOOGLE_API_KEY" />

    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

    <activity
        android:name=".MainActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustPan"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
        </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

`

oliviermtl commented 2 years ago

Downgrading targetSdkVersion to 30, solves the issue, the notification is still flagged as indirect but is not blocked.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

brsaylor2 commented 2 years ago

I'm seeing this issue with v4.3.1.

stale[bot] commented 2 years ago

The issue has been closed for inactivity.

xgbn commented 2 years ago

I am also seeing this issue with 4.3.1

raphaelpare commented 2 years ago

Solved by downgrading targetSdkVersion = 31 to targetSdkVersion = 30 in build.gradle

Edit : Unfortunatly with this change in targetSdkVersion, you cannot deploy on google play store your app because it now requires at least version 31 for security reasons. A fix for this issue is highly needed

tjadliupgrade commented 1 year ago

Still seeing the issue even with 4.3.3

tsalama commented 1 year ago

Same here. Can this be reopened??

asdemura commented 1 year ago

When app is killed notification is created by firebase so we need to update firebase core library for targetSdkVersion>30. In file ./android/app/build.gradle replace implementation 'com.google.firebase:firebase-core:16.0.0' by implementation platform('com.google.firebase:firebase-bom:31.1.1') implementation 'com.google.firebase:firebase-messaging' implementation 'com.google.firebase:firebase-analytics'

./android/app/build.gradle

dependencies {
    ...
    implementation project(':react-native-notifications')
    implementation platform('com.google.firebase:firebase-bom:31.1.1')
    implementation 'com.google.firebase:firebase-messaging'
    implementation 'com.google.firebase:firebase-analytics'
}  
ginoraviola commented 1 year ago

Thank you @asdemura, I was facing the same issue and your fix did the trick 👍

quizzyDev commented 1 year ago

This seems to still be an issue with version 4.3.5 - Android push notifications do not open the app and if you look at the log cat in Android studio you see NotificationService: Indirect notification activity start (trampoline) from com.xxx.xxx blocked

@asdemura 's workaround fixes the issue for us.

vnanhtuan commented 1 year ago

Thank you @asdemura, I fixed my issue and the app works well