android studio常见错误

时间:2021-11-25 10:09:12

1、Failed to import new Gradle project: Could not install Gradle distribution from'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.

问题原因:中国连接gradle的地址被强了

解决方案:修改android studio设置Http Proxy->Auto-detect proxy settings

2、编译时报错“Compilation completed with 2 errors and 0 warnings in 9 sec
Gradle: 
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':teston:packageDebug'.
> org.bouncycastle.asn1.ASN1Integer.<init>(J)V

* 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 distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.”

问题原因:引用了第三方包,未导入

解决方案:在build.gradle的

dependencies {
compile files('libs/android-support-v4.jar')}

中导入既可;

问题原因:代码中包涵了中文,导致编译时出现不可映射字符

解决方案:在build.gradle中加入

tasks.withType(Compile){
options.encoding='UTF-8'
}

编码定义即可;