程序异常退出,LogCat中日志如下:
09-27 07:08:18.608 7529-7529/com.tangula.android.base I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
09-27 07:08:18.608 7529-7529/com.tangula.android.base W/dalvikvm: VFY: unable to resolve virtual method 852: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources T h e m e ; ) L a n d r o i d / g r a p h i c s / d r a w a b l e / D r a w a b l e ; 09 − 2707 : 08 : 18.6087529 − 7529 / c o m . t a n g u l a . a n d r o i d . b a s e D / d a l v i k v m : V F Y : r e p l a c i n g o p c o d e 0 x 6 e a t 0 x 000209 − 2707 : 08 : 18.6087529 − 7529 / c o m . t a n g u l a . a n d r o i d . b a s e I / d a l v i k v m : C o u l d n o t f i n d m e t h o d a n d r o i d . c o n t e n t . r e s . R e s o u r c e s . g e t D r a w a b l e F o r D e n s i t y , r e f e r e n c e d f r o m m e t h o d a n d r o i d . s u p p o r t . v 7. w i d g e t . R e s o u r c e s W r a p p e r . g e t D r a w a b l e F o r D e n s i t y ∗ ∗ 09 − 2707 : 08 : 18.6087529 − 7529 / c o m . t a n g u l a . a n d r o i d . b a s e W / d a l v i k v m : V F Y : u n a b l e t o r e s o l v e v i r t u a l m e t h o d 854 : L a n d r o i d / c o n t e n t / r e s / R e s o u r c e s ; . g e t D r a w a b l e F o r D e n s i t y ( I I L a n d r o i d / c o n t e n t / r e s / R e s o u r c e s Theme;)Landroid/graphics/drawable/Drawable; 09-27 07:08:18.608 7529-7529/com.tangula.android.base D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 09-27 07:08:18.608 7529-7529/com.tangula.android.base I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity **09-27 07:08:18.608 7529-7529/com.tangula.android.base W/dalvikvm: VFY: unable to resolve virtual method 854: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources Theme;)Landroid/graphics/drawable/Drawable;09−2707:08:18.6087529−7529/com.tangula.android.baseD/dalvikvm:VFY:replacingopcode0x6eat0x000209−2707:08:18.6087529−7529/com.tangula.android.baseI/dalvikvm:Couldnotfindmethodandroid.content.res.Resources.getDrawableForDensity,referencedfrommethodandroid.support.v7.widget.ResourcesWrapper.getDrawableForDensity∗∗09−2707:08:18.6087529−7529/com.tangula.android.baseW/dalvikvm:VFY:unabletoresolvevirtualmethod854:Landroid/content/res/Resources;.getDrawableForDensity(IILandroid/content/res/ResourcesTheme;)Landroid/graphics/drawable/Drawable;**
09-27 07:08:18.608 7529-7529/com.tangula.android.base D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
09-27 07:08:18.608 7529-7529/com.tangula.android.base E/dalvikvm: Could not find class ‘android.graphics.drawable.RippleDrawable’, referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlapping Rendering
09-27 07:08:18.608 7529-7529/com.tangula.android.base W/dalvikvm: VFY: unable to resolve instanceof 249 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
09-27 07:08:18.608 7529-7529/com.tangula.android.base D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c
09-27 07:08:18.608 7529-7529/com.tangula.android.base I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
09-27 07:08:18.608 7529-7529/com.tangula.android.base W/dalvikvm: VFY: unable to resolve virtual method 667: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
09-27 07:08:18.608 7529-7529/com.tangula.android.base D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
09-27 07:08:18.608 7529-7529/com.tangula.android.base I/dalvikvm: Could not find method android.content.Context.createDeviceProtectedStorageContext, referenced from method android.support.v4.content.ContextCompat.createDeviceProtectedStorageContext
09-27 07:08:18.608 7529-7529/com.tangula.android.base W/dalvikvm: VFY: unable to resolve virtual method 659: Landroid/content/Context;.createDeviceProtectedStorageContext ()Landroid/content/Context;
09-27 07:08:18.608 7529-7529/com.tangula.android.base D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
然后程序就结束了!!!
然后分析日志吧!上面的内容过滤一下ERROR级别的分别如下:
09-27 07:08:15.358 1883-1883/com.google.process.gapps E/NetworkScheduler.SR: Invalid parameter app
09-27 07:08:15.358 1883-1883/com.google.process.gapps E/NetworkScheduler.SR: Invalid package name : Perhaps you didn’t include a PendingIntent in the extras?
09-27 07:08:15.378 2036-2316/com.google.android.gms E/Drive.UninstallOperation: Package still installed com.tangula.android.base
09-27 07:08:15.458 2036-7497/com.google.android.gms E/IntentOperationSvc: Failed to instantiate Chimera operation impl, dropping operation
09-27 07:08:15.598 1883-1883/com.google.process.gapps E/NetworkScheduler.SR: Invalid parameter app
09-27 07:08:15.598 1883-1883/com.google.process.gapps E/NetworkScheduler.SR: Invalid package name : Perhaps you didn’t include a PendingIntent in the extras?
到这里为止都是com.google报错,而且还没有结束。一般来说这不是问题,大部分情况下可能是墙引起的。
09-27 07:08:16.028 7529-7529/? E/Trace: error opening trace file: Permission denied (13)
这里爆了没法打开trace文件,没有授权。看上去这个是日志相关的。应该也没有关系。
09-27 07:08:18.608 7529-7529/com.tangula.android.base E/dalvikvm: Could not find class ‘android.graphics.drawable.RippleDrawable’, referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
09-27 07:09:43.198 2036-5093/com.google.android.gms E/CheckinTask: Checkin failed: https://android.clients.google.com/checkin (request #0):
这里说找不到RippleDrawable类,这是啥?
java.net.ConnectException: failed to connect to android.clients.google.com/74.125.204.102 (port 443) after 120000ms: isConnected failed: ECONNREFUSED (Connection refused)
09-27 07:10:03.328 2036-7808/com.google.android.gms E/ActivityThread: Failed to find provider info for com.google.android.wearable.settings
09-27 07:11:13.798 1883-2335/com.google.process.gapps E/GCM: Missing checkin config file
这里的情况应该是APP已经死了,连不上。
所以最大的问题是RippleDrawable这个问题。RippleDrawable是Android 5.0中提供的一个波纹特效,对应API级别是21。我们引用的AppCompact包是支持兼容到v7的。所以不应该出这个问题。于是测试了一下,API Level 17以上就没有问题,程序可以正常启动。
查资料,都没有说如何解决这个问题的。
应啃日志,发现出问题之前好像在读主题的资源
09-27 07:08:18.608 7529-7529/com.tangula.android.base W/dalvikvm: VFY: unable to resolve virtual method 852: Landroid/content/res/Resources;.getDrawable ** (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;**
09-27 07:08:18.608 7529-7529/com.tangula.android.base D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
注意其中的 (ILandroid/content/res/Resources$Theme;)
主题文件如下:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
- "colorPrimary"
>@color/colorPrimary
- "colorPrimaryDark">@color/colorPrimaryDark
- "colorAccent">@color/colorAccent
- "windowActionBar">false
- "windowNoTitle">true
- "android:actionMenuTextColor">@android:color/white
style>
<style name="AppTheme.NoActionBar">
- "windowActionBar"
>false
- "windowNoTitle">true
- "android:actionMenuTextColor">@android:color/white
style>
这里AppTheme是自动生成的,AppTheme.NoActionBar是自定义ActionBar的时候从网上抄过来的。我们怀疑程序启动的时候,加载主题的时候有些Ripple效果的资源被读取了,然后因为平台不兼容,导致程序崩溃。
经过各种实验之后发现问题是这样的:
AppTheme.NoActionBar没有指定parent,所以用了编译时候的指定的平台版本。也就是没用到AppCompact库中的内容。我的最低版本是16,编译和目标版本都是27,所以系统启动的时候,NoActionBar就会用版本27中的默认样式作为基础样式。这样也就有Ripple的问题了。
最后,解决办法就是给他指定一个AppCampat中的parent样式,例如:
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
- "windowActionBar"
>false
- "windowNoTitle">true
- "android:actionMenuTextColor">@android:color/white
style>
The End