原因:
使用的v4包中没有这个类,有两种情况:
1.有多个v4包且版本不一致,运行时使用的其中一个最新版本的v4包不包含这个类;
2.只有一个v4包且此版本中不包含这个类。
分析:
高版本v4包中没有这个类,经查看源码发现supprot-24.2.1中有这个类,而support-26.0.0中没有,具体临界版本是多少没有深入研究
解决方法:
1.如果是第一种情况且知道多个v4包的引入位置,可以将其他库中的v4包屏蔽:
compile(第三方jar) {
exclude module: 'support-v4'
}
或者屏蔽module下的所有库中的v4包:
configurations {
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
如果不知道其他v4包的引入位置可使用终极方案,在主module的build.gradle文件的根节点中加入:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '23.4.0'
}
}
}
}
此方法可修改所有引入v4包的版本。
2.第二种情况直接修改唯一的v4包版本到23.4.0就可以了。