2017-05-07 127 views
0

我使用下面的腳本在我目前的Android項目的Android工作室::搖籃腳本錯誤的Android()

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

android { 
    compileSdkVersion 11 
    buildToolsVersion "11.0" 

    defaultConfig { 
     applicationId "com.stackoverflow.answer" 
     minSdkVersion 11 
     targetSdkVersion 11 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.2' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
     maven { url 'https://jitpack.io' } 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

但後來發現此錯誤消息。 This error

如何解決這個問題?

回答

0

android塊應位於包含apply plugin: 'com.android.application'的模塊build.gradle之內,而不在build.gradle文件中。

實施例:

build.gradle

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.2' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
     maven { url 'https://jitpack.io' } 
    } 
} 

模塊build.gradle(可能是app文件夾中):

apply plugin: 'com.android.application' 


android { 
    compileSdkVersion 11 
    buildToolsVersion "11.0" 

    defaultConfig { 
     applicationId "com.stackoverflow.answer" 
     minSdkVersion 11 
     targetSdkVersion 11 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 
相關問題