ChatGPT解决这个技术问题 Extra ChatGPT

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. It throws the following error when trying to sync 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

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

What exactly do I need to change here?

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

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.

Can you post your build.gradle(app)?
@Skizo-ozᴉʞS added the project build.gradle file
@alashow this is related to different issue, message there is "API 'variant.getJavaCompile()' is obsolete.."
Issue exists with the stable version as well

N
Naveed Ahmad

The issue has been fixed in their latest release 'io.fabric.tools:gradle:1.30.0'

Please update your both gradle fabric tools with 1.30.0

buildscript {
  // ... repositories, etc. ...

   dependencies {
       // ...other dependencies ...
       classpath 'io.fabric.tools:gradle:1.30.0'
   }
}

For more details https://github.com/firebase/firebase-android-sdk/issues/198#issuecomment-473435453


Make sure to change it in the build.gradle in both the project level and app.
Version 1.28.0 fixed my problem, current version is 1.29.0 docs.fabric.io/android/changelog.html#fabric-gradle-plugin
I'm still getting this warning with classpath 'io.fabric.tools:gradle:1.31.0' and implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'. It's either broken again or not fixed for all cases.
Where did you get this fabric tools gradle version? I can only find 1.25.4 mvnrepository.com/artifact/io.fabric.tools/gradle
A
Anggrayudi H

EDIT

This issue has been fixed in Fabric 1.28.0. In your build.gradle of the project level, add the following line:

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

Previous Answer

It happens after I updated Android Studio to 3.3.0. apply plugin: 'io.fabric' is the cause. I have sent a bug report to Firebase team about this issue.

You have 3 options:

Wait until the next version of Fabric plugin is released. Check the latest version here.

Downgrade to Android Studio 3.2.1.

Comment out io.fabric plugin.

In build.gradle of your app's module:

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.


Would it be possible for you to link to the bug report or issue you opened with Firebase? I'd love to upvote it.
I have to use the io.fabric plugin then how can i remove this warning without changing this?
This is the cause, not a viable solution
They are saying that you can use it until end of the 2019 year. For now I'm using, we will see what happens )
Why downgrading? No sense! It's just a warning, it's not removed yet and it can build your project (the whole 2019 year...). I believe they will fix it during this year
T
Troll

In application build.gradle, downgrade to this stable version of gradle:

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

It happens after I updated Android Studio to 3.3, a temp solution until they fix it.

Edit: You don't need to downgrade your Android Studio


Then you also have to downgrade to Android Studio 3.2.1. Thanks anyway
I had the same problem after upgrading Android Studio (AS) to version 3.3. I got Gradle sync to work again by downgrading Gradle to version 4.6 and Android Gradle Plugin to version 3.2.1, which was the versions I was using prior to the AS update. Look up the table here if you are doubt how to modify the versions for gradle and the plugin.
It worked without downgrading anything thanks for the suggestion
you don't need to downgrade your android studio @RubénViguera
You don't need to downgrade anything other than gradle version as mentioned in the answer. This should be the accepted answer.
1
113408

UPDATE As of today you can use classpath 'io.fabric.tools:gradle:1.28.0' to fix this issue !

If commenting out Crashlytics's plugin io.fabric on the app gradle file worked for you temporarily

//apply plugin: 'io.fabric'

Then upgrading your fabric gradle dependencies on the Project gradle file will permanently solve the issue:

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

NB: this doesn’t remove the warnings but let you use Crashlytics with AS3.3+


@RJB Are you using Crashlytics? If you remove it from your project it works ? If yes then this should fix the issue. However you might still get warnings, but the project will compila and you can generate your apk safely
Yes. I mean that I am still getting the warning.
the op and others (including me) had this issue and were unable to compile the project with crashlytics enabled. So to keep Crashlytics and still push to prod you can use the above mentioned update even though it still trigger "warnings".
J
Jude Fernandes

Not sure what the actual issue is but commenting out the crashlytics related dependencies from the project solved issue.


R
Ryde

It's confirmed as bug for Crashlytics and they are working on it.

https://issuetracker.google.com/issues/116408637

Quoted from Google assignee:

je...@google.com #23 Jan 23, 2019 01:40AM Hi all, Thank you for your patience. It looks like the bug in all cases is coming from crashlytics and I've filed a bug with them. I will keep you updated on the status.

For me, my debug app is working fine on my device just by running and ignoring the warning without commenting Crashlytics or Fabric. I have not try for production.

Update:

Google Issue Tracker had mark this issues as Won't Fix (Infeasible) because all the issues was from Crashlytics, and let fixes done by Crashlytics team (despite they are same Googler...).

They suggest to follow this link for Crashlytics updates:

https://github.com/firebase/firebase-android-sdk/issues/198

Note: I'm still using Android Studio 3.3 with io.fabric.tools:gradle:1.26.0 without commenting any of Craslytics and it's works fine on my debug app.

Update:

I can confirm now that it works fine on my production/release version app. How do I know it works? Because it had sent me back a crash reports -_-'

Anyway, just ignore the warning, they should fix it eventually.

Aww, just read that it had fixed with fabric 1.28.0 :)


G
Gastón Saillén

Latest news from 01/24/2019

https://i.stack.imgur.com/fqXMM.png

Info here https://issuetracker.google.com/issues/116408637

We will need to wait untill Crashlytics came up with a solution, here is GitHub issue opened

https://github.com/firebase/firebase-android-sdk/issues/198

The only way I'm using as right now to not comment io.fabric plugin is downgrading my gradle and upgrading my fabric classpath (this is working on my production app)

 dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'io.fabric.tools:gradle:1.27.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

How about we just add -dontwarn com.crashlytics.android.Crashlytics in proguard-rules.pro
If you remove the warning by doing that the problem is still there and you will need to eventually get back to the problem again
Right! It is a temp solution to get build compiled, but it is much better than downgrading everything.
Yes, downgrading it will cause to work, if you dismiss the warning you can keep the updated version but it won't work
@Mustansir, I think it's a gradle-related problem and has nothing to do with Proguard.
A
Agna JirKon Rx

As it was said, the problem is with Fabric/Crashlytics.

apply plugin: 'io.fabric'

It's a bug on Crashlytics/Firebase side, please check the following link and see the bug' status : https://github.com/firebase/firebase-android-sdk/issues/198


M
Martin Zeitler

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; 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.

https://i.stack.imgur.com/4tEX9.png


Yes, i agree, this type of error was not present in the previous build tools. The next RC may fix it
it was not fixed in the release
developer.android.com/studio/releases/gradle-plugin#3-3-0 ...add android.debug.obsoleteApi=true to see where it comes from. there were a few methods renamed, with Provider appended to their name.
@SergeyNarozhnyy in project gradle.properties
@SergeyNarozhnyy the 3.3.0 release broken a few things, since the variant API had changed. can link one recent discussion: stackoverflow.com/questions/54206898/… (added a summary as an answer there).
a
amit pandya

For me, I followed these steps: 1. upgrade the Gradle dependency on project level build.gradle.

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

add this plugin dependency below apply plugin: 'com.android.application' in the app level build.gradle. apply plugin: 'io.fabric' Sync the project with gradle files.


X
Xavier Rubio Jansana

This happens due to the update of your Android Studio from Android Studio 3.2.0 to Android Studio 3.3.0. Update Your Gradle Dependencies (Project)of IO.Fabric. Like:

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

and also update your Kotlin version to

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"

This will resolve this issues. Thanks


Thanks. Your answer helped me.
@Sean If you are using Kotlin and io febric.then It works otherwise for working downgrade your classpath version.It will works...
The Crashlytics build ID is missing. This occurs when Crashlytics tooling is absent from your app's build configuration
0
0xAliHn

Build log prints how to debug this, particularly you need to run build with -Pandroid.debug.obsoleteApi=true, that'll print stack-trace of call to deprecated API and you'll be able to figure which plugin/code calls it.

If it ends up being your code — use new Provider API (read Lazy Task Configuration doc)

If it comes from other plugin — report to them with stack-trace and warning message and maybe submit a patch. As in this case its related to io.fabric issue.


V
Vladyslav Panchenko

this has been fixed in the latest release of the Fabric gradle plugin, 1.28.0, which went live today. Have this in your top-level build.gradle:

buildscript {
// ... repositories, etc. ...

dependencies {
    // ...other dependencies ...
    **classpath 'io.fabric.tools:gradle:1.28.0'**
}

p
pableiros

When I opened the project, I pressed the Run migrations button appeared on the right bottom corner from Android Studio. A migration was performed and the problem was solve without commenting out the Crashlytics dependency.

https://i.stack.imgur.com/WER35.png


P
Petar

Changing source compatibility in module build.gradle file to Java 8 fixes the issue

compileOptions {
    sourceCompatibility 1.8
    targetCompatibility 1.8
}

Be sure to rebuild the project after adding those lines


In top level build.gradle or module level (/app) ?
module level(app)
S
Sadjad Abbasnia

this will fix the error : On the taskbar click Tools->Kotlin->Configure Kotlin in Project


F
Fragment

In my case, I needed to use io.fabric plugin, and the solution was, to update to the latest fabric tools gradle version:

classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'io.fabric.tools:gradle:1.27.0'

H
Henrique Monte

For those who need to keep the Fabric plugin applied, the temporary solution is to go back to the previous version of the gradle at the project level.

Change the classpath version to com.android.tools.build:gradle:3.2.1.


M
Mohammad

It was a problem with latest gradle (in my case 3.3.2) version and Fabric.io plugin. It is now solved by the new version Users should have this in their top-level build.gradle:

buildscript {
   // ... repositories, etc. ...

    dependencies {
        // ...other dependencies ...
        classpath 'io.fabric.tools:gradle:1.28.0'
    }
}

P
Pavan

Fix is update the root build gradle files to latest. And this answer hold true now. in fureture again new change will be implementing by gradle and android SDK. At times answer will vary in due course of time.

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

}
dependencies {

    classpath 'com.android.tools.build:gradle:3.5.0'
    classpath 'com.google.gms:google-services:4.3.0'
    classpath 'io.fabric.tools:gradle:1.30.0'
}

a
alacoo

first of all this is not an error

it's warning

and its show up when update gradle to 3.3.0 Often occur because io.fabric so wait until the update fabric current version where warning is still show up is 'io.fabric.tools:gradle:1.27.1'