UnsupportedOperationException" android" SDK

时间:2017-03-15 09:57:24

标签: android android-studio android-gradle kotlin build-tools

我在Kotlin中有项目,我已将Android Studio更新为2.3.3,将gradle更新为3.3,并将工具更新为25.3.1。在建设过程中我遇到了这个错误:

Caused by: java.lang.UnsupportedOperationException: The "android" command is no longer included in the SDK. Any references to it (e.g. by third-party plugins) should be removed.
        at com.android.SdkConstants.androidCmdName(SdkConstants.java:1947)
        at com.android.SdkConstants$androidCmdName$0.callStatic(Unknown Source)
        at com.jakewharton.sdkmanager.internal.AndroidCommand$Real.<init>(AndroidCommand.groovy:21)
        at com.jakewharton.sdkmanager.internal.PackageResolver.resolve(PackageResolver.groovy:22)
        at com.jakewharton.sdkmanager.internal.PackageResolver$resolve.call(Unknown Source)
        at com.jakewharton.sdkmanager.SdkManagerPlugin$_apply_closure2$_closure3.doCall(SdkManagerPlugin.groovy:44)
        at com.jakewharton.sdkmanager.SdkManagerPlugin$_apply_closure2$_closure3.doCall(SdkManagerPlugin.groovy)
        at com.jakewharton.sdkmanager.SdkManagerPlugin.time(SdkManagerPlugin.groovy:51)
        at com.jakewharton.sdkmanager.SdkManagerPlugin$_apply_closure2.doCall(SdkManagerPlugin.groovy:43)
        at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:40)
        at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:25)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:44)
        at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:79)
        at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:30)
        at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
        at com.sun.proxy.$Proxy16.afterEvaluate(Unknown Source)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:82)
        ... 56 more

Gralde档案:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://jitpack.io" }
        jcenter()
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
        classpath 'com.github.JakeWharton:sdk-manager-plugin:master'
    }
}

apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'

task increaseBuildStageVersion << {
    def versionPropsFileI = file('version.properties')
    if (versionPropsFileI.canRead()) {
        def Properties versionPropsI = new Properties()

        versionPropsI.load(new FileInputStream(versionPropsFileI))
        def value = 1
        println("INCREASING STAGE VERSION")

        def versionBuild = versionPropsI['VERSION_BUILD_STAGE'].toInteger() + value
        def codeVersion = versionPropsI['VERSION_CODE_STAGE'].toInteger() + value

        versionPropsI['VERSION_BUILD_STAGE'] = versionBuild.toString()
        versionPropsI['VERSION_CODE_STAGE'] = codeVersion.toString()

        versionPropsI.store(versionPropsFileI.newWriter(), null)
    } else {
        throw new GradleException("Could not read version.properties!")
    }
}

task increaseBuildProductionVersion << {
    def versionPropsFileI = file('version.properties')
    if (versionPropsFileI.canRead()) {
        def Properties versionPropsI = new Properties()

        versionPropsI.load(new FileInputStream(versionPropsFileI))
        def value = 1
        println("INCREASING PRODUCTION VERSION")

        def versionBuild = versionPropsI['VERSION_BUILD_PRODUCTION'].toInteger() + value
        def codeVersion = versionPropsI['VERSION_CODE_PRODUCTION'].toInteger() + value

        versionPropsI['VERSION_BUILD_PRODUCTION'] = versionBuild.toString()
        versionPropsI['VERSION_CODE_PRODUCTION'] = codeVersion.toString()

        versionPropsI.store(versionPropsFileI.newWriter(), null)
    } else {
        throw new GradleException("Could not read version.properties!")
    }
}

tasks.whenTaskAdded { task ->
    if (task.name == 'packageStageRelease') {
        task.dependsOn increaseBuildStageVersion
    } else if (task.name == 'packageProductionRelease') {
        task.dependsOn increaseBuildProductionVersion
    }
}

android {
    signingConfigs {
        release {
            .....
        }
    }

    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.fivedottwelve.bonusapp"
        minSdkVersion 19
        targetSdkVersion 25
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }

    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable false
            signingConfig signingConfigs.release


            def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
            def buildTime = new GregorianCalendar().format("dd-MM-yyyy' 'h:mm:ss a Z")
            buildConfigField "String", "GIT_SHA", "\"{$gitSha}\""
            buildConfigField "String", "BUILD_TIME", "\"{$buildTime}\""
        }

        debug {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable true

            buildConfigField "String", "GIT_SHA", "\"DEBUG\""
            buildConfigField "String", "BUILD_TIME", "\"BUILD_TIME\""
        }
    }
    productFlavors {
        development {
            versionName "1.0." + getStageVersionName() + "-stage"
            versionCode getStageVersionCode()
            applicationIdSuffix ".stage"
            resValue "string", "app_name", "BonusApp"

            buildConfigField('String', 'API_URL', "\"https://fivedottwelve.com/\"")
        }
        stage {
            versionName "1.0." + getStageVersionName() + "-stage"
            versionCode getStageVersionCode()
            applicationIdSuffix ".stage"
            resValue "string", "app_name", "BonusApp"

            buildConfigField('String', 'API_URL', "\"https://fivedottwelve.com/\"")

        }
        production {
            versionName "1.0." + getProdVersionName()
            versionCode getProdVersionCode()
            resValue "string", "app_name", "BonusApp"

            buildConfigField('String', 'API_URL', "\"https://fivedottwelve.com/\"")
        }
    }

    dexOptions {
        preDexLibraries true
        maxProcessCount 6
        javaMaxHeapSize "3g"
    }

    testOptions {
        unitTests.all {
            // All the usual Gradle options.
            testLogging {
                jvmArgs '-XX:MaxPermSize=256m'
                events "passed", "skipped", "failed", "standardOut", "standardError"
                outputs.upToDateWhen { false }
                showStandardStreams = true
            }
        }
    }
    lintOptions {
        disable 'InvalidPackage', 'ContentDescription'
        abortOnError false
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    packagingOptions {
        exclude 'main/AndroidManifest.xml'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'LICENSE.txt'
        exclude 'LICENSE'
    }
}

kapt {
    generateStubs = true
}


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

    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

    compile 'com.github.salomonbrys.kotson:kotson:2.5.0'

    compile "com.android.support:support-v4:$rootProject.ext.android_support_version"
    compile "com.android.support:appcompat-v7:$rootProject.ext.android_support_version"
    compile "com.android.support:design:$rootProject.ext.android_support_version"
    compile "com.android.support:recyclerview-v7:$rootProject.ext.android_support_version"
    compile "com.android.support:cardview-v7:$rootProject.ext.android_support_version"
    compile 'com.android.support:multidex:1.0.1'

    compile "com.google.android.gms:play-services-base:$rootProject.ext.play_service_version"
    compile "com.google.android.gms:play-services-gcm:$rootProject.ext.play_service_version"

    kapt "com.google.dagger:dagger-compiler:$rootProject.ext.Dagger_version"
    compile "com.google.dagger:dagger:$rootProject.ext.Dagger_version"

    compile "io.reactivex:rxjava:$rootProject.ext.RxJava_version"
    compile "io.reactivex:rxandroid:$rootProject.ext.RxAndroid_version"
    provided 'javax.annotation:jsr250-api:1.0'


    compile "com.squareup.okhttp3:okhttp:$rootProject.ext.retrofit_http_version"
    compile "com.squareup.okhttp3:okhttp-urlconnection:$rootProject.ext.retrofit_http_version"
    compile "com.squareup.okhttp3:logging-interceptor:$rootProject.ext.retrofit_http_version"

    compile "com.squareup.retrofit2:retrofit:$rootProject.ext.retorfit_version"
    compile "com.squareup.retrofit2:converter-gson:$rootProject.ext.retorfit_version"
    compile "com.squareup.retrofit2:adapter-rxjava:$rootProject.ext.retorfit_version"

    compile 'com.facebook.android:facebook-android-sdk:4.20.0'

    compile 'me.relex:circleindicator:1.2.1@aar'

    //glide
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'

    //transitions
    compile "com.andkulikov:transitionseverywhere:1.7.0"

    //beacons
    compile "com.kontaktio:sdk:$rootProject.ext.kontakt_io"

    compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
        transitive = true;
    }

}

repositories {
    maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
    maven { url 'http://maven.livotovlabs.pro/content/groups/public' }
    maven { url 'https://maven.fabric.io/public' }
}

/*
Resolves dependency versions across test and production APKs, specifically, transitive
dependencies. This is required since Espresso internally has a dependency on support-annotations.
*/
configurations.all {
    resolutionStrategy.force "com.android.support:support-annotations:$rootProject.ext.android_support_version"
}

/*
All direct/transitive dependencies shared between your test and production APKs need to be
excluded from the test APK! This is necessary because both APKs will contain the same classes. Not
excluding these dependencies from your test configuration will result in an dex pre-verifier error
at runtime. More info in this tools bug: (https://code.google.com/p/android/issues/detail?id=192497)
*/
configurations.compile.dependencies.each { compileDependency ->
    println "Excluding compile dependency: ${compileDependency.getName()}"
    configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
        configurations.androidTestCompile.exclude module: "${compileDependency.getName()}"
    }
}

1 个答案:

答案 0 :(得分:8)

我删除了apply plugin: 'android-sdk-manager'并且它有效