invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.63k stars 2.2k forks source link

[Android] Notifications do not play sound on android 10 #3243

Closed D3vlin closed 4 years ago

D3vlin commented 4 years ago

Issue

I currently have an application in playstore, but when my users who use Android 10 update the version, they report that notifications stop playing sound.

I have tried several things to find the problem.

And so far, the only thing that works is for users to erase the application data and restart their device so that notifications work correctly.

I have also used the adb logcat command to check the emulator log to see what happens when the notification should be displayed and the sound played.

I have found the following exception, this error is reproduced both when I try to reproduce a custom sound or the default sound.

Captura_de_Pantalla_2020-02-25_a_la_s__8 45 24_a _m

Once the application data has been erased and the device is restarted, the error disappears and the sound is reprimanded normally.


Project Files

Javascript

Click To Expand

#### `package.json`: ```json # N/A ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ``` ### iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // N/A ```

--- ### Android
Click To Expand

#### Have you converted to AndroidX? - [ x ] my application is an AndroidX application? - [ x ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ x ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy buildscript { repositories { mavenCentral() maven { url "https://jitpack.io" } maven { url 'https://maven.google.com' } maven { url "$rootDir/../node_modules/react-native/android" } maven { url 'https://maven.fabric.io/public' } google() jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } } dependencies { classpath 'com.android.tools.build:gradle:3.3.0' classpath 'com.google.gms:google-services:3.2.1' classpath 'io.fabric.tools:gradle:1.25.4' classpath 'com.google.firebase:firebase-plugins:1.1.4' } } allprojects { repositories { mavenLocal() maven { url "$rootDir/../node_modules/react-native/android" } maven { url "https://jitpack.io" } maven { url 'https://maven.google.com/' } google() jcenter() maven { url "$rootDir/../node_modules/jsc-android/dist" } } } subprojects { afterEvaluate {project -> if (project.hasProperty("android")) { android { compileSdkVersion 28 buildToolsVersion "28.0.3" } } } } ``` #### `android/app/build.gradle`: ```groovy apply plugin: "com.android.application" apply plugin: 'io.fabric' apply plugin: "com.google.firebase.firebase-perf" import com.android.build.OutputFile project.ext.react = [ entryFile: "index.android.js" // was index.js" ] apply from: "../../node_modules/react-native/react.gradle" apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = false /** * General android variables, also used in AndroidManifest */ def MIN_SDK_VERSION = 16 def TARGET_SDK_VERSION = 28 def VERSION_CODE = 85 def VERSION_NAME = "0.2.18" def SUPPORT_LIB_VERSION = "28.0.0" def GOOGLE_PLAY_SERVICES_VERSION = "12.0.1" def GOOGLE_PLAY_SERVICES_VISION_VERSION = "15.0.2" android { defaultConfig { applicationId "com.myProject" minSdkVersion MIN_SDK_VERSION targetSdkVersion TARGET_SDK_VERSION versionCode VERSION_CODE versionName VERSION_NAME ndk { abiFilters "armeabi-v7a", 'arm64-v8a', "x86", 'x86_64' } multiDexEnabled = true manifestPlaceholders = [ minSdkVersion: MIN_SDK_VERSION, targetSdkVersion: TARGET_SDK_VERSION, versionCode: VERSION_CODE, versionName: VERSION_NAME ] missingDimensionStrategy 'react-native-camera', 'general', 'mlkit' } signingConfigs { release { if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) { storeFile file(MYAPP_RELEASE_STORE_FILE) storePassword MYAPP_RELEASE_STORE_PASSWORD keyAlias MYAPP_RELEASE_KEY_ALIAS keyPassword MYAPP_RELEASE_KEY_PASSWORD } } } dexOptions { javaMaxHeapSize "4g" incremental true } flavorDimensions "react-native-camera" productFlavors { general { dimension "react-native-camera" } mlkit { dimension "react-native-camera" } } sourceSets { main { java.srcDirs = ['src/main/java'] } general { java.srcDirs = ['src/general/java'] } mlkit { java.srcDirs = ['src/mlkit/java'] } } lintOptions { abortOnError false warning 'InvalidPackage' } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", 'arm64-v8a', "x86", 'x86_64' } } buildTypes { release { proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" signingConfig signingConfigs.release } } // applicationVariants are e.g. debug, release applicationVariants.all { variant -> variant.outputs.each { output -> // For each separate APK per architecture, set a unique version code as described here: // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits def versionCodes = ["armeabi-v7a":1, "x86":2, 'arm64-v8a':3, 'x86_64':4] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } packagingOptions { exclude 'META-INF/androidx.exifinterface_exifinterface.version' pickFirst '**/libjsc.so' pickFirst '**/libc++_shared.so' } } dependencies { implementation project(':react-native-vector-icons') implementation project(':@react-native-community_netinfo') implementation "org.webkit:android-jsc:r241213" implementation project(':react-native-camera') implementation "com.google.zxing:core:3.3.3" implementation "com.drewnoakes:metadata-extractor:2.11.0" generalImplementation "com.google.android.gms:play-services-vision:$GOOGLE_PLAY_SERVICES_VISION_VERSION" implementation "com.android.support:exifinterface:$SUPPORT_LIB_VERSION" implementation "com.android.support:support-annotations:$SUPPORT_LIB_VERSION" implementation "com.android.support:support-v4:$SUPPORT_LIB_VERSION" mlkitImplementation "com.google.firebase:firebase-ml-vision:19.0.3" mlkitImplementation "com.google.firebase:firebase-ml-vision-face-model:17.0.2" implementation "androidx.multidex:multidex:2.0.0" implementation 'com.android.support:support-core-utils:28.0.0' implementation project(':react-native-version-number') implementation project(':react-native-share') implementation project(':react-native-sound') implementation project(':realm') implementation project(':react-native-fbsdk') implementation (project(':react-native-firebase')){exclude group: "com.google.android.gms"} implementation project(':react-native-branch') implementation 'com.android.installreferrer:installreferrer:1.0' implementation project(':react-native-mixpanel') implementation "com.android.support:appcompat-v7:25.0.1" implementation ("com.facebook.react:react-native:+") implementation ('com.google.android.gms:play-services-gcm:15.0.1') { force = true; } implementation 'com.google.firebase:firebase-ads:15.0.0' implementation "com.google.firebase:firebase-analytics:15.0.2" implementation ('com.google.firebase:firebase-core:16.0.1'){force = true} implementation ('com.google.firebase:firebase-database:16.0.1'){ force = true; } implementation ('com.google.firebase:firebase-auth:16.0.4'){ force = true; } implementation ('com.google.firebase:firebase-messaging:17.3.3'){ force = true; } implementation ('com.google.android.gms:play-services-tagmanager-v4-impl:16.0.1') implementation 'com.crashlytics.sdk.android:crashlytics:2.9.3' implementation "com.google.firebase:firebase-perf:16.0.0" implementation 'com.google.firebase:firebase-inappmessaging-display:17.0.0' implementation ('com.google.android.gms:play-services-analytics:16.0.6') {exclude group: "com.google.android.gms"} implementation 'com.google.firebase:firebase-storage:16.0.5' implementation 'com.facebook.android:facebook-android-sdk:[4,5)' } // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' } apply plugin: 'com.google.gms.google-services' ``` #### `android/settings.gradle`: ```groovy rootProject.name = 'myProject' include ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android') include ':@react-native-community_netinfo' project(':@react-native-community_netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android') include ':react-native-camera' project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') include ':react-native-firebase' project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android') include ':react-native-version-number' project(':react-native-version-number').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-version-number/android') include ':react-native-share' project(':react-native-share').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-share/android') include ':react-native-sound' project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android') include ':realm' project(':realm').projectDir = new File(rootProject.projectDir, '../node_modules/realm/android') include ':react-native-fbsdk' project(':react-native-fbsdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk/android') include ':react-native-branch' project(':react-native-branch').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-branch/android') include ':react-native-mixpanel' project(':react-native-mixpanel').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mixpanel/android') include ':app' ``` #### `MainApplication.java`: ```java package com.myproject; import android.app.Application; import android.content.Context; import androidx.multidex.MultiDex; import com.facebook.FacebookSdk; import com.facebook.CallbackManager; import com.facebook.appevents.AppEventsLogger; import com.facebook.react.ReactApplication; import com.oblador.vectoricons.VectorIconsPackage; import com.reactnativecommunity.netinfo.NetInfoPackage; import org.reactnative.camera.RNCameraPackage; import io.invertase.firebase.RNFirebasePackage; import com.facebook.reactnative.androidsdk.FBSDKPackage; import com.apsl.versionnumber.RNVersionNumberPackage; import cl.json.RNSharePackage; import com.zmxv.RNSound.RNSoundPackage; import io.realm.react.RealmReactPackage; import com.kevinejohn.RNMixpanel.RNMixpanel; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; import com.facebook.soloader.SoLoader; import io.invertase.firebase.admob.RNFirebaseAdMobPackage; //Firebase AdMob import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage; // Firebase Analytics import io.invertase.firebase.auth.RNFirebaseAuthPackage; // Firebase Auth import io.invertase.firebase.database.RNFirebaseDatabasePackage; // Firebase Realtime Database import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage; import io.invertase.firebase.storage.RNFirebaseStoragePackage; import io.invertase.firebase.fabric.crashlytics.RNFirebaseCrashlyticsPackage; import io.invertase.firebase.perf.RNFirebasePerformancePackage; import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; // import Branch and RNBranch import io.branch.rnbranch.RNBranchPackage; import io.branch.rnbranch.RNBranchModule; import java.util.Arrays; import java.util.List; public class MainApplication extends Application implements ReactApplication { private static CallbackManager mCallbackManager = CallbackManager.Factory.create(); protected static CallbackManager getCallbackManager() { return mCallbackManager; } @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } @Override public void onCreate() { super.onCreate(); FacebookSdk.sdkInitialize(getApplicationContext()); // If you want to use AppEventsLogger to log events. AppEventsLogger.activateApp(this); SoLoader.init(this, /* native exopackage */ false); RNBranchModule.getAutoInstance(this); } private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List getPackages() { return Arrays.asList( new MainReactPackage(), new VectorIconsPackage(), new NetInfoPackage(), new RNCameraPackage(), new RNFirebasePackage(), new RNVersionNumberPackage(), new RNSharePackage(), new RNSoundPackage(), new RealmReactPackage(), new FBSDKPackage(), new RNBranchPackage(), new RNMixpanel(), // add/remove these packages as appropriate new RNFirebaseAdMobPackage(), new RNFirebaseAnalyticsPackage(), new RNFirebaseAuthPackage(), new RNFirebaseDatabasePackage(), new RNFirebaseCrashlyticsPackage(), new RNFirebasePerformancePackage(), new RNFirebaseMessagingPackage(), new RNFirebaseNotificationsPackage(), new RNFirebaseStoragePackage() ); } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } } ``` #### `AndroidManifest.xml`: ```xml ```

--- ## Environment
Click To Expand

**`react-native info` output:** ``` OS: macOS 10.15.3 CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz Memory: 33.46 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.0.0 - ~/.nvm/versions/node/v10.0.0/bin/node npm: 5.6.0 - ~/.nvm/versions/node/v10.0.0/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 Android SDK: API Levels: 28, 29 Build Tools: 28.0.3, 29.0.3 System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom IDEs: Android Studio: 3.5 AI-191.8026.42.35.6010548 Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild npmPackages: react: ^16.9.0 => 16.9.0 react-native: ^0.61.5 => 0.61.5 ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [ x ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `5.1.1` - **`Firebase` module(s) you're using that has the issue:** - `Notifications` - **Are you using `TypeScript`?** - `Y/N` & `VERSION`

--- Think `react-native-firebase` is great? Please consider supporting all of the project maintainers and contributors by donating via our [Open Collective](https://opencollective.com/react-native-firebase/donate) where all contributors can submit expenses. [[Learn More]](https://invertase.io/oss/react-native-firebase/contributing/donations-expenses) - 👉 Check out [`React Native Firebase`](https://twitter.com/rnfirebase) and [`Invertase`](https://twitter.com/invertaseio) on Twitter for updates on the library.
suseendhar commented 4 years ago

@D3vlin you can refer this https://stackoverflow.com/questions/54796492/android-notification-channel-sounds-stop-working-when-using-sound-uris-that-refe it might be helpful for you

D3vlin commented 4 years ago

@suseendhar, I have tried the solutions they propose, but the error persists. I can't think of anything else that could be the cause of the bug. Anything I can try?

suseendhar commented 4 years ago

@D3vlin have you changed your channel id and tried? because the issue wont fix if you just simply change the raw path alone,need to change the channel id also . I faced the exact same issue and by changing channel id and refer the raw file directly fix for me

D3vlin commented 4 years ago

How can I change the folder/file path if I'm directly using the React Native Firebase lib to create the channel as follows:

import { Platform } from 'react-native';
import Firebase from 'react-native-firebase';

const MP3_SOUND = 'pillsshaking';
const VIBRATION_PATTERN = [0, 800, 200, 800, 200, 800];
const CHANNEL_ID = 'test_channel';
const CHANNEL_NAME = 'test';

const FB_NOTIFICATIONS = Firebase.notifications;

class NotificationService {

    static initAndroidChannel() {

        if (Platform.OS == 'android' && Platform.Version >= 26) {
            let channel = new FB_NOTIFICATIONS.Android.Channel(CHANNEL_ID, CHANNEL_NAME, FB_NOTIFICATIONS.Android.Importance.Max)
                .setDescription("Test notification channel")
                .setSound(MP3_SOUND)
                .enableVibration(true)
                .setVibrationPattern(VIBRATION_PATTERN)
                .setShowBadge(false); 

            FB_NOTIFICATIONS().android.createChannel(channel);
        } else {
            // Do nothing
        }
    }
}
suseendhar commented 4 years ago

@D3vlin i have used in native android studio not in react native but try to change your "test_channel" to someother name and check

D3vlin commented 4 years ago

@suseendhar, Yes I tried.

I have also noticed that when I restart the emulator, the sound of the application sounds normally again without the need to erase its data.

We will test how it behaves in physical devices. It may be an emulator bug that I use.

stale[bot] commented 4 years ago

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.