1. 程式人生 > >android studio專案換電腦後重新執行報的莫名其妙的錯誤Gradle DSL method not found: 'apply()

android studio專案換電腦後重新執行報的莫名其妙的錯誤Gradle DSL method not found: 'apply()

報錯型別

Error:(1, 0) Gradle DSL method not found: ’apply()’
Possible causes:

或者

Error:(1, 0) startup failed:
build file ‘D:\ASworkspace\GgAndBd\build.gradle’: 1: Invalid variable name. Must start with a letter but was: 
. At [1:1] @ line 1, column 1.
//Top-level build file where you can add configuration options common to all sub-projects/modules.
^
1 error
Open File

按照as提供的建議,嘗試無果後,繼續翻stackoverflow,找到一種解決方式。
解決方法:

https://stackoverflow.com/questions/40434400/could-not-find-method-apply-for-arguments
I have solved this problem! Here is my may:
1.copy the contetn of “build.gradle”,then delete the “build.gradle”;
2.create a new build.gradle and paste the previous content to this “build.gradle”
That’s all !

即:刪除專案跟節點的全域性build.gradle檔案(先複製出其中的內容),再在as中新建一個該檔案,將之前的內容貼上進來,重新“try again”。看來是檔案編碼格式引起,可是看了下as預設都是UTF-8呀,所以不知道報錯緣由。