AS(Android studio)常见问题

来源:互联网 发布:淘宝网晚礼服 编辑:程序博客网 时间:2024/05/17 00:08

1.JUnit 找不到问题

JUnit是一个Java语言的单元测试框架,在as gradle编译的时候需要引入单元测试的东西,因此需要引用这个jar包。

以前一直用Eclipse开发Android,最近准备用用Android Studio好不容易配置完了,新建了个工程竟然是有错误

Error:A problem occurred configuring project ':app'.
> Could not download junit.jar (junit:junit:4.12)
   > Could not get resource 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.jar'.
      > Could not GET 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.jar'.
         > peer not authenticated


翻墙下载了junit-4.12.jar,才创建成功。然后我找到了junit-4.12.jar的文件路径,大家再遇到这个问题,也不想麻烦去翻墙,可以直接下载一个junit-4.12.jar,放到自己的Android Studio的相应目录中,然后重启android studio就可以了。

1.找到自己android studio 的安装目录,下面是我自己的android studio安装目录:D:\Android\Android Studio\

2.把junit-4.12.jar放到D:\Android\Android Studio\gradle\gradle-2.4\lib\plugins\目录下就ok了。


或者将中间代码注释掉

dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    //testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:23.3.0'}
2.解决Android studio Instance Run 错误(Tools | Android | Enable ADB integration' to be enabled)
研究了一下Instant Run是Android Studio 2.0新加入的功能,可以快速部署代码的更改到模拟器/手机上,不用像之前一样等半天。
可以在设置里把Instant Run打开或者关掉,设置地方如下图:

这个开关要是打开,那么在 Tools - Android - Enable ADB Integration 也需要打开



3.解决 Android studio 导入jar 问题
在 app/build.gradle文件中如果引入 
compile fileTree(dir: 'libs', include: ['*.jar'])   那么jar文件是直接可以放置在libs文件下。
在 AS 中引入jar有几种方式:1.引入Android studio安装目录中的lib文件夹中的库,常见的有annotation,junit等。2.就是gradle下载的,如:
compile 'com.google.android.gms:play-services:9.8.0' 3.sdk中下载的jar 4.工程目录下libs文件夹中的jar. 
4.Your project path contains non-ASCII characters. This will most likely cause the build to fail on Windows. Please move your project to a different directory. 
See http://b.android.com/95744 for details. This warning can be disabled by using the command line flag -Dcom.android.build.gradle.overridePathCheck=true, 
or adding the line com.android.build.gradle.overridePathCheck=true' to gradle.properties file in the project directory.
其实很好解决啦,就是你的工程项目路径或者项目名称包含了中文,修改相关的名称就好了!
5. 运行Android studio工程

Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException: 

org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-oracle/bin/java'' 

finished with non-zero exit value 2

这个问题可能是jar包的重复导入也有可能是方法数溢出。 加上  multiDexEnabled true 

[java] view plain copy
  1. defaultConfig {  
  2.         applicationId ""  
  3.         minSdkVersion 14  
  4.         targetSdkVersion 21  
  5.         versionCode 19  
  6.         versionName "1.2.7"  
  7.         // dex突破65535的限制  
  8.         multiDexEnabled true  
  9.     }  

0 0
原创粉丝点击