在intellij 16中创建Android应用时,Gradle同步失败
我在ubuntu 14.04 LTS上使用Intellij IDEA 2016.3.4开发android应用程序。 错误gradle sync failed, missing android extension is occurring.
我使用sdk平台25.0.2,kotlin版本1.0.6。 这是抛出一个错误的行:
apply plugin: 'kotlin-android'
并且错误信息是:
错误:(16,0)名称为“android”的扩展名不存在。 当前注册的扩展名:[ext]打开文件
我迷路了。 请任何人都可以帮我。 详细的解决方案将不胜感激!
编辑1:这是build.gradle代码
apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.example.gogol.myapplication" minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.0', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.1.1' testCompile 'junit:junit:4.12' }
编辑2:这里是build.gradle根项目
//顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。
buildscript { ext.kotlin_version = '1.0.6' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } apply plugin: 'kotlin-android' allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } repositories { mavenCentral() } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile 'com.android.support:appcompat-v7:25.1.1' compile 'com.android.support:support-annotations:25.1.1' } android { sourceSets { main.java.srcDirs += 'src/main/kotlin' } compileSdkVersion 25 buildToolsVersion '25.0.2' }
在您的根build.gradle文件中添加apply plugin: 'android'
。
之后,你的build.gradle文件看起来像
buildscript { ext.kotlin_version = '1.0.6' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } apply plugin: 'android' apply plugin: 'kotlin-android' allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } repositories { mavenCentral() } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile 'com.android.support:appcompat-v7:25.1.1' compile 'com.android.support:support-annotations:25.1.1' } android { sourceSets { main.java.srcDirs += 'src/main/kotlin' } compileSdkVersion 25 buildToolsVersion '25.0.2' }
- Gradle构建中未解决的Kotlin扩展函数的引用
- Gradle – 以非零退出值完成1
- 在org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated找不到属性’run’
- 在Gradle usin Kotlin中构建JAXB类
- Android Studio 3.1 Canary 3上的Gradle同步错误
- Kotlin的gradle插件不适用于自定义源集(JMH)
- 制作模块化Gradle项目的最佳方法
- 在Spring Boot项目中使用Gradle从Kotlin测试引用Java代码时未解决的参考
- kotlin-gradle插件自动配置错误