Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了缺少android.compileSdkVersion!错误gradle build大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试构建我的库并将其上传到存储库,但不幸的是gradle构建失败.我花了几个小时试图修复这个错误,但我尝试的没有任何帮助.
这是我从根项目目录的build.gradle.
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()
    }
}

和我的模块目录中的build.gradle

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.
//            }
        }
    }
}

我还在local.properties文件添加了一些配置

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

bintray.gpg.password=####
bintray.osS.User=####
bintray.oss.password=####

问题是我在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)

错误消息输出结束时,我得到了以下内容

* 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

解决方法

与“编译sdk版本”相关的此错误是因您使用的是Gradle 2.4

检入您的Android studio偏好设置并搜索Gradle.如果您选中了“使用本地gradle发行版”,请查看版本并尝试更改为“使用认gradle包装器(推荐)”

现在,如果那不起作用.检查项目结构,在“项目”选项中可能使用“Gradle版本2.4”,因此设置为2.2.1

在最糟糕的情况下,您可能正在使用控制台,因此请运行:gradle –version并检查您的gradle版本.

尽量避免使用“Gradle 2.4”,因为它存在与Android studio中某些任务相关的问题.

大佬总结

以上是大佬教程为你收集整理的缺少android.compileSdkVersion!错误gradle build全部内容,希望文章能够帮你解决缺少android.compileSdkVersion!错误gradle build所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。