問題背景: 最近在開始使用AndroidStudio3.0,剛好有一個開源的項目(Material-Movies),需要學習下。因為該項目比較早(2015年),而這段時間AndroidStudio和Gradle都升級了,所以就導致直接導入是編譯不通過的。好在AndroidStudio也智能,基本上都會有提示,可以按他的要求升級什么的。
問題描述:在對所有的升級都進行修改后,進行Sync已能成功編譯,但是一旦執行BuildAPK就會報錯。Execution failed for task ':app:compileDebugJavaWithJavac'
問題分析:按網上的說法,在命令行執行:
gradlew compileDebug --stacktrace
會發現如下:
exception is:
org.gradle.execution.TaskSelectionException: Task 'compileDebug' is ambiguous in root project 'HackVG'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl', 'compileDebugAndroidTestJavaWithJavac', '
compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndroidTestShaders', 'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac', 'compileDebugNdk', 'compileDebugRenderscript',
'compileDebugShaders', 'compileDebugSources', 'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources'.
然后網上各種搜索也搜索不出個所以然來。
問題的轉機出現在,無意看到
implementation 'com.jakewharton:butterknife:6.0.0'
annotationProcessor 'com.jakewharton:butterknife:6.0.0'
想起來在3.0之后編譯有修改過,由原來的APTplugin改為annotationProcessor. 然后implemet改為implementation。 如果只有anoatationProcessor編譯是能找到的,但是要build還是需要加implementationd的。
問題解決:需要添加成對
implementation 'com.google.dagger:dagger:2.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
原來漏了加
implementation 'com.google.dagger:dagger:2.0'
添加之后果然能夠解決。