背景
有一天突然接到一个项目,要求我在有限的时间内修改文档中列出的 1、2、3、4、5、6、7、8…若干个bug,扫了一眼,用的都是第三方库,一大堆,既然接了任务就得完成不是,跟之前的同事拿过来代码简单沟通了一下,用的AndroidStudio3.5.2,git clone 代码,导入项目,open…一气呵成,就在暗自自喜说尽快弄完的时候run了一下,从这里就要开始无穷无尽的问题。
First Blood:
由于androidStudio版本导致gradle version引起的版本问题
ERROR: No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
This version of the NDK may be incompatible with the Android Gradle plugin version 3.0 or older.
Please use plugin version 3.1 or newer.
Upgrade plugin to version 3.5.2 and sync project
解决方案:按照提示修改为 3.5.2
Double Kill:
butterKnife版本问题
The Android Gradle plugin supports only Butterknife Gradle plugin version 9.0.0-rc2 and higher.
The following dependencies do not satisfy the required version:
root project 'icedemo' -> com.jakewharton:butterknife-gradle-plugin:8.4.0
解决方案:按照提示将butterKnife的版本统一修改至9.0.0
Trible Kill
不同版本support包引起冲突
org.gradle.execution.MultipleBuildFailures: Build completed with 1 failures.
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:49)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
... 6 more
Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class android.support.v4.app.AppLaunchChecker found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.widget.AutoScrollHelper$ClampedScroller found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Duplicate class android.support.v4.widget.AutoScrollHelper$ScrollAnimationRunnable found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Duplicate class android.support.v4.widget.ContentLoadingProgressBar found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Duplicate class android.support.v4.widget.ContentLoadingProgressBar$1 found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Duplicate class android.support.v4.widget.ContentLoadingProgressBar$2 found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Duplicate class android.support.v4.widget.ListViewAutoScrollHelper found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Duplicate class android.support.v4.widget.NestedScrollView found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Duplicate class android.support.v4.widget.NestedScrollView$AccessibilityDelegate found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Duplicate class android.support.v4.widget.NestedScrollView$OnScrollChangeListener found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Duplicate class android.support.v4.widget.NestedScrollView$SavedState found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Duplicate class android.support.v4.widget.NestedScrollView$SavedState$1 found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-ui-27.0.2-runtime.jar (com.android.support:support-core-ui:27.0.2)
Go to the documentation to learn how to Fix dependency resolution errors.
at com.android.ide.common.workers.ExecutorServiceAdapter.await(ExecutorServiceAdapter.kt:108)
at com.android.build.gradle.internal.tasks.CheckDuplicateClassesDelegate.run(CheckDuplicateClassesDelegate.kt:67)
at com.android.build.gradle.internal.tasks.CheckDuplicateClassesTask.doTaskAction(CheckDuplicateClassesTask.kt:61)
at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:51)
at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:31)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:90)
at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:48)
at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:120)
... 38 more
Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Duplicate class android.support.v4.app.AppLaunchChecker found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.FrameMetricsAggregator found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.FrameMetricsAggregator$FrameMetricsApi24Impl found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.FrameMetricsAggregator$FrameMetricsApi24Impl$1 found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.FrameMetricsAggregator$FrameMetricsBaseImpl found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.FrameMetricsAggregator$MetricType found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.NavUtils found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.TaskStackBuilder found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.TaskStackBuilder$SupportParentable found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.content.FileProvider found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.content.FileProvider$PathStrategy found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.content.FileProvider$SimplePathStrategy found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Go to the documentation to learn how to Fix dependency resolution errors.
at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)
at com.android.ide.common.workers.ExecutorServiceAdapter.await(ExecutorServiceAdapter.kt:102)
... 101 more
Caused by: java.lang.RuntimeException: Duplicate class android.support.v4.app.AppLaunchChecker found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.FrameMetricsAggregator found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.FrameMetricsAggregator$FrameMetricsApi24Impl found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.FrameMetricsAggregator$FrameMetricsApi24Impl$1 found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.FrameMetricsAggregator$FrameMetricsBaseImpl found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.FrameMetricsAggregator$MetricType found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.NavUtils found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.TaskStackBuilder found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.app.TaskStackBuilder$SupportParentable found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.content.FileProvider found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Duplicate class android.support.v4.content.FileProvider$PathStrategy found in modules support-compat-28.0.0-runtime.jar (com.android.support:support-compat:28.0.0) and support-core-utils-27.0.2-runtime.jar (com.android.support:support-core-utils:27.0.2)
Go to the documentation to learn how to Fix dependency resolution errors.
at com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable.run(CheckDuplicateClassesDelegate.kt:128)
at com.android.ide.common.workers.ExecutorServiceAdapter$submit$submission$1.run(ExecutorServiceAdapter.kt:68)
at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinTask.externalInterruptibleAwaitDone(ForkJoinTask.java:361)
at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1001)
... 102 more
jiejue
解决方案:将项目中所有的support版本统一,在app 的Module 的gradle.build 最外层(和android、dependencies等平级)中添加统一support代码
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion "26.1.0"
}
}
}
}
至于这个版本到底用什么看项目情况而定,例如我们项目中使用的com.android.support:appcompat-v7:26.1.0,所以在这里我将版本修改为26.1.0
Quadra kill
CompileOptions.getBootClasspath()Ljava/lang/String;’.
Unable to find method 'org.gradle.api.tasks.compile.CompileOptions.getBootClasspath()Ljava/lang/String;'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
解决方案:删除项目中me.tatarka.retrolambda 插件,
在module中的build.gradle删除 apply plugin: ‘me.tatarka.retrolambda’
在最外层build.gradle 中删除classpath ‘me.tatarka:gradle-retrolambda:3.7.0’
看似很简单的一句话,实则这个几个问题困扰了大概一周的时间,主要是中间几个问题把我带偏了,还有一点跟着csdn上的文章跑偏了,还是想的太简单,tooYang…最主要的就是最后这个问题,差点把我搞崩溃,为啥这么说呢!!!
一开始的跑偏已经让我心惊胆战,精疲力竭了,可是这个问题更让我抓狂。
接下来就是排除错误的步骤:
1:根据两个提示
-
Re-download dependencies and sync project (requires network)
重新下载依赖项和同步项目(需要网络)
短暂的同步之后问题依旧存在。 -
Stop Gradle build processes (requires restart)
停止渐变生成过程(需要重新启动)
除了重启了一下studio并无任何毛用。
2:问度娘
看似有很多回答,挨个点看学习,大致分文两种答案:
1:将可以运行的项目中的 gradle.wraper 文件直接复制到该项目中
2:修改targetVersion 版本
然而并无卵用。此时除了无助还是无助。
3:本地排除法(非耐心人士慎用,会把你逼疯的)
我在本地又新建了一个项目(这里将我原本的项目命名为P1,新建的项目命名为P2),使用同样的版本,同样的gradle,说白了除了代码没用他的,其他的都是一模一样,run一下,发现是可以的。因为是新项目肯定是可以的。
继续将项目中的代码复制到新建的项目中,这次复制我直接将大部分依赖,下面的Module都复制过去了,基本能占到P1项目中的50%代码量,(这里会有人问为什么不复制appModule而是复制其他的Module,那是因为appModule依赖了其他的子Module,所以如果从代码中排查错误,代码越少越好排查,所以先复制子Module中的代码)run…runing…我的天,出现了跟原来的项目P1同样的错误,这个基本说明我的排错思路是对的。
然后将P2中代码一点点删除,每次删除一点我都跑一下,如果跑起来
1有问题:那说明刚刚删除的那点代码没问题,因为本来就有问题,删除了点代码依旧有问题,那说明刚刚删除的代码没问题。(这里要保证前后错误一样)
2可以正常运行:那说明刚刚删除的那点代码有问题,因为本来就有问题,删除了点代码没有问题,那说明刚刚删除的代码有问题。
就这样,基本删代码run了10几个版本之后,最终确定是有那么几行代码,删掉之后就可以运行,不删就有问题,那几本可以确定就是这点代码了,于是去原项目P1验证刚刚的问题代码。
找到原项目中那段代码,删除,果然不报那个错误了…
此时应该有掌声,说明我的排错思路是没有错误的。
最后给大家献上那段我想杀了的代码
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
apply plugin: 'me.tatarka.retrolambda'
classpath 'me.tatarka:gradle-retrolambda:3.7.0’这行位于最外层build.gradle文件中
apply plugin: ‘me.tatarka.retrolambda’ 位于module 的build.gradle 中
如果没有最外层的这个 classpath,则module就会提示你缺少-retrolambda,那如果删除 apply plugin下的,则出现上面那个错误。
至此这个问题算是解决了,回顾一下:
1:me.tatarka.retrolambda 是个什么东西 :就是一个android Studio Lambda插件:查看详情
2:其实一开始问度娘的时候会发现,搜出来的结果都是 setbootclasspath,而我遇到的是 getbootclasspath,不信?你自己看看
总结
到这里我的app总算运行起来了;
其实这里你们看到的是从项目下载下来到运行起来的几个主要问题,其实在一开始跑偏的时候还有其他问题,运行项目都搞了好几天,那就接下来改bug…(感觉又掉了几根头发)