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

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.