无法构建插件flutter_plugin_android_lifecycle
Posted
技术标签:
【中文标题】无法构建插件flutter_plugin_android_lifecycle【英文标题】:The plugin flutter_plugin_android_lifecycle could not be built 【发布时间】:2020-08-17 12:11:22 【问题描述】:任务 - :compileReleaseJavaWithJavac 失败说: 插件flutter_plugin_android_lifecycle由于错误无法构建:
error: package androidx.lifecycle does not exist
import androidx.lifecycle.Lifecycle;
和
error: cannot find symbol
public static Lifecycle getActivityLifecycle(
^
symbol: class Lifecycle
location: class FlutterLifecycleAdapter
这是 FlutterLifecycleAdapter.java 文件:
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();
这是我第一次使用 sharedPreferences 和 Flutter_secure_storage,也是我第一次遇到这个问题。 我相信更新 Android Studio 后出现错误。 我没有触及这个文件中的任何内容。 提前感谢您的帮助!
【问题讨论】:
你解决了吗? 【参考方案1】:请按照以下步骤操作:
在 gradle-wrapper.properties 中添加以下代码:
distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip
在 gradle.properites 请检查以下行是否已添加:
android.useAndroidX=true
android.enableJetifier=true
在 android/build.gradle 文件中添加以下代码:
classpath 'com.android.tools.build:gradle:3.5.4'
并在 android/build.gradle 中检查此版本:
compileSdkVersion 29
请参考此链接了解更多信息: clickhere
【讨论】:
以上是关于无法构建插件flutter_plugin_android_lifecycle的主要内容,如果未能解决你的问题,请参考以下文章
Flutter - 无法构建插件 firebase_core
无法构建插件flutter_plugin_android_lifecycle