Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> AndroidStudio初體驗:解決Execution failed for task ':TestAndroid:compileDebug'.

AndroidStudio初體驗:解決Execution failed for task ':TestAndroid:compileDebug'.

編輯:關於Android編程

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通過!

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved