error: package androidx.lifecycle does not exist in flutter

C:\flutter-sdk\.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-1.0.8\android\src\main\java\io\flutter\embedding\engine\plugins\lifecycle\FlutterLifecycleAdapter.java:8: error: package androidx.lifecycle does not exist

import androidx.lifecycle.Lifecycle;

C:\flutter-sdk\.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-1.0.8\android\src\main\java\io\flutter\embedding\engine\plugins\lifecycle\FlutterLifecycleAdapter.java:22: error: cannot find symbol

public static Lifecycle getActivityLifecycle(

symbol: class Lifecycle

location: class FlutterLifecycleAdapter

解决方案:

I added the required Gradle dependency implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' in build.gradle file in path : [flutter sdk directory]\.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-1.0.8\android\build.gradle and error gone in the next flutter build apk --release run.

在插件flutter_plugin_android_lifecycle最新版本的相关文件:android\build.gradle  下新增行:

implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

位置如下图所示:

新增代码位置

来源:https://github.com/flutter/flutter/issues/60883


你可能感兴趣的:(error: package androidx.lifecycle does not exist in flutter)