Error: Program type already present: android.support.v4.view.NestedScrollingParentHelper
大致意思是说重复依赖导致的错误,费劲周章彻底解决了问题,特此记录!
思路:既然是重复依赖,也就说明工程和的某个.jar依赖了相同的.jar,去除掉依赖,问题解决,废话真多,直接上方法emmm.
解决方法:一共两种
方法一
将下面一段代码贴到app/build.gradle里,其中details.useVersion版本号就是你的support-v4或v7包的版本
android {
.....
defaultConfig {
.....
}
buildTypes {
...
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.4.0'
}
}
}
}
}
方法二
步骤1、随便在一个.java文件里把这个NestedScrollingParentHelper粘贴进去,按住Ctrl,鼠标放上去,看到了它依赖的包名
步骤2、Android Studio的 Terminal下敲 gradlew -q app:dependencies 命令,可以看到,com.android.support:appcompat-v7:25.4.0里包含了com.android.support:support-core-ui:25.4.0
步骤3、使用exclue排除重复引用的jar包
implementation('com.android.support:appcompat-v7:25.4.0', {
exclude module: 'animated-vector-drawable'
})
-------------------------------------------------------------完美解决------------------------------------------------------------------
注:假如需要同时去除多个时,可以这么写
implementation('com.android.support:appcompat-v7:25.4.0', {
exclude module: 'animated-vector-drawable'
exclude module: 'support-v4'
})
记录下遇到问题的解决办法,一是方便自己日后查看,二是希望能帮助遇到此问题的朋友能快速解决。