解決flutter 錯誤: 程式包androidx.lifecycle不存在問題
發生於編譯時:錯誤: 程式包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不存在內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!