【发布时间】:2010-07-28 21:49:46
【问题描述】:
我正在尝试将 android 1.6+ 应用程序反向移植到 android 1.5。
遵循此处的建议:
- http://comments.gmane.org/gmane.comp.handhelds.android.devel/97051
- http://groups.google.com/group/android-developers/browse_thread/thread/ff22f6e42a4a46d2/4201a20aaa23069d
- Android 2.2 SDK breaks compatibility with older phones
- https://developer.android.com/guide/topics/resources/providing-resources.html#ScreenCompatibility
...我做了以下事情:
- 修改 AndroidManifest.xml 将 minSdkVersion 设置为 3
- 将我之前在 drawable-mdpi/ 中的所有文件移动到 drawable/
- 将 drawable-hdpi/ 重命名为 drawable-hdpi-v4/
在我看来,这应该确保 1.5 设备使用 drawable/ 中的文件,而 1.6 及更高版本的设备酌情使用 drawable/ 和 drawable-hdpi-v4/ 中的文件。 drawable/ 和 drawable-hdpi-v4/ 目录是我 res 文件夹中唯一的可绘制目录。
但是,在 1.5 模拟器上编译、安装和运行生成的二进制文件后,我收到以下错误:
E/AndroidRuntime( 1096): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 1096): at android.widget.ImageView.<init>(ImageView.java:103)
E/AndroidRuntime( 1096): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 1096): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
E/AndroidRuntime( 1096): at android.view.LayoutInflater.createView(LayoutInflater.java:499)
E/AndroidRuntime( 1096): ... 26 more
E/AndroidRuntime( 1096): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/bg.png from drawable resource ID #0x7f02002e
E/AndroidRuntime( 1096): at android.content.res.Resources.loadDrawable(Resources.java:1641)
E/AndroidRuntime( 1096): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
E/AndroidRuntime( 1096): at android.widget.ImageView.<init>(ImageView.java:113)
E/AndroidRuntime( 1096): ... 30 more
E/AndroidRuntime( 1096): Caused by: java.io.FileNotFoundException: res/drawable/bg.png
E/AndroidRuntime( 1096): at android.content.res.AssetManager.openNonAssetNative(Native Method)
E/AndroidRuntime( 1096): at android.content.res.AssetManager.openNonAsset(AssetManager.java:392)
E/AndroidRuntime( 1096): at android.content.res.Resources.loadDrawable(Resources.java:1634)
E/AndroidRuntime( 1096): ... 32 more
由于我不明白的原因,1.5 设备无法看到 bg.png 图像文件,其版本位于 drawable/ 和 drawable-hdpi-v4/ 目录中。
在 1.6 上运行相同的二进制文件可以正常工作。
为什么 1.5 设备无法通过此设置看到我的 res/drawable/bg.png 图像?
更新: 如Providing screen resource compatibility for Android 1.5 中所述,我使用的是 Android SDK r6 并将我的 mdpi 资源放在 drawable/ 目录中。另外,我已经验证了该问题并非孤立于 bg.png。如果我在我的 xml 中删除对损坏的可绘制对象的引用,则应用程序会在 setContentView() 期间中断下一个和每个后续图形。
【问题讨论】:
标签: android