The bundle in release
does not generate the res/raw
folder. Therefore, libraries like PushNotification that read the sound from that folder do not work correctly.
I need the audio.mp3
file to exist in the release bundle inside the res/raw
folder
The problem only exists in the release bundle
. In the debug bundle
it works correctly.
I show how the folder structure is inside the apk
in a bundle made with debug
. Notice how the audio.mp3
file exists.
.
└── apk
├── assets
│ └── ...
...
...
│ └── ...
└── res
├── color
├── color-night-v8
├── color-v21
├── color-v23
└── color-v31
└── raw
├── audio.mp3
Now I show how is the folder structure inside the apk in a bundle made with release. See how the raw folder does not exist
.
└── apk
├── assets
│ └── ...
...
...
│ └── ...
└── res
├── color
├── color-night-v8
├── color-v21
├── color-v23
└── color-v31
This means that the push notification will not sound with the custom audio.
Replication
Here I present a repository with a simple project of an ionic app that reproduces the mentioned error.
https://github.com/WilmerRS/ionic-push-notification-raw-files
Build, create apk as release and review the generated apk.
Aditional Context
This is the configuration tried so that the audio.mp3 file is not removed from the bundle in release. It has not achieved any effect.
Keep file, android/app/src/main/res/raw/keep.xml
<?xml version="1.0" encoding="utf-8"?>
<resources tools:keep="@raw/audio.mp3, @raw/audio, @raw/*"
xmlns:tools="http://schemas.android.com/tools">
</resources>
Proguard rules android/app/proguard-rules.pro
-keepclassmembers class **.R$* {public static <fields>;}
-keep class **.R$*
Ionic config.xml ./config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.app" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
...
<platform name="android">
...
<resource-file src="resources/audio.mp3" target="app/src/main/res/raw/audio.mp3" />
...
</platform>
</widget>