android studio不能运行项目新建项目出错,怎么办?

打开项目配置后发现报错:这是Gradle 版本太低与java 环境不兼容导致的更改Gradle版本:在这里将版本调高点,我这里改为8.0,与自己原来创建项目的版本一致:调整完记得点击Apply接下来调整Modules:同样,调整完点击Apply接着在Suggestions中调整:Apply后点击OK,发现配置中再次报错:修改这里:之后点击上方Try Again:如果还出现下方错误:再加两行代码:运行后仍然报错:再次调整:接下来就可以成功加载了:如果还遇到下面的问题,则继续按提示操作:至此,Android Studio项目打开报错的问题就彻底解决啦。
}
报错信息org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: A problem occurred configuring root project 'Test1'.
Caused by: org.gradle.internal.exceptions.LocationAwareException: A problem occurred configuring root project 'Test1'
Caused by: org.gradle.internal.exceptions.LocationAwareException: A problem occurred configuring root project 'Test1'
##解决方法把项目的build.gradle 里的buildscript 和allprojects 改成下面的配置这是原来的配置改为如下代码:buildscript {
repositories {
// maven库
def cn = "http://maven.aliyun.com/nexus/content/groups/public/"
def abroad = "http://central.maven.org/maven2/"
// 先从url中下载jar若没有找到,则在artifactUrls中寻找
maven {
url cn
artifactUrls abroad
}
maven { url "http://maven.aliyun.com/nexus/content/repositories/jcenter"}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
// maven库
def cn = "http://maven.aliyun.com/nexus/content/groups/public/"
def abroad = "http://central.maven.org/maven2/"
// 先从url中下载jar若没有找到,则在artifactUrls中寻找
maven {
url cn
artifactUrls abroad
}
maven { url "http://maven.aliyun.com/nexus/content/repositories/jcenter"}
google()
}
}
}
前言:自从用上Android studio 之后,遇到各种gradle 的问题,前一段时间,把我经常遇到的问题总结了一下 ,大部分问题是Google 查到了,亲测可用之后,总结分享出来。也感谢这些前辈们处理完这些问题留下的宝贵经验总结。1. Gradle DSL method not found runProguard()从字面就能看出来,出现这个问题的原因是找不到runProguard()这个方法了(调用这个方法的地方在每个Module对应的build.gradle文件中)。 这是因为,当Android Studio升级时,也自动的将项目下的build.gradle文件(不是Module对应的build.gradle!)下的内容修改成了:
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0-rc4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}而升级之前是这样的(以我的电脑为例,应该是类似的):
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
显然,最简单的解决方法是将gradle的版本改回去,此方法可能的确有效。 但是,这种做法显然不是最好的方法。查阅官方文档之后(http://tools.android.com/tech-docs/new-build-system)之后发现,在新版本的gradle中,runProguard这个方法已经废弃了,并且改为新的方法了:minifyEnabled. 因此,正确的解决方法不是修改gradle的版本号,而是将项目中每个Module对应的build.gradle文件中的runProguard方法名改为minifyEnabled,即:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}问题完美解决。2. Error Plugin with id android-apt not found.note解决办法:删除 Plugin with id ‘android-apt’ not found3. Could not find property outputFile on com android build gradle.noteAndroid studio从1.0 RC 4升级到1.0(其实就是打了一个8M的patch)后,这个时候相应的gradle的版本也会直接使用“com.android.tools.build:gradle:1.0.0”,如果这时你在gradle文件中又用到outputFile就会出现上述的问题。好吧,其实这也是gradle团队搞的问题,有时候我们多希望gradle能像android一样,对旧版本有一个非常好的兼容性。 废话不多说,直接说怎么解决这个问题吧,这个问题的原因是outputFile这个函数被换地方了。 old:applicationVariants.all { variant ->
......
variant.outputFile = new File(variant.outputFile.parent, name);
......
}
}new: applicationVariants.all { variant ->
......
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, name);
......
}
}按上述方式改就ok了。4. Gradle DSL method not found android().note解决方法: 删掉最外层的build.gradle中的android {
compileSdkVersion 19
buildToolsVersion '21.1.1'
}后续问题总结将继续更新}

我要回帖

更多关于 android studio不能运行项目 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信