release
中的bundle不会生成res/raw
文件夹。因此,从该文件夹读取声音的 PushNotification 等库无法正常工作。
我需要
audio.mp3
文件存在于res/raw
文件夹内的发布包中
问题只存在于
release bundle
。在 debug bundle
它工作正常。
我在用
apk
制作的捆绑包中展示了 debug
中的文件夹结构。注意audio.mp3
文件是如何存在的。
.
└── apk
├── assets
│ └── ...
...
...
│ └── ...
└── res
├── color
├── color-night-v8
├── color-v21
├── color-v23
└── color-v31
└── raw
├── audio.mp3
现在我展示了发布包中 apk 中的文件夹结构是怎样的。看看raw文件夹怎么不存在
.
└── apk
├── assets
│ └── ...
...
...
│ └── ...
└── res
├── color
├── color-night-v8
├── color-v21
├── color-v23
└── color-v31
这意味着推送通知不会与自定义音频一起响起。
在这里,我展示了一个存储库,其中包含一个简单的离子应用程序项目,该项目重现了上述错误。
https://github.com/WilmerRS/ionic-push-notification-raw-files
构建,创建 apk 作为发布并查看生成的 apk。
这是尝试过的配置,因此 audio.mp3 文件不会在发布时从捆绑包中删除。它没有达到任何效果。
保留文件,
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 规则
android/app/proguard-rules.pro
-keepclassmembers class **.R$* {public static <fields>;}
-keep class **.R$*
离子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>