Getting android.compileSdkVersion is missing! error gradle build

I am trying to build my library and upload it to the repository, but unfortunatly gradle build fails. I have spent several hours trying to fix this error, but nothing what I tried didn’t help.
Here is my build.gradle from root project dir.

buildscript {
    repositories {
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'com.github.dcendents:android-maven-plugin:1.2'
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1"
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

And build.gradle from my module directory

apply plugin: 'com.android.library'
apply plugin: "com.jfrog.bintray"
apply plugin: 'com.github.dcendents.android-maven'
version = "1.0.0"
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 21
        versionCode 1
        versionName "1.0.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
def siteUrl = 'https://github.com/CROSP/AndroidHorizontalRecyclerView'      // Homepage URL of the library
def gitUrl = 'https://github.com/CROSP/AndroidHorizontalRecyclerView.git'   // Git repository URL
group = "com.github.crosp.horizontalrecyclerview"                      // Maven Group ID for the artifact

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.jsoup:jsoup:1.8.1'
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.android.support:recyclerview-v7:21.0.3'

}
install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'

                // Add your description here
                name 'Android Horizontal Recycler View with Headerr'
                description = 'Android Horizontal Recycler View with Header project for displaying horizontal list on Android '
                url siteUrl

                // Set your license
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id 'crosp'
                        name 'Alexandr Crospenko'
                        email 'crosp@ukr.net'
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl

                }
            }
        }
    }
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}
artifacts {
    archives javadocJar
    archives sourcesJar
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

// https://github.com/bintray/gradle-bintray-plugin
bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    configurations = ['archives']
    pkg {
        repo = "maven"
        // it is the name that appears in bintray when logged
        name = "crosp"
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
        version {
            gpg {
                sign = true //Determines whether to GPG sign the files. The default is false
                passphrase = properties.getProperty("bintray.gpg.password") //Optional. The passphrase for GPG signing'
            }
//            mavenCentralSync {
//                sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
//                user = properties.getProperty("bintray.oss.user") //OSS user token
//                password = properties.getProperty("bintray.oss.password") //OSS user password
//                close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
//            }
        }
    }
}

Also I have added some configurations into my local.properties file

sdk.dir=/home/crosp/Android/Sdk
bintray.user=####
bintray.apikey=####

bintray.gpg.password=####
bintray.oss.user=####
bintray.oss.password=####

The problem is that I get following error after gradle bintrayUpload.

Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
java.lang.IllegalArgumentException: android.compileSdkVersion is missing!
at com.android.build.gradle.internal.SdkHandler.initTarget(SdkHandler.java:80)

And at the end of error message output I get following

  * Where:
    Build file '/home/crosp/AndroidStudioProjects/HorizontalList/horizontalrecyclerview/build.gradle' line: 3
    
    * What went wrong:
    A problem occurred evaluating project ':horizontalrecyclerview'.
    > org/gradle/api/publication/maven/internal/DefaultMavenFactory

Configuration ordering with the Android plugin is a bit funky. I’m almost certain it’s the call to android.getBootClasspath() that’s the cause of this issue. You may have to defer that configuration. Perhaps try putting it inside an afterEvaluate { } block.

1 Like

Thank you for answer, what should I put inside afterEvaluate { } ? This line classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) ?

I have exlored an error with stacktrace and it gives following.

You’ll probably have to put the whole javadoc task declaration in that block.

1 Like
artifacts {
  //  archives javadocJar
    archives sourcesJar
}

I have just tried to comment javadoc artifact, but this didn’t help , still the same error.

I have just changed dependencies to

  dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
        classpath 'com.github.dcendents:android-maven-plugin:1.2'
    }

Now got following output

gradle bintrayUpload
Download https://jcenter.bintray.com/org/ow2/asm/asm-analysis/4.0/asm-analysis-4.0.pom
Download https://jcenter.bintray.com/com/android/tools/external/lombok/lombok-ast/0.2.2/lombok-ast-0.2.2.pom
Download https://jcenter.bintray.com/org/ow2/asm/asm-tree/4.0/asm-tree-4.0.pom
Download https://jcenter.bintray.com/org/ow2/asm/asm-analysis/4.0/asm-analysis-4.0.jar
Download https://jcenter.bintray.com/com/android/tools/external/lombok/lombok-ast/0.2.2/lombok-ast-0.2.2.jar
Download https://jcenter.bintray.com/org/ow2/asm/asm-tree/4.0/asm-tree-4.0.jar

FAILURE: Build failed with an exception.

* Where:
Build file '/home/crosp/AndroidStudioProjects/HorizontalList/horizontalrecyclerview/build.gradle' line: 3

* What went wrong:
A problem occurred evaluating project ':horizontalrecyclerview'.
> org/gradle/api/publication/maven/internal/DefaultMavenFactory

Using stacktrace option gives the same error as it was earlier .

Caused by: java.lang.NoClassDefFoundError: org/gradle/api/publication/maven/internal/DefaultMavenFactory

What version of Gradle are you using to build your project. That class was moved to a different package in Gradle 2.4. My guess is one of your plugins (the ‘android-maven-plugin’ sound suspect) is referencing this Gradle internal class that has moved.

1 Like

Current version of gradle is 2.4
Should I install <2.4 version ?

You should be using the Gradle Wrapper. Currently the Android Gradle plugin isn’t fully compatible with Gradle 2.4. I’d suggest you update you update the ‘gradle-wrapper.properties’ file to point at Gradle 2.3.

1 Like

Thank you a lot for your help, I am going to try it now

AWESOME !!! Thank you very much you saved my time !!!
I have just build my project with gradlew executable file located in my project directory and everything built successfully !!
Thank you very much again.
One last question, my library has some dependencies from repos , for example

compile 'com.android.support:appcompat-v7:22.1.1’
compile ‘com.android.support:recyclerview-v7:21.0.3’

What is correct way to add this dependencies into my library, because I get :

error: cannot find symbol

Thank you.
Or maybe I have to download libraries and put them into my directory ?

Can you give some more context? There must be more to that error. Also, where are you adding the dependencies in your script?

1 Like

It pretended to be ok now, I have just rebuild project, dependencies are, of course, defined in build.gradle.
Thank you very much for your help !! Sorry for such questions, I am newbie in gradle. But I’ve realised that it a great tool and I am goind to learn it deeply.
Thank you.