tglr
tglr

Reputation: 41

Could not find method defaultConfig() - Android Studio

I recently (3 days ago) started learning Android Studio. I bought an Eclipse game project to play with, but I am getting errors. And when I fix that error, I get a new error.

The current one that I can't seem to fix is:

Error:(2, 0) Could not find method defaultConfig() for arguments [build_2ttwbw07u5v666j5nx2ciclk3$_run_closure1@5ac759e5] on project ':app' of type org.gradle.api.Project. Open File

My build.gradle (Module: App):

defaultConfig {
        applicationId "com.getemplate.catadventure"
        minSdkVersion 14
        targetSdkVersion 26

        sourceSets.main {
            jniLibs.srcDir 'src/main/libs'
            jni.srcDirs = [] //disable automatic ndk-build call
        }

        ndk {
            moduleName "player_shared"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }


android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    dexOptions {
        preDexLibraries = false
    }
}

dependencies {
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/dagger-1.2.2.jar')
    compile files('libs/javax.inject-1.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    compile files('libs/support-v4-19.0.1.jar')
}

Anyone know why I am getting the error?

Here's a screenshot: screenshot error

Thank you very much for your time and assistance in this matter.

Upvotes: 1

Views: 8078

Answers (1)

ישו אוהב אותך
ישו אוהב אותך

Reputation: 29844

This is because you didn't add code for android application plugin which is apply plugin: 'com.android.application'. You also need to move the defaultConfig inside the android like this:

apply plugin: 'com.android.application'

android {

  compileSdkVersion 26
  buildToolsVersion "26.0.3"

  defaultConfig {
   ...
  }

}

dependencies {
  ...
}

Upvotes: 3

Related Questions