2017-04-05 1 views
1

Ich bin neu in Android-Programmierung finden, wenn ich versuche, mein erstes Projekt zu bauen, bekomme ich folgende Fehler -Gradle Sync fehlgeschlagen: Es kann keine Methode android() für Argumente auf Stammprojekt auf Android Studio

Gradle-Synchronisierung fehlgeschlagen: Die Methode android() für Argumente [build_ed74sxwq3zd69j7x0p9x4y5fb $ _run_closure3 @ 3d54d64f] für das Stammprojekt 'MyApplication' vom Typ org.gradle.api.Project konnte nicht gefunden werden.

// Top-level build file where you can add configuration options common to all sub-projects/modules. 
 
buildscript { 
 
    repositories { 
 
     jcenter() 
 
    } 
 
    dependencies { 
 
     classpath 'com.android.tools.build:gradle:2.3.0' 
 

 
     // 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 
 
} 
 

 
android { 
 
    compileSdkVersion 19 
 
    buildToolsVersion '25.0.2' 
 
    dexOptions { 
 
     incremental true 
 
    } 
 
    compileOptions { 
 
     sourceCompatibility JavaVersion.VERSION_1_6 
 
     targetCompatibility JavaVersion.VERSION_1_6 
 
    } 
 
} 
 
dependencies {compile files('app/libs/junit-4.12-JavaDoc.jar') 
 
} 
 
apply plugin: 'maven'

Die App/build/gradle Datei -

apply plugin: 'com.android.application' 
 

 
android { 
 
    compileSdkVersion 25 
 
    buildToolsVersion "25.0.2" 
 
    defaultConfig { 
 
     applicationId "com.surabhi.myapplication" 
 
     minSdkVersion 15 
 
     targetSdkVersion 25 
 
     versionCode 1 
 
     versionName "1.0" 
 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
 
     externalNativeBuild { 
 
      cmake { 
 
       cppFlags "-std=c++11" 
 
      } 
 
     } 
 
    } 
 
    buildTypes { 
 
     release { 
 
      minifyEnabled false 
 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
 
     } 
 
    } 
 
    externalNativeBuild { 
 
     cmake { 
 
      path "CMakeLists.txt" 
 
     } 
 
    } 
 
} 
 

 
dependencies { 
 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
 
     exclude group: 'com.android.support', module: 'support-annotations' 
 
    }) 
 
    compile 'com.android.support:appcompat-v7:25.3.1' 
 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
 
    compile 'com.android.support:design:25.3.1' 
 
    testCompile 'junit:junit:4.12' 
 
    compile files('app/libs/junit-4.12-JavaDoc.jar') } 
 
    apply plugin: mavin

Antwort

1

Sie verwenden die falschbuild.gradle Datei.

Sie können den android Block in der Top-Level-Datei nicht definieren.

Sie haben dieser Teil in Ihrem i

android { 
    compileSdkVersion 19 
    buildToolsVersion '25.0.2' 
    dexOptions { 
     incremental true 
    } 
    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_6 
     targetCompatibility JavaVersion.VERSION_1_6 
    } 
} 
dependencies {compile files('app/libs/junit-4.12-JavaDoc.jar') 
} 
apply plugin: 'maven' 
0

zu entfernen hatte das gleiche Problem in Android Studio 2.3.3, was ich falsch mache, ist, dass meine Abhängigkeiten in der falschen build.gradle waren (das ist falsch) enter image description here

die build.gradle, die wir brauchen, ist das mit der android-Option, wie im folgenden `gilt Plugin: 'com.android.application'

android { compileSdkVersion 23 buildToolsVersion '23 .0.0'

defaultConfig { 
    applicationId "com.movas.mservice12" 
    minSdkVersion 9 
    targetSdkVersion 23 
    versionCode 11 
    versionName "2.0" 
    multiDexEnabled true 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
lintOptions { 
    abortOnError false 
} 
dexOptions { 
    // incremental = true 
    preDexLibraries = false 
    javaMaxHeapSize "4g" // 2g should be also OK 
} 

} ` folgen, wo Sie die dexOptions hinzufügen ist im Inneren der android geschweiften Klammern.

Verwandte Themen