简体   繁体   中英

gradle class cast exception: cannot cast to 'java.lang.iterable'

I have an android project for which I am writing a build.gradle file. I have some dependency library projects as well which will reside in the root folder. So the structure of the folders will be something like the following,

RootFolder: Test Project, Some library Project, Project 3 and Project 4.

And my build.gradle looks like this,

buildscript {

    repositories {
        mavenCentral()
    }

    dependencies {

        classpath 'com.android.tools.build:gradle:0.12.+'       

    }

}

apply plugin: 'android'

dependencies {

    compile 'com.android.support:support-v4:18.0.+'
    compile project(':test-library')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')

}

ext {

    project.sourcecompatibility = "1.6"
    project.targetcompatibility = "1.6"

}

// ========================================
// Android Plugin
// ========================================

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"


    defaultConfig {
        versionName "1.1"
        minSdkVersion 8
        targetSdkVersion 19

    }

    lintOptions {

        abortOnError false

    }

    sourceSets {

        main {

            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = {'src'}
            resources.srcDirs = {'src'}
            aidl.srcDirs = {'src'}
            renderscript.srcDirs = {'src'}
            res.srcDirs = {'res'}
            assets.srcDir = {'assets'}

        }       

    }


    buildTypes {

        debug {
            debuggable = true
            zipAlign = false
        }


        release {           
            debuggable = false
            zipAlign = true
        }

    }
}

And I am getting the following error,

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/someuser/Desktop/Gradle Testing Projects/TestProject_GradleTest/build.gradle' line: 75

* What went wrong:
A problem occurred evaluating root project 'TestProject_GradleTest'.
> Cannot cast object 'build_23rtd5r6a61l25hprb7evd7kna$_run_closure3_closure6_closure8_closure9@22a92801' with class 'build_23rtd5r6a61l25hprb7evd7kna$_run_closure3_closure6_closure8_closure9' to class 'java.lang.Iterable'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

I dont understand why am I getting classcastexception and how should I fix it? Thanks in advance.

Nevermind, it was sourceset issue.

 manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = {'src'}
            resources.srcDirs = {'src'}
            aidl.srcDirs = {'src'}
            renderscript.srcDirs = {'src'}
            res.srcDirs = {'res'}
            assets.srcDir = {'assets'}

should look like the following,

  manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDir = ['assets']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM