1

I was trying to include this library to my current project following the method suggested here This resulted in breaking down my project and I am getting the following error at the build.gradlle file of the library error Here is the build.gradle of the project (updated):

// 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:1.2.3'

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

subprojects {
    ext.global_compileSdkVersion = 22
    ext.global_buildToolsVersion = "23.0.0 rc2"
}

build.gradle for the app module:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.android.application'

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

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

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc2"
}

subprojects {
    ext.global_compileSdkVersion = 22
    ext.global_buildToolsVersion = "23.0.0 rc2"
}

and the build.gradle for the library I am trying to add:

    /*
*    Copyright (C) 2015 Haruki Hasegawa
*
*    Licensed under the Apache License, Version 2.0 (the "License");
*    you may not use this file except in compliance with the License.
*    You may obtain a copy of the License at
*
*        http://www.apache.org/licenses/LICENSE-2.0
*
*    Unless required by applicable law or agreed to in writing, software
*    distributed under the License is distributed on an "AS IS" BASIS,
*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*    See the License for the specific language governing permissions and
*    limitations under the License.
*/

apply plugin: 'com.android.library'

ext {
    // required for 'android-maven-publish.gradle'
    mavenPublishDestDir = new File(rootDir, "repository").absolutePath
    mavenPublishDataFile = file('./library-data.properties').absolutePath
    mavenPublishSigningSetting = file('../signing/library-maven-publish-signing.properties').absolutePath
}

// Common configurations

android {

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 22

        def dataProps = new Properties()
        dataProps.load(project.file(project.mavenPublishDataFile).newDataInputStream())

        versionCode dataProps.VERSION_CODE.toInteger()
        versionName dataProps.VERSION_NAME
    }
    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
            consumerProguardFiles 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            shrinkResources false
            consumerProguardFiles 'proguard-rules.pro'
        }
    }
} apply plugin: 'java'

dependencies {
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
}

tasks.withType(JavaCompile) {
    options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
}

and settings.gradle

include ':app', ':advancedRecyclerView'

What is it that I am doing wrong?

Community
  • 1
  • 1
A_Matar
  • 2,210
  • 3
  • 31
  • 53

2 Answers2

4

This is not an answer for the OP, but may be of use to others who get the error

Gradle DSL method not found: 'apply()'

In my case the problem turned out to be the encoding of the build.gradle file. I had edited the file in a text editor and it got saved as UTF-8-BOM, which Gradle apparently doesn't accept. So the solution was simply to re-save the file in ANSI or UTF-8 (without BOM) encoding.

RenniePet
  • 11,420
  • 7
  • 80
  • 106
1

First of all, you can't use the apply plugin in your top-level file.
Then remove this line

apply plugin: 'com.android.application'

The best way to use this library in your project is to import it as a maven dependency without cloning the code locally.

compile 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.7.4'

You should have a structure like this:

root
  app
    build.gradle
  build.gradle
  settings.gradle

In settings.gradle

include ':app'

In top-level build.gradle

// 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:1.3.0'

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

allprojects {
    repositories {
        jcenter()
    }
}

In app/build.gradle

apply plugin: 'com.android.application'

android {
    defaultConfig {
      //....
    }

    //....

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    //Add the library
    compile 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.7.4'
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841