The plugin flutter_plugin_android_lifecycle could not be built
Asked Answered
S

1

6

The task - :compileReleaseJavaWithJavac failed saying: The plugin flutter_plugin_android_lifecycle couldn't be built due to the errors:

error: package androidx.lifecycle does not exist
import androidx.lifecycle.Lifecycle;

and

error: cannot find symbol
  public static Lifecycle getActivityLifecycle(
                ^
  symbol:   class Lifecycle
  location: class FlutterLifecycleAdapter

Here is the FlutterLifecycleAdapter.java file:

package io.flutter.embedding.engine.plugins.lifecycle;

import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;

/** Provides a static method for extracting lifecycle objects from Flutter plugin bindings. */
public class FlutterLifecycleAdapter {
  private static final String TAG = "FlutterLifecycleAdapter";

  /**
   * Returns the lifecycle object for the activity a plugin is bound to.
   *
   * <p>Returns null if the Flutter engine version does not include the lifecycle extraction code.
   * (this probably means the Flutter engine version is too old).
   */
  @NonNull
  public static Lifecycle getActivityLifecycle(
      @NonNull ActivityPluginBinding activityPluginBinding) {
    HiddenLifecycleReference reference =
        (HiddenLifecycleReference) activityPluginBinding.getLifecycle();
    return reference.getLifecycle();
  }
}

This is the first time I'm using sharedPreferences and Flutter_secure_storage and the first time I've encountered this problem. I believe error came up after I updated Android Studio. I haven't touched anything in this file. Thanks for your help in advance!

Scraggly answered 3/5, 2020 at 2:43 Comment(1)
did you solved this?Catanddog
T
0

Kindly Follow the below Steps:

In gradle-wrapper.properties add these Below Code:

distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip

enter image description here

In gradle.properites Kindly check the below lines are added:

android.useAndroidX=true
android.enableJetifier=true

enter image description here

In android/build.gradle file add the Below Code:

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

enter image description here

And check this version in android/build.gradle:

compileSdkVersion 29

enter image description here

Please refer this Link For More Info: clickhere

Titulary answered 2/8, 2021 at 18:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.