Execution failed for task ':TestAndroid:compileDebug'.
有各種各樣原因,具體就請自己進cmd編譯看什麼地方出錯
進入項目的gradle檔案所在目錄打
gradlew compileDebug --stacktrace
來追蹤就可以啦~
昨天編譯的時候出現了問題,具體問題具體解決!
Gradle:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':TestAndroid:compileDebug'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Could not execute build using Gradle installation 'C:\gradle-1.6'.
首先進入命令列
進入項目根目錄(gradule檔案所在目錄)
輸入命令
gradlew compileDebug --stacktrace
查看錯誤位置:
錯誤如下
=================================================================
C:\Users\Administrator\AndroidStudioProjects\TestAndroid\TestAndroid\src\main\ja
va\com\example\testandroid\MainActivity.java:125: 警告:編碼 GBK 的不可映射字元
//淇濆瓨褰撳墠璁$畻緇撴灉錛屼笅嬈℃墦寮?仮澶?
SharedPreferences settings = getSharedPreferences(PROFILE_
NAME,Activity.MODE_PRIVATE);
^
C:\Users\Administrator\AndroidStudioProjects\TestAndroid\TestAndroid\src\main\ja
va\com\example\testandroid\MainActivity.java:125: 警告:編碼 GBK 的不可映射字元
//淇濆瓨褰撳墠璁$畻緇撴灉錛屼笅嬈℃墦寮?仮澶?
SharedPreferences settings = getSharedPreferences(PROFILE_
NAME,Activity.MODE_PRIVATE);
^
C:\Users\Administrator\AndroidStudioProjects\TestAndroid\TestAndroid\src\main\ja
va\com\example\testandroid\MainActivity.java:126: 找不到符號
符號: 變數 settings
SharedPreferences.Editor editor = settings.edit();
^
1 錯誤
:TestAndroid:compileDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':TestAndroid:compileDebug'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':TestAnd
roid:compileDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec
uter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskE
xecuter$1.run(CacheLockReleasingTaskExecuter.java:35)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def
aultCacheAccess.java:179)
=======================================================
因循錯誤應該是編碼問題
125行用了中文注釋
因為Gradle預設編譯採用了GBK,但是java檔案中的注釋中文用UTF-8
所以有問題
設定Gradle的編譯編碼即可:
具體方法
開啟項目結構
structure
開啟gradle檔案
加入
//設定編碼
tasks.withType(Compile) {
options.encoding = "UTF-8"
}
然後再次運行命令列查看有錯不
如果不行檢查自己的java檔案編碼
換成UTF-8
再編譯 OK通過!