在intellij 16中创建Android应用程序时,Gradle同步失败

时间:2017-02-19 16:29:51

标签: android intellij-idea 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'
 }

1 个答案:

答案 0 :(得分:1)

在root 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'
}