解决flutter 错误: 程序包androidx.lifecycle不存在问题
作者:Emperor灬fly
发生于编译时:错误: 程序包androidx.lifecycle不存在
先贴一段报错log,让你更加准确的匹配问题所在,对症下药,药,切克闹。
D:\study\flutter\flutter\.pub-cache\hosted\pub.flutter-io.cn\flutter_plugin_android_lifecycle-1.0.8\android\src\main\java\io\flutter\embedding\engine\plugins\lifecycle\FlutterLifecycleAdapter.java:8: 错误: 程序包androidx.lifecycle不存在
import androidx.lifecycle.Lifecycle;
^
D:\study\flutter\flutter\.pub-cache\hosted\pub.flutter-io.cn\flutter_plugin_android_lifecycle-1.0.8\android\src\main\java\io\flutter\embedding\engine\plugins\lifecycle\FlutterLifecycleAdapter.java:22: 错误: 找不到符
号
public static Lifecycle getActivityLifecycle(
符号: 类 Lifecycle
位置: 类 FlutterLifecycleAdapter
2 个错误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
Exception: The plugin flutter_plugin_android_lifecycle could not be built due to the issue above.
既然问题已经匹配上了,那就说下我下面的解决实践吧。
上面的问题其实就是Androidx引用库兼容问题,当某些插件升级到一定版本时就会出现这个问题。
首先升级下sdk
实际上到这里就已经解决了,但是可能有些包被墙了,下载不了,导致还是没解决,则需要使用阿里云的代理了
到这里应该是完全解决了,但是不排除个别钉子户,根据github issure给出的解决方案就是需要升级一下
gradle的版本了
方便复制:
maven{ url 'https://maven.aliyun.com/repository/google'} maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'} maven{ url 'https://maven.aliyun.com/repository/public'} maven{ url 'https://maven.aliyun.com/repository/jcenter'} distributionUrl = https://services.gradle.org/distributions/gradle-4.10.2-all.zip # 手动更新Gradle版本
以上就是我实践出来的解决方法,如果能帮到你,那真的是太好了。
总结
到此这篇关于解决flutter 错误: 程序包androidx.lifecycle不存在问题的文章就介绍到这了,更多相关程序包androidx.lifecycle不存在内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!