android studio 编译调试 错误

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

阅读更多
个人分类: Android
上一篇浅谈下Android Studio Build选项的功能
下一篇Android Building System 分析
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭