zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 748 forks source link

android.content.res.Resources$NotFoundException when google run the app on pre launch report #601

Open loic-lopez opened 5 years ago

loic-lopez commented 5 years ago

:beetle: Description Getting android.content.res.Resources$NotFoundException on submitting App to playstore

:beetle: Code:

import Sound from "react-native-sound"

/**
 * SoundPlayer will be the controller to handle app sounds and ringtones
 */
export class SoundPlayer implements IService {
  private errorSound: Sound
  private successSound: Sound

  @autobind
  public error(): void {
    this.errorSound.play()
  }

  public async setup(): Promise<void> {
    this.successSound = new Sound(require("./assets/popcorn.mp3"), noop)
    this.errorSound = new Sound(require("./assets/nfc_failure.mp3"), noop)
  }

  public setupForTests(successSoundMock?: any, errorSoundMock?: any): void {
    this.successSound = successSoundMock || mock
    this.errorSound = errorSoundMock || mock
  }

  @autobind
  public success(): void {
    this.successSound.play()
  }
}

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

If your problem is happening on a device, which device?

Stacktrace:

FATAL EXCEPTION: mqt_native_modules
Process: com.exorun, PID: 10341
android.content.res.Resources$NotFoundException: File res/raw/app_services_soundplayer_assets_popcorn.mp3 from drawable resource ID #0x7f0b0001
    at android.content.res.ResourcesImpl.openRawResourceFd(ResourcesImpl.java:291)
    at android.content.res.Resources.openRawResourceFd(Resources.java:1263)
    at com.zmxv.RNSound.RNSoundModule.createMediaPlayer(RNSoundModule.java:161)
    at com.zmxv.RNSound.RNSoundModule.prepare(RNSoundModule.java:61)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
    at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
    at android.os.Looper.loop(Looper.java:154)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
    at java.lang.Thread.run(Thread.java:761)
Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
    at android.content.res.AssetManager.openNonAssetFdNative(Native Method)
    at android.content.res.AssetManager.openNonAssetFd(AssetManager.java:460)
    at android.content.res.ResourcesImpl.openRawResourceFd(ResourcesImpl.java:289)

Also the javascript code above is working on a simulator.

paulmelnikow commented 5 years ago
Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

This is interesting ^^

Have you tried with a different .mp3 file?

loic-lopez commented 5 years ago

@paulmelnikow thanks for reply, I have not tried but the code runs in production version of the application.

Also it works in a simulator with a debug build.

loic-lopez commented 5 years ago

Maybe, as i'm on androidX, before migrating to androidX the problem was not there.

ajungg commented 5 years ago

try turning off the resigning of the apk in the pre launch settings, see if that helps

loic-lopez commented 5 years ago

@ajungg where?

kurniaeliazar commented 5 years ago

maybe what he means is this release management --> pre-launch report --> go to settings --> Pre-launch report version

please let me know the result, I also experienced the same things :(

nromptea42 commented 5 years ago

Hello, I have the same error since the 22th of this month. Everything works fine with a production build on every phone I tried but every device of the pre-launch report crashs with this stacktrace :

FATAL EXCEPTION: mqt_native_modules
Process: com
android.content.res.Resources$NotFoundException: File res/raw/question.mp3 from drawable resource ID #0x7f080002
    at android.content.res.Resources.openRawResourceFd(Resources.java:1315)
    at com.zmxv.RNSound.RNSoundModule.createMediaPlayer(RNSoundModule.java:153)
    at com.zmxv.RNSound.RNSoundModule.prepare(RNSoundModule.java:57)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:160)
    at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
    at android.os.Handler.handleCallback(Handler.java:746)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
    at android.os.Looper.loop(Looper.java:148)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
    at java.lang.Thread.run(Thread.java:818)
Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
    at android.content.res.AssetManager.openNonAssetFdNative(Native Method)
    at android.content.res.AssetManager.openNonAssetFd(AssetManager.java:426)
    at android.content.res.Resources.openRawResourceFd(Resources.java:1312)
    ... 12 more

The resigning of the apk is off and it still doesn't work. I'm not using androidX (yet) and my react-native-sound package is not up to date. These are my versions : "react-native": "0.57.7", "react-native-sound": "^0.10.9",

If I understand correctly I can still deploy my build and see if it affects my users but I'm a bit scared.

kurniaeliazar commented 5 years ago

I tried this but not sure this is a good solution enough I added this in my proguard rule

-keep class *.R
-keepclasseswithmembers class **.R$* {
    public static <fields>;
}

maybe see if that helps

loic-lopez commented 5 years ago

In my case for my production builds i'm not using proguard.

loic-lopez commented 5 years ago

If I understand correctly I can still deploy my build and see if it affects my users but I'm a bit scared.

@nromptea42 you can try a production build without submitting it to your external users.

nromptea42 commented 5 years ago

I'm not using proguard either. @loic-lopez I downloaded, installed and launched the apk on multiple phones and it works fine. Maybe I will deploy to a certain percentage of external users to see how it goes.

ajungg commented 5 years ago

maybe what he means is this release management --> pre-launch report --> go to settings --> Pre-launch report version

please let me know the result, I also experienced the same things :(

Thats exactly what i meant :)

That option turns off the resigning of the APK and disables some features of the Robo Test. I had similar issues since two days and that helped. Since it worked before it seems to be a temporary issue with the Robo test.

loic-lopez commented 5 years ago

After digging a lot I made my binary x64 compliant see: developer.android.com/distribute/best-practices/develop/64-bit#building_with_android_studio_or_gradle

And submitted an AAB bundle the error does not occur anymore. How to generate an AAB bundle:

cd android && ./gradlew bundleRelease

I will update this issue if I have more information.