Proguard breaking audio file in assets or raw
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的更多相关文章
- 万能存储工具类SDCard存储 /data/data/存储 assets存储 raw存储
万能存储工具类 SDCard存储 /data/data/存储 assets存储 raw存储 粘贴过去就能够用了 <uses-permission android:name="and ...
- Assets和Raw区别
在建立项目中一般会默认建立assets文件,当然我们还可以在res文件下面建立raw文件夹,这里面都可以存放一些多媒体文件或者文本信息,可以供我们在程序中使用. assets下面的文件不会被编译,通过 ...
- 【.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 ...
- android工程下assets与raw文件夹
在应用的开发中,当我们创建一个新的Android工程后,我们会发现工程中包含了一个目录assets,另外当我们察看一些示例工程的时候,有时会发现在该工程的资源目录下会有一个raw目录(res/raw) ...
- Combining an audio file with video file in python
Combining an audio file with video file in python - Stack Overflow https://stackoverflow.com/questio ...
- Sound (audio file) player in java - working source code example
转载自:http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/sound-audio-file-player-in-java-working.html ...
- Android读写assets、raw、sdard和工程文件的方法
Android开发离不开对文件的操作,前面的文章“Android简易数据存储之SharedPreferences”和“Android数据存储之SQLite的操作”,分别讲解了简单的数据的存储和数据库数 ...
- android 文件读取(assets、raw)
需要注意的是,来自Resources和Assets 中的文件只可以读取而不能进行写的操作. assets文件夹里面的文件都是保持原始的文件格式,需要用AssetManager以字节流的形式读取文件. ...
- Android 开发 assets和raw
在Android Project中,有两个文件夹的数据是不会被编译,以原型的方式打包到APK中,这两个文件夹就是 assets 和 res/raw/ 相同点: 1.数据不会编译成二进制字节码. 2.可 ...
随机推荐
- mysql5.6数据库双机热备、主从备份
主题:mysql5.6数据库双机热备.主从备份 缘由: 在Web应用系统中,数据库性能是导致系统性能瓶颈最主要的原因之一.尤其是在大规模系统中,数据库集群已经成为必备的配置之一.集群的好处主要有:查询 ...
- IOException while loading persisted sessions: java.io.EOFException
运行eclipse启动服务器的时候,出现了IOException while loading persisted sessions: java.io.EOFException报错.本以为是代码修改出现 ...
- 使用JMeter测试基于WebSocket协议的服务
使用JMeter测试基于WebSocket协议的服务 :first-child{margin-top:0!important}img.plugin{box-shadow:0 1px 3px rgba( ...
- 删除当前文件夹的bat工具
@echo off:11set /p path=Please enter delete filepath:del /f /s /q %path%rd /q /s %path%goto 11pause
- firefox 59 无法使用 pac 代理上网
最近装了 firefox,电脑配置不太高,chrome 太吃内存了. 但是发现 SwitchyOmega的 pac 模式无法工作,这篇文章提到了两个思路, 其中network.dns.disableI ...
- golang 重构博客统计服务
欢迎关注楼主与他的小伙伴们的小站,每周分享一些技术文章,让我们在技术上一起成长------> 戳这里,欢迎光临小站 -_- 作为一个后端开发,在docker,etcd,k8s等新技术不断涌现的今 ...
- JavaScript 如何工作:渲染引擎和性能优化技巧
翻译自:How JavaScript works: the rendering engine and tips to optimize its performance 这是探索 JavaScript ...
- eclipse操作
1.手动添加组件源码 2.源码阅读技巧 选择类Ctrl+T(Quick Type Hierarchy),查看该类的继承关系: 选择方法Ctrl+Alt+H(Open Call Hierarchy),查 ...
- 1222: FJ的字符串 [水题]
1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = ...
- select chosen 的入门使用
首先要引用 因为肯定要引用jq,所以就没有写啦 <link rel="stylesheet" href="__ROOT__/Public/jschy/chosen_ ...