解决错误更加准确匹配

解决flutter 错误: 程序包androidx.lifecycle不存在问题

编程开发 2020-10-16 08:11:27 54

导读

发生于编译时:错误:程序包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\embedd……

发生于编译时:错误: 程序包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

解决flutter 错误: 程序包androidx.lifecycle不存在问题

实际上到这里就已经解决了,但是可能有些包被墙了,下载不了,导致还是没解决,则需要使用阿里云的代理了

解决flutter 错误: 程序包androidx.lifecycle不存在问题

到这里应该是完全解决了,但是不排除个别钉子户,根据github issure给出的解决方案就是需要升级一下
gradle的版本了

解决flutter 错误: 程序包androidx.lifecycle不存在问题
解决flutter 错误: 程序包androidx.lifecycle不存在问题

方便复制:

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版本

以上就是我实践出来的解决方法,如果能帮到你,那真的是太好了。


1253067 TFnetwork_cn