Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: package androidx.lifecycle does not exist in flutter

I want to use local_auth plugin in flutter, and it needs Android lifecycle, so i installed flutter_plugin_android_lifecycle, but i get this error with it if i try to release apk: error: package androidx.lifecycle does not exist. I tried a lot of things, but i just cannot get it to work.

''' C:\flutter.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-1.0.7\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.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-1.0.7\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 2 errors

       FAILURE: Build failed with an exception.

       * What went wrong:
       Execution failed for task ':compileReleaseJavaWithJavac'.
       > Compilation failed; see the compiler error output for details.

       * Try:
       Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

       * Get more help at https://help.gradle.org

       BUILD FAILED in 1s

'''

like image 374
Milán Dóczi Avatar asked May 07 '20 01:05

Milán Dóczi


3 Answers

Adding implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' in build.grable plugin folder will solve the issue.

Refer https://github.com/flutter/flutter/issues/60883 for more details.

like image 78
arun-r Avatar answered Nov 05 '22 03:11

arun-r


Add this in you flutter yaml dependencies

flutter_plugin_android_lifecycle: ^1.0.11

For more can visit : https://pub.dev/packages/flutter_plugin_android_lifecycle/install

like image 2
Mukta Avatar answered Nov 05 '22 03:11

Mukta


This can be also due to a version gradle problem, so try to use these compatible versions in your /android/build.gradle

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

you can try also:

3.3.3

3.4.3

3.5.4

3.6.4

4.0.1

This error came to me using the flutter plugin file_picker. I hope this work.

like image 2
Pedro Molina Avatar answered Nov 05 '22 01:11

Pedro Molina