http://stackoverflow.com/questions/21440572/proguard-breaking-audio-file-in-assets-or-raw

Issue:

I have an activity that plays a beep sound with MediaPlayer that works fine and used to work fine even in the proguarded production version. With the latest release it 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 a number of different ways of loading and playing the sound including storing it in assets instead of the original res/raw and they all work when I use in the app that has not been proguarded but they all fail with the release version that is proguarded/zipaligned and signed.

My proguard file is rather large and it does contain the often suggested fix of

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

Anybody have any ideas or encountered something like this before?

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

Update 2: An interesting thing is that it seem to take quite a while (close to 1s) to crash with this message. As if it is searching or processing some file or something .. but the file is really small so its weird.

Answer:

The error suggests that the zip entry beep.ogg is compressed, when it shouldn't be.

Individual entries in zip files can optionally be compressed. This compression is typically transparent to the application that reads the zip file. However, Android accesses some types of files (like .ogg and .mp3) directly, without unpacking them, which only works if they are not compressed.

You can see which entries are compressed with

unzip -lv MyApplication.apk

In the column 'Method', 'Defl' means compressed and 'Stored' means uncompressed.

ProGuard doesn't perform the final packaging of the apk file -- aapt, apkbuilder, jarsigner, zipalign, and possible post-processing steps do. At the proper stages, they should leave .ogg and .mp3 files uncompressed. You may need to check their integration in the Maven build process.

DexGuard incidentally does perform the final packaging. It has an option -dontcompress to control which files or file types are left uncompressed. The default configuration leaves .ogg and .mp3 files uncompressed.

(I am the developer of ProGuard and DexGuard)

Update by Manfred Moser:

This was indeed the problem. Turns out that this has nothing to do with the proguard integration or the Android Maven Plugin. The problem was caused by the Maven Jarsigner Plugin configuration I used. I had set removeExistingSignatures to true, which is not the default value and caused all files in the archive to be compressed. I consider this a weird bug of the jarsigner plugin at this stage. In any case... the default config is to for this parameter to be set to false so nobody should have any problem ... unless of course you set it to true like I did ;-)

Proguard breaking audio file in assets or raw的更多相关文章

  1. 万能存储工具类SDCard存储 /data/data/存储 assets存储 raw存储

    万能存储工具类 SDCard存储  /data/data/存储  assets存储 raw存储 粘贴过去就能够用了 <uses-permission android:name="and ...

  2. Assets和Raw区别

    在建立项目中一般会默认建立assets文件,当然我们还可以在res文件下面建立raw文件夹,这里面都可以存放一些多媒体文件或者文本信息,可以供我们在程序中使用. assets下面的文件不会被编译,通过 ...

  3. 【.Net Core】Assets file project.assets.json not found. Run a NuGet package restore

    问题起因 添加 .net core的Project build失败. 提示以下error: Assets file project.assets.json not found. Run a NuGet ...

  4. android工程下assets与raw文件夹

    在应用的开发中,当我们创建一个新的Android工程后,我们会发现工程中包含了一个目录assets,另外当我们察看一些示例工程的时候,有时会发现在该工程的资源目录下会有一个raw目录(res/raw) ...

  5. Combining an audio file with video file in python

    Combining an audio file with video file in python - Stack Overflow https://stackoverflow.com/questio ...

  6. Sound (audio file) player in java - working source code example

    转载自:http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/sound-audio-file-player-in-java-working.html ...

  7. Android读写assets、raw、sdard和工程文件的方法

    Android开发离不开对文件的操作,前面的文章“Android简易数据存储之SharedPreferences”和“Android数据存储之SQLite的操作”,分别讲解了简单的数据的存储和数据库数 ...

  8. android 文件读取(assets、raw)

    需要注意的是,来自Resources和Assets 中的文件只可以读取而不能进行写的操作. assets文件夹里面的文件都是保持原始的文件格式,需要用AssetManager以字节流的形式读取文件. ...

  9. Android 开发 assets和raw

    在Android Project中,有两个文件夹的数据是不会被编译,以原型的方式打包到APK中,这两个文件夹就是 assets 和 res/raw/ 相同点: 1.数据不会编译成二进制字节码. 2.可 ...

随机推荐

  1. 编写高质量代码改善C#程序的157个建议——建议58:用抛出异常代替返回错误代码

    建议58:用抛出异常代替返回错误代码 CLR异常机制的优点: 正常控制流会被立即中止,无效值或状态不会在系统中继续传播. 提供了统一的处理错误的方法. 提供了在构造函数.操作符重载及属性中报告异常的遍 ...

  2. ABP源码uml类图

    陆陆续续学习ABP框架有一段时间了,阳光铭睿的入门教程和HK Zhang的源码分析文章对我的学习帮助都很大.之所以会花这么大工夫去学习ABP.看ABP的源代码,一是因为本人对于DDD也非常有兴趣,AB ...

  3. 使用JS完成首页定时弹出广告图片

    一.需求分析 在首页中的顶部做一个定时弹出广告图片. 二.技术分析 隐藏图片: display: none        定时操作: setInterval(“显示图片的函数”, 3000); 三.代 ...

  4. sql server 简单语句整合

    1.去重distinct , group by select distinct userid,username from 表名 select userid,username from 表名 group ...

  5. 指针和动态分配内存 (不定长度数组)------新标准c++程序设计

    背景: 数组的长度是定义好的,在整个程序中固定不变.c++不允许定义元素个数不确定的数组.例如: int n; int a[n]; //这种定义是不允许的 但是在实际编程中,往往会出现要处理的数据数量 ...

  6. django修改数据库连接

    settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'domain', 'USER ...

  7. stegsolve的功能

  8. 入参为json类型的接口测试示例

    一.接口文档内容 二.使用postman(入参为json类型) 如下部分内容即是json串: { "name":"刘星", "grade": ...

  9. 洛谷P2764 最小路径覆盖问题(最大流)

    传送门 先说做法:把原图拆成一个二分图,每一个点被拆成$A_i,B_i$,若原图中存在边$(u,v)$,则连边$(A_u,B_v)$,然后$S$对所有$A$连边,所有$B$对$T$连边,然后跑一个最大 ...

  10. win8.1 开启企业模式

      1,Win+R Gpedit.msc 2, 3,   4,F12   多了一项企业模式