Proguard的打破资产或原始音频文件 [英] Proguard breaking audio file in assets or raw

查看:443
本文介绍了Proguard的打破资产或原始音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有扮演一个蜂鸣声与MediaPlayer的工作正常,并用于即使在proguarded产版做工精细的活动。在最新的版本,现在突然崩溃

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

我尝试了一些装载不同的方式和播放,包括其存储资产,而不是原来的RES声音/生,他们所有的工作,当我在尚未proguarded应用程序使用,但他们都失败,并释放即proguarded / zipaligned和签名版本。

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.

我ProGuard的文件是相当大,它包含的经常建议修订

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?

更新:我也试图与mp3文件,它有同样的问题。

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

更新2:一个有趣的事情是,它似乎需要一段时间(接近1秒)崩溃与此消息。好象是搜索或处理一些文件或东西..但该文件是非常小,所以它的怪异。

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.

推荐答案

该错误表明ZIP条目beep.ogg为com pressed,当它不应该。

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

个别条目可任选地融为一体pressed。此COM pression通常是透明的,读取压缩文件的应用程序。然而,Android的访问某些类型的文件(如.OGG和.M​​P3)直接,没有拆包他们,这只是工作,如果他们不是COM pressed。

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.

您可以看到哪些项是COM pressed与

You can see which entries are compressed with

unzip -lv MyApplication.apk

在列'法','DEFL是指COM pressed和保存的意思uncom pressed。

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

ProGuard的不执行apk文件的最终包装 - AAPT,apkbuilder,的jarsigner,zipalign,以及可能的后处理步骤做。在合适的阶段,他们应该离开.OGG和uncom pressed .mp3文件。您可能需要检查他们融入Maven构建过程。

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顺带会执行最后的包装。它有一个选项-dontcom preSS来控制哪些文件或文件类型是左uncom pressed。默认配置将使.OGG和.mp3文件uncom pressed。

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.

(我ProGuard,并将DexGuard的开发者)

(I am the developer of ProGuard and DexGuard)

更新由曼弗雷德·莫泽:

Update by Manfred Moser:

这确实是问题。事实证明,这已经无关ProGuard的整合还是Android Maven插件。这个问题是由Maven的的jarsigner插件配置我使用造成的。我已成立removeExistingSignatures为真,这是不是默认值,造成的一切文件归档是COM pressed。我认为这是一个奇怪的bug的jarsigner插件在这个阶段。在任何情况下...的默认配置是为这个参数设置为false,以便任何人都不应该有任何问题......当然,除非你将其设置为true,像我一样;-)

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的打破资产或原始音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆