While Android Studio Updated to v3.3 getting API 'variant.getAssemble()' is obsolete and has been replaced with 'variant.getAssembleProvider()'

帅比萌擦擦* 提交于 2019-11-28 00:15:46

variant.assemble has been deprecated and replaced by a new provider API.

If for example you are using it as next:

variant.outputs.all { output ->
        variant.assemble.doLast {
            ....
        }
    }
}

Then replace it the new provider API:

variant.outputs.all { output ->
    variant.getAssembleProvider().configure() {
        it.doLast { 
            ....
            }
        }
}

It's a warning, it doesn't negatively impact your build. You may go forward and update to AGP 3.3.0.

The new Android Gradle Plugin started leveraging lazy configuration (Task Configuration Avoidance API and Provider API) which, if used properly, may improve build speeds by only evaluating tasks and properties which are needed. Consumers of AGP need to use the updated API (e.g. getAssembleProvider().configure() instead of getAssemble()) otherwise the tasks and properties are always evaluated.

The point of lazy API: Don't configure tasks which aren't going to run in a particular build.

Read more:

What to do

If it's not coming from your code there's nothing for you to do other than wait for updated libraries (and pray they do it right).

If it comes from your code, here's an example of migration: I'm using this bit of code from Jake Wharton to disable BuildConfig.java generation for my library modules.

libraryVariants.all {
    it.generateBuildConfig.enabled = false
}

Using the new lazy API it looks like this.

libraryVariants.all {
    it.generateBuildConfigProvider.configure {
        it.enabled = false
    }
}

The eager API would cause the generateBuildConfig task to be configured even if I didn't need it, such as running clean. The lazy API configures the task only if it's part of the task graph to run. This saves time during the configuration phase.

How to figure out if it comes from your code? Put this in your gradle.properties

android.debug.obsoleteApi=true

Now run a build and check the output for stack traces.

Full error

For completeness, here's an example of a full error message caused by the Fabric plugin 1.27.0 with AGP 3.3.0:

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.
To determine what is calling variant.getExternalNativeBuildTasks(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.

Bad example

Here's a diff of how Facebook React dealt with the API migration in their plugin: https://github.com/facebook/react-native/pull/23103/files

In other words, they didn't. taskProvider.get() is equal to task - both uses are eager. The tasks are always configured.

The only thing this approach achieves is removing the warning so

  • the consumer has no idea they're not getting any benefits of the lazy API,
  • the plugin author is no longer reminded they're using it wrong.

The Task Configuration Avoidance API docs contain a migration guide and a helpful table describing how to create and chain tasks lazily. If you're a plugin author, please read it.

This type of warning can appear if some library used is your project is using this method

Temporary solution!
- Edit your root "build.gradle" file.
- Change "com.android.tools.build:gradle:3.3.0" to "3.2.0"
Done.

same problem:

https://stackoverflow.com/a/52470224/8920453

and see this:

https://stackoverflow.com/a/54239512/8920453

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!