在分割APK时由于ButterKnife崩溃导致构建失败

时间:2017-05-27 19:31:58

标签: android android-gradle apk butterknife

我们有一个包含许多依赖项,多种风格和构建类型的大项目。

我试图根据official instruction拆分APK。但是,构建失败了。我在我的项目上尝试了相同的步骤,一切顺利。

堆栈跟踪指出ButterKnife存在问题,但我无法解决问题。

:bankOK:compileBetaNewApiDebugJavaWithJavac UP-TO-DATE
:bankOK:mergeBetaNewApiDebugAssets UP-TO-DATE
:bankOK:processBetaNewApiHdpiDebugManifest
:bankOK:processBetaNewApiHdpiDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bankOK:processBetaNewApiHdpiDebugResources'.
> Cannot invoke method replaceAll() on null object

例外是:

Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':bankOK:processBetaNewApiHdpiDebugResources'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:66)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: java.lang.NullPointerException: Cannot invoke method replaceAll() on null object
    at butterknife.plugin.ButterKnifePlugin$_apply_closure1$_closure2$_closure3$_closure4.doCall(ButterKnifePlugin.groovy:32)
    at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:590)
    at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:571)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)

有人知道可能存在的问题是什么吗?

1 个答案:

答案 0 :(得分:0)

根据Github上的thisthis问题,看起来ButterKnife插件存在一些问题。

从插件中删除依赖项并将其关闭解决了这个问题。

// commented:
// apply plugin: 'com.jakewharton.butterknife'

不幸的是,除了这个插件之外,没有其他方法可以在库模块(连接为apply plugin: 'com.android.library')中使用ButterKnife,所以我将它从库模块中删除,然后像往常一样将它保留在主模块中依赖性:

annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0
provided 'javax.annotation:jsr250-api:1.0'
compile 'com.jakewharton:butterknife:8.6.0'