Proguard violates audio file in assets or raw

I have an activity that plays an audio signal from MediaPlayer, which works great and is used to work even in the serial version. With the latest release, he now suddenly crashes with

Caused by: android.content.res.Resources$NotFoundException: File res/raw/beep.ogg from drawable resource ID #0x7f060000
at android.content.res.Resources.openRawResourceFd(Resources.java:994)
at android.media.MediaPlayer.create(MediaPlayer.java:855)
at com.digikey.mobile.activity.CaptureActivity.onCreate(SourceFile:135)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
... 11 more
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:428)
at android.content.res.Resources.openRawResourceFd(Resources.java:991)
... 16 more

I tried several different ways to download and play sound, including storing it in assets instead of the original res / raw, and they all work when I use an application that has not been profiled, but they all do not work with the release of a version that is predefined / zipaligned and signed.

My proguard file is quite large and contains a commonly suggested fix

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

Anyone have any ideas or something like that before?

Update: I also tried with mp3 files and had the same problems.

2: , ( 1 ). - - , , .

+4
3

, zip- beep.ogg , .

zip . , zip . , Android (,.ogg .mp3), , , .

,

unzip -lv MyApplication.apk

"" "Defl" , "" .

ProGuard apk - aapt, apkbuilder, jarsigner, zipalign . .ogg .mp3 . , Maven.

DexGuard, , . -dontcompress, , . .ogg .mp3 .

( ProGuard DexGuard)

:

. , proguard Android Maven. Maven Jarsigner Plugin, . removeExistingSignatures true, . jarsigner. ... false, ... , , true, ;-)

+12

, , , :

res/raw/beep.ogg

, , R. , , .ogg raw.

-keep class *.R

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

, ProGuard ( , ).

08-30 22:10:32.360 561-18619/? E/FileSource: Failed to open file 'android.resource://com.mycompany.myapp/2131230720'. (No such file or directory)

keep.xml,

- (@/res/raw/keep.xml):

    <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@raw/*">
</resources>

, , , mp3 RAW.

unzip -lv app-release.apk mp3 :

0 Stored 0 0% 00-00-1980 00:00 00000000 res/raw/audio.mp3

(0 ?!).

+1

Source: https://habr.com/ru/post/1524353/


All Articles