Flutter 无法在设备导入 androidx.annotation.Nullable 上运行应用程序
Posted
技术标签:
【中文标题】Flutter 无法在设备导入 androidx.annotation.Nullable 上运行应用程序【英文标题】:Flutter fail to run app on device import androidx.annotation.Nullable 【发布时间】:2019-07-03 08:58:03 【问题描述】:Initializing gradle...
Resolving dependencies...
Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
/Users/ipatel/Documents/AAAA/FlutterSetup/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.0/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:9: error: cannot find symbol
import androidx.annotation.NonNull;
^
symbol: class NonNull
location: package androidx.annotation
/Users/ipatel/Documents/AAAA/FlutterSetup/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.0/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:10: error: cannot find symbol
import androidx.annotation.Nullable;
^
symbol: class Nullable
location: package androidx.annotation
/Users/ipatel/Documents/AAAA/FlutterSetup/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.0/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:253: error: cannot find symbol
public void onFailure(@NonNull Exception e)
^
symbol: class NonNull
/Users/ipatel/Documents/AAAA/FlutterSetup/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.0/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:274: error: cannot find symbol
public Void apply(@NonNull Transaction transaction)
^
symbol: class NonNull
/Users/ipatel/Documents/AAAA/FlutterSetup/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.0/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:272: error: cannot find symbol
@Nullable
^
symbol: class Nullable
/Users/ipatel/Documents/AAAA/FlutterSetup/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.0/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:503: error: cannot find symbol
public void onFailure(@NonNull Exception e)
^
symbol: class NonNull
/Users/ipatel/Documents/AAAA/FlutterSetup/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.0/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java:558: error: cannot find symbol
public void onFailure(@NonNull Exception e)
^
symbol: class NonNull
7 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':cloud_firestore:compileDebugJavaWithJavac'.
> 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 4s
Finished with error: Gradle task assembleDebug failed with exit code 1
不知道为什么会发现上述错误?我只是尝试在我的系统中连接设备并运行。
以前,我尝试在未安装 Android Studio 的情况下通过 VS Code 在设备上运行应用程序。所以我按照https://medium.com/@aubykhan/setting-up-flutter-without-android-studio-6f7abdeb353c这个教程,通过终端手动安装了Gradle。
以下是我的终端的一些历史记录:
431 brew install gradle 432 brew cask 安装 java 433 冲泡安装 gradle 434 颤振配置 --gradle-dir /usr/local/opt/gradle 435颤动--版本 第436章 第437章 扑医生 438 sdkmanager“系统图像;android-21;默认;x86_64” 第439章~/.bash_profile 440 打开 $HOME/.bash_profile
我认为问题可能是系统发现 Gradle 的两条路径或问题是其他路径?不知道,但我该如何解决这个问题?
【问题讨论】:
你迁移pub.dartlang.org/packages/firebase_core#030了吗? @GünterZöchbauer - 永远感谢您的指导。现在我可以在我的设备上运行 App,但在控制台显示“不推荐使用 registerResGeneratingTask,请使用 registerGeneratedResFolders(FileCollection)” 我认为你可以忽略它。我见过很多次,但不知道如何摆脱它,据我所知,它不会引起问题。 【参考方案1】:您需要迁移到AndroidX,如受影响官方插件的更新日志https://pub.dartlang.org/packages/firebase_core#030中所述
【讨论】:
如何迁移到AndroidX? 查看我的答案中的链接。 当我转到 Refactor>Migrate to AndroidX 时,它说 No usages found in the project。 Flutter 项目有替代方案吗? 你是否打开了android
此处提到的目录flutter.io/docs/development/packages-and-plugins/…
@GünterZöchbauer,仍然没有为我工作,请帮忙,已经一个星期了!!【参考方案2】:
在 android/gradle.properties 添加下面两行。就我而言,使用此解决问题。
android.useAndroidX=true
android.enableJetifier=true
【讨论】:
只是为了澄清这个答案,有一个官方页面详细解释了这个flutter.dev/docs/development/packages-and-plugins/… 这样做了,但没有帮助(以上是关于Flutter 无法在设备导入 androidx.annotation.Nullable 上运行应用程序的主要内容,如果未能解决你的问题,请参考以下文章
您的应用未使用 AndroidX - Flutter 不允许我生成 apk
错误:迁移到 AndroidX 后找不到符号导入 com.google.firebase.iid.InstanceIdResult
FirebaseAuthPlugin.java:9:错误:找不到符号导入 androidx.annotation.NonNull;
Flutter 返回 `lifecycle-common-java8.jar (androidx.lifecycle:lifecycle-common-java8:2.0.0)` 错误