java - The plugin flutter_plugin_android_lifecycle could not be built
问题描述
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!
解决方案
请按照以下步骤操作:
在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
请参考此链接了解更多信息: 点击这里
推荐阅读
- react-native - Azure devops react native ios build 失败,出现一般错误 65
- python - 如何使用python在终端中显示文本文件
- excel - For循环没有正确计算行的总和
- css - 悬停时将图像缩放到原始大小
- r - 根据内容合并数据框单元格
- visual-studio-2010 - Msbuild - 在属性中嵌套属性
- swift - 只有在安装应用时才能看到 App Clips 横幅
- swift - 我是否必须锁定从 AVCaptureVideoDataOutput 生成的 CVPixelBuffer
- environment-variables - OpenUI5 应用程序中的环境变量
- wordpress - 为什么我会收到此代码的致命错误消息