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


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容