问题1: Error:(1, 0) Plugin with id ‘com.android.application’ not found
Latest Gradle: 2.8
Check with: gradle -v
Download here: http://services.gradle.org/distributions/gradle-2.8-bin.zip
Latest Android Build Tools: 1.3.1
If you add the following code snippet to the top of your build.gradle file, gradle will update the build tools.
Read more here: http://tools.android.com/tech-docs/new-build-system
问题2: Error:Cause: failed to find target with hash string ‘android-xx’ in: C:\xxx
Android Studio 在加载OpenCV库时, 会出现报错: “failed to find target android-xx”,修改app文件夹中的build.gradle文件即可. 把SdkVersion改为使用的SDK, 如19.
修改步骤:
- Flie — Project structure — Modules — Compile Sdk Version(选中本地可用的SDK版本)
- 对应修改build.gradle123456android {compileSdkVersion 20buildToolsVersion '20.0.0' //与本地版本相对应... ...}
问题3:android studio在编译的时候提示非法字符。
这种问题一边都是文件编码的问题,需要注意的是即使是UTF-8的编码也是分有BOM和无BOM编码的,一般提示非法字符是因为有BOM编码引起的。解决方式是点击选中有问题的文件,ctr+shif+c复制该文件的路径,然后在notepad中ctr+o打开这个文件,在格式中,选择无BOM的UTF-8编码保存,工程刷新即可。
问题4:Android studio常量表达式的错误。
在switch语句的case中,如果使用 R.id.xxx 则会提示有问题,不允许非常量在case语句中。
这个错误在eclipse下并没有,但是AS中会报这个错,是switch case的问题,解决方法是将switch换成if else
在AS中我们使用Alt+Enter(opt+Enter for Mac)快捷键直接将switch转换为if else,如下图所示: