Gradle DSL method not found: 'main()'

557 Views Asked by At

syncing Gradle it gives the following error Error:(24, 0) Gradle DSL method not found: 'main()' Possible causes:

  • The project 'OcrAgainNew' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • "gradle.build"

    buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
       }
    }
    
    apply plugin: 'com.android.library'
    
    android {
    compileSdkVersion 23
    buildToolsVersion "21.1.2"
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
       }
    }
    
    sourceSets.main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        res.srcDirs = ['res']
        jniLibs.srcDirs = ['libs']
    }
    

    screenshot of my project

    2

    There are 2 best solutions below

    1
    On

    If you are using version 0.14.0 or higher of the gradle plugin, you should replace runProguard with minifyEnabled in your build.gradle files.

    0
    On

    You have to define the sourceSets block inside the android block

    android {
       compileSdkVersion 23
       buildToolsVersion "21.1.2"
       defaultConfig {
           minSdkVersion 15
           targetSdkVersion 23
       }
    
       sourceSets.main {
          manifest.srcFile 'AndroidManifest.xml'
          java.srcDirs = ['src']
          resources.srcDirs = ['src']
          res.srcDirs = ['res']
          jniLibs.srcDirs = ['libs']
       }
    }