我已经定义了一些我想在我的应用程序中使用的自定义属性,它们在通过 Eclipse 运行时工作正常,但有时在构建和分发 APK 时会引发异常。下面是异常的堆栈跟踪:
W/dalvikvm( 2521): threadid=1: thread exiting with uncaught exception (group=0x40f44300)
E/AndroidRuntime( 2521): FATAL EXCEPTION: main
E/AndroidRuntime( 2521): android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
E/AndroidRuntime( 2521): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
E/AndroidRuntime( 2521): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime( 2521): at com.myapp.android.ui.fragment.CustomDialogFragmentImpl.onCreateView(CustomDialogFragmentImpl.java:74)
E/AndroidRuntime( 2521): at com.myapp.android.ui.fragment.SupportCustomDialogFragment.onCreateView(SupportCustomDialogFragment.java:41)
E/AndroidRuntime( 2521): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
E/AndroidRuntime( 2521): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
E/AndroidRuntime( 2521): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
E/AndroidRuntime( 2521): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
E/AndroidRuntime( 2521): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
E/AndroidRuntime( 2521): at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime( 2521): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 2521): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 2521): at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 2521): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2521): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 2521): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 2521): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 2521): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2521): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 2521): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 2521): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
E/AndroidRuntime( 2521): ... 23 more
E/AndroidRuntime( 2521): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
E/AndroidRuntime( 2521): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
E/AndroidRuntime( 2521): at android.view.View.<init>(View.java:3342)
E/AndroidRuntime( 2521): at android.view.ViewGroup.<init>(ViewGroup.java:427)
E/AndroidRuntime( 2521): at android.widget.FrameLayout.<init>(FrameLayout.java:101)
E/AndroidRuntime( 2521): at android.widget.FrameLayout.<init>(FrameLayout.java:97)
E/AndroidRuntime( 2521): ... 26 more
这是第 13 行的视图:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="12dp"
android:paddingLeft="?attr/listItemPaddingLeft"
android:paddingRight="?attr/listItemPaddingRight" >
这是我定义的属性:
<declare-styleable name="MyAppTheme">
<attr name="listItemPaddingLeft" format="dimension" />
<attr name="listItemPaddingRight" format="dimension" />
<attr name="listItemHeight" format="dimension" />
<attr name="listHeaderHeight" format="dimension" />
</declare-styleable>
最后,这是我的主题:
<style name="MyAppTheme" parent="@style/Theme.Sherlock.Light">
<item name="listItemPaddingLeft">22dp</item>
<item name="listItemPaddingRight">22dp</item>
<item name="listItemHeight">43dp</item>
<item name="listHeaderHeight">73dp</item>
</style>
有没有人看到我定义事物的方式有任何问题,或者可以解释为什么这在本地构建时会起作用,但在 APK 签名时不起作用?我的设备是 Galaxy Nexus,它在本地和已签名的 APK 上运行良好,但 Galaxy S3 不适用于已签名的 APK(无法在本地测试)。