android studio - 导入工程报错[Plugin with id 'com.android.application' not found]
出错现象:

大概意思是找不到:com.android.application 插件,以上现象对于初学者来说会经常碰到,下面分析下产生的原因。
原因分析
首先来看看导入后的工程结构:

对于此工程结构,是否有个疑问? 这是未正常同步完成的结构,Gradle Scripts下面似乎少了个 build.gradle ,上图红框部分描述清楚了是 Module: GraphicsDemo ,表示该 build.gradle 是Module的,而不是Project的。来看看一个正常的 Project+Module的工程是怎样的:

请注意红框位置,一个是Project, 一个是 Module 。这两个 build.gradle 究竟啥区别呢? 众所周知,Android Studio在组织工程结构的时候是以Project作为基础,可以在它的基础上创建多个Module,正如上图所示!不少开发人员在贡献自己的代码到Github或者CSDN下载频道的时候,就直接把Module 整个文件夹丟上去了,导致下载使用的人出现了上述错误现象。 究其原因,还是先了解下 两种类型 gradle文件的错用吧!
build.gradle(Project: xxxx)
该文件是整个工程编译的全局文件,优先级最高
源码如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
// 优先级最高的build文件,先于Module的build.gradle执行
buildscript {
repositories {
jcenter() //指定maven镜像,下同
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0' //指定classpath
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir //指定clean的时候清除掉指定目录
}
从上述的注释可以看出该文件的作用:
1. 编译工程最顶级的文件,优先级最高;
2. 指定maven仓库地址,gradle相关的包是从maven拉取下来的;
3. 指定 classpath,不然无法找到某些类,标题出现的问题就是这个原因。
build.gradle(Module: xxx)
该文件是某个Module编译时候用到的文件
源码如下:
//注意:Gradle是通过插件来区分是可执行的工程还是libiary工程,下面表示可执行工程
apply plugin: 'com.android.application'
android {
compileSdkVersion
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "mashen.graphicsdemo"
minSdkVersion
targetSdkVersion
versionCode
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
这里面的配置都是大家耳熟能详的了,重点看看第一行,apply plugin: ‘com.android.application’ 表示当前Module是可执行工程。 然而找不到这个插件,原因就是 com.android.application 来源于 com.android.tools.build:gradle:2.2.0 。 这下估计都明白了!
解决方案:
将build.gradle里面的配置脚本拷贝到Module下的 build.gradle里面,也就是下面的脚本:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
//注意:更换成自己的AS的版本
}
}
allprojects {
repositories {
jcenter()
}
}
查看gradle版本: Terminal —> gradle -v (前提是配置了环境变量)
本文转自:http://blog.csdn.net/seafishyls/article/details/53572939
android studio - 导入工程报错[Plugin with id 'com.android.application' not found]的更多相关文章
- android studio java工程 报错
作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱:313134555@qq.com E-mail: 313134555 @qq.com android studio java工程 ...
- android studio 导入工程问题总结
github上下了几个开源项目,在导入android studio时出现各种问题, 在网上查询各种资料后一一得以解决,现对个问题点进行简单的总结: 1. gradle project sync fai ...
- 导入android sdk samples工程报错"did you mean to use @+id instead of @+android:id?"
导入“D:\adt-bundle-windows-x86_64-20140702\sdk\samples\android-15”中的工程报错 did you mean to use @+id inst ...
- android studio使用部分报错处理
1.android studio 导入项目时Error:SSL peer shut down incorrectly 今天导入一个项目到studio,显示在下载一个一个1.1.0-rc4的东西. 过了 ...
- 【Android】 导入项目报错的解决方案
1.打项目的properties -->android 为其指一个运版本, 2.修改default properties 文件 ,改相应版本等级 3.选中项目,单击右键,选中properties ...
- android studio 9.png 报错
Eclipse里能正常运行,但是导入到Android Studio里就报如下的错误 百度了下,说有两种解决办法一种是改后缀名,还有一种是重新在Android Studio里画一下点9图片.但是这个项目 ...
- 解决小米手机Android Studio安装app 报错的问题It is possible that this issue is resolved by uninstalling an existi
问题描述 Android Studio升级到2.3版本之后,小米手机MIUI8不能运行Android Studio程序,报如下错误: Installation failed with message ...
- Android 解决小米手机Android Studio安装app 报错的问题It is possible that this issue is resolved by uninstalling an existi
Android Studio升级到2.3版本之后,小米手机MIUI8不能运行Android Studio程序,报如下错误: Installation failed with message Faile ...
- android 编译错误 Error:(1, 0) Plugin with id 'com.android.application' not found.
在导入一个项目时,由于它本身的gradle版本比较高,你试用比较旧版本的gradle时就报出Plugin with id 'com.android.application' not found.的错误 ...
随机推荐
- Java之——redis并发读写锁,使用Redisson实现分布式锁
原文:http://blog.csdn.net/l1028386804/article/details/73523810 1. 可重入锁(Reentrant Lock) Redisson的分布式可重入 ...
- 【shiro】使用shiro,点击页面请求总是302状态码
解决方法: 配置shiro中,将要求放过的地址后面加上后缀,这里是.htmls 因为web.xml中配置所有的页面都是放过的
- Atom 有什么优秀插件?
蓝色 ,主业三流青春校园小说作家兼反差萌段子手… 韦易笑等 130 人赞同 若是C / C++的话,我推荐ATOM的这几个插件主要用于代码补全,实时语法检测,以及代码格式调整,其实就是Clang的那一 ...
- IOS是否在项目中存在,所使用的反射那点事
NSClassFromString,NSSelectorFromString,isKingOfClass 1. NSClassFromString 这种方法推断类是否存在,假设存在就动态载入的,不存为 ...
- ylbtech-LanguageSamples-Security(安全)
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-Security(安全) 1.A,Security 示例(Sample) 返回顶部 “安 ...
- iOS:详解MJRefresh刷新加载更多数据的第三方库
原文链接:http://www.ios122.com/2015/08/mjrefresh/ 简介 MJRefresh这个第三方库是李明杰老师的杰作,这个框架帮助我们程序员减轻了超级多的麻烦,节约了开发 ...
- iOS:多线程同步加锁的简单介绍
多线程同步加锁主要方式有3种:NSLock(普通锁).NSCondition(状态锁).synchronized同步代码块 还有少用的NSRecursiveLock(递归锁).NSConditionL ...
- jQuery.toggleClass() 和detach()方法详解
一.toggleClass()函数: toggleClass()函数用于切换当前jQuery对象所匹配的每一个元素上指定的css类名.所谓"切换",就是如果该元素上已存在指定的类名 ...
- pip安装scrapy时报错:error: Unable to find vcvarsall.bat
网上一堆胡说八道的,请看微软官方文章: https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcv ...
- supervise 用来监控服务,自动启动
Atong介绍的这个工具,挺好用的.supervise 官方网站: https://cr.yp.to/daemontools.html cd /data/test cat test.c #includ ...