API‘variable.getExternalNativeBuildTasks()‘已过时,已替换为‘variant.getExternalNativeBuildProviders()

本文翻译自:API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders()

Using Android Studio 3.3 Canary 11 with the gradle plugin version 3.3.0-alpha11 . 使用Android Studio 3.3 Canary 11和gradle插件版本3.3.0-alpha11 It throws the following error when trying to sync gradle 尝试同步gradle时,它会引发以下错误

WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been 
replaced with 'variant.getExternalNativeBuildProviders()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration- 
avoidance
Affected Modules: app

Clicking on the error leads me to this line in the gradle file 单击错误会将我引导至gradle文件中的此行

applicationVariants.all { variant ->
            variant.outputs.all {
                outputFileName = "${variant.name}-${variant.versionName}.apk"
            }
        }

What exactly do I need to change here? 我到底需要改变什么?

project build.gradle project build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral() // jcenter() works as well because it pulls from Maven Central
        maven { url "https://maven.google.com" }
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha11'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath "io.realm:realm-gradle-plugin:4.1.1"
        classpath 'com.google.gms:google-services:3.2.1'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://maven.google.com" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

// Define versions in a single place
ext {
    // Sdk and tools
    minSdkVersion = 21
    targetSdkVersion = 27
    compileSdkVersion = 27
    buildToolsVersion = '27.0.3'

    // App dependencies
    supportLibraryVersion = '27.1.1'
    appCompactLibraryVersion = '27.1.1'
    playServicesVersion = '15.0.1'
    firebaseVersionCore = '16.0.1'
    firebaseVersionPerf = '16.0.0'
    firebaseVersionMessaging = '17.1.0'

    //lottie
    lottieVersion = '2.5.0'
}

app build.gradle app build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.25.4'
    }
    buildscript {
        repositories {
            maven { url "https://maven.google.com" }
            maven { url 'https://maven.fabric.io/public' }
            mavenCentral()

        }

        dependencies {
            // These docs use an open ended version so that our plugin
            // can be updated quickly in response to Android tooling updates

            // We recommend changing it to the latest version from our changelog:
            // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
            classpath 'io.fabric.tools:gradle:'
        }
    }
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
repositories {
    maven { url 'https://maven.fabric.io/public' }
}

apply plugin: 'io.fabric'
apply plugin: 'realm-android'

android {

    realm {
        syncEnabled = false
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        applicationId "example.com"
        minSdkVersion rootProject.ext.minSdkVersion
        multiDexEnabled true
        versionCode mVersionCode
        versionName mVersionName
        vectorDrawables.useSupportLibrary = true

    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {

        applicationVariants.all { variant ->
            variant.outputs.all {
                outputFileName = "${variant.name}-${variant.versionName}.apk"
            }
        }

        release {
            shrinkResources true
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            lintOptions {
                disable 'MissingTranslation'
            }

            applicationVariants.all { variant ->
                variant.outputs.all {
                    outputFileName = "${variant.name}-${variant.versionName}.apk"
                }
            }

        }
        debug {
            shrinkResources true
            minifyEnabled true
            useProguard true
            debuggable true
            versionNameSuffix '-DEBUG'
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'debug-proguard-rules.pro'

            ext.enableCrashlytics = false
            crunchPngs false

        }
    }

    flavorDimensions "default"

    lintOptions {

        checkReleaseBuilds false

    }

    packagingOptions {
        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'
    }
    buildToolsVersion '28.0.2'
}

configurations {
    implementation.exclude group: "org.apache.httpcomponents", module: "httpclient"
}

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

    implementation "com.android.support:appcompat-v7:$rootProject.appCompactLibraryVersion"
    implementation "com.android.support:support-compat:$rootProject.supportLibraryVersion"
    implementation "com.android.support:mediarouter-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:design:$rootProject.supportLibraryVersion"


    api 'com.squareup.retrofit2:retrofit:2.4.0'
    api 'com.squareup.okhttp3:okhttp:3.11.0'
    api 'com.squareup.okhttp3:logging-interceptor:3.10.0'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.daimajia.easing:library:2.0@aar'
    implementation 'com.daimajia.androidanimations:library:2.3@aar'

    implementation 'com.akexorcist:googledirectionlibrary:1.0.5'
    implementation 'io.reactivex:rxandroid:1.2.1'
    implementation 'io.reactivex:rxjava:1.3.0'
    // Wifi hotspot library
    implementation 'cc.mvdan.accesspoint:library:0.2.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'org.jsoup:jsoup:1.10.3'
    api "com.airbnb.android:lottie:$rootProject.lottieVersion"
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    testImplementation 'junit:junit:4.12'
    implementation 'com.jakewharton:butterknife:8.8.1'

    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

    implementation 'com.googlecode.libphonenumber:libphonenumber:8.2.0'

    implementation "com.google.android.gms:play-services-base:$rootProject.playServicesVersion"
    implementation "com.google.android.gms:play-services-cast-framework:$rootProject.playServicesVersion"
    implementation "com.google.android.gms:play-services-auth:$rootProject.playServicesVersion"
    implementation "com.google.android.gms:play-services-identity:$rootProject.playServicesVersion"
    implementation "com.google.android.gms:play-services-awareness:$rootProject.playServicesVersion"
    implementation "com.google.android.gms:play-services-cast:$rootProject.playServicesVersion"
    implementation "com.google.android.gms:play-services-drive:$rootProject.playServicesVersion"
    implementation "com.google.android.gms:play-services-location:$rootProject.playServicesVersion"
    implementation "com.google.android.gms:play-services-maps:$rootProject.playServicesVersion"

    implementation "com.google.firebase:firebase-core:$rootProject.firebaseVersionCore"
    implementation "com.google.firebase:firebase-perf:$rootProject.firebaseVersionPerf"
    implementation "com.google.firebase:firebase-messaging:$rootProject.firebaseVersionMessaging"
    implementation "com.google.firebase:firebase-analytics:$rootProject.firebaseVersionCore"


    api('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
        transitive = true
    }
    api('com.crashlytics.sdk.android:answers:1.4.1@aar') {
        transitive = true
    }
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    api project(path: ':libraryBTHelper')
    api project(':bkk_rush')

    debugApi 'com.amitshekhar.android:debug-db:1.0.3'
    api "org.jdeferred:jdeferred-android-aar:1.2.6"
    implementation 'com.android.support:gridlayout-v7:27.1.1'
}

apply plugin: 'com.google.gms.google-services'

I have skipped out a few constants and other sensitive information in the app/build.gradle file. 我在app / build.gradle文件中跳过了一些常量和其他敏感信息。


#1楼

参考:https://stackoom.com/question/3XulD/API-variable-getExternalNativeBuildTasks-已过时-已替换为-variant-getExternalNativeBuildProviders


#2楼

the issue-tracker might refer to "lazy task configuration" - 问题跟踪器可能会引用“懒惰任务配置” -

that's at least what task configuration avoidance suggests. 这至少是避免任务配置的建议。

but one possibly can prevent the access to this obsolete method of BaseVariantImpl , when variant.outputs.all won't access that method (internally) - or when checks can prevent the access; 但是当variant.outputs.all不能访问该方法(内部)时,或者当检查可以阻止访问时,可能会阻止访问这个过时的BaseVariantImpl方法; or when accessing the variant by it's name; 或者当用它的名字访问变体时; or somehow disable the external native build tasks for the variant. 或以某种方式禁用变体的外部本机构建任务。 also see the single-variant project sync option, which rather seems related. 还可以看到单变量项目同步选项,这看起来很相关。

or wait for build-tools 3.3.0-alpha12 or 3.3.0-beta1 ...this is not even a release candidate , therefore investing to much time might be pointless - except using it to file another bug-report. 或等待构建工具 3.3.0-alpha123.3.0-beta1 ......这甚至都不是release candidate ,因此投入大量时间可能毫无意义 - 除非使用它来提交另一个错误报告。

the new quick feedback 新的快速反馈 快速反馈 button still looks the most promising. 按钮仍然看起来最有前途。


#3楼

不确定实际问题是什么,但是从项目中解决了与崩解相关的依赖关系解决了问题。


#4楼

EDIT 编辑

This issue has been fixed in Fabric 1.28.0 . Fabric 1.28.0中已修复此问题。 In your build.gradle of the project level, add the following line: 在项目级别的build.gradle中,添加以下行:

classpath 'io.fabric.tools:gradle:1.28.1'

Previous Answer 上一个答案

It happens after I updated Android Studio to 3.3.0. 它发生在我将Android Studio更新到3.3.0之后。 apply plugin: 'io.fabric' is the cause. apply plugin: 'io.fabric'是原因。 I have sent a bug report to Firebase team about this issue. 我已向Firebase小组发送了有关此问题的错误报告。

You have 3 options: 你有3个选择:

  • Wait until the next version of Fabric plugin is released. 等到下一版Fabric插件发布。 Check the latest version here . 这里查看最新版本。

  • Downgrade to Android Studio 3.2.1 . 降级到Android Studio 3.2.1

  • Comment out io.fabric plugin. 注释掉io.fabric插件。

In build.gradle of your app's module: 在app的模块的build.gradle中:

apply plugin: 'com.android.application'
// apply plugin: 'io.fabric' <== this plugin causes the error

However, you can still build and run your projects even though this error appears. 但是,即使出现此错误,您仍可以构建和运行项目。 Just ignore it. 只是忽略它。


#5楼

in application build.gradle , downgrade to this stable version of gradle : 在应用程序build.gradle中,降级到这个稳定版本的gradle:

classpath 'com.android.tools.build:gradle:3.2.1'

It happens after I updated Android Studio to 3.3 , temp solution until they fix it ! 它发生在我将Android Studio更新为3.3,临时解决方案之后,直到他们修复它!

edit: you don't need to downgrade your android studio ! 编辑:你不需要降级你的android工作室!


#6楼

When I opened the project, I pressed the Run migrations button appeared on the right bottom corner from Android Studio . 当我打开项目时,我按下Android Studio右下角出现的Run migrations按钮。 A migration was performed and the problem was solve without commenting out the Crashlytics dependency. 执行迁移并解决问题,而没有评论Crashlytics依赖项。

在此输入图像描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值