Flutter无法构建apk。

4

我正在使用以下插件制作Flutter应用:

firebase_core: ^0.4.0+9
firebase_storage: ^3.0.6
firebase_auth: ^0.14.0+5
firebase_database: ^3.0.7
http:
image_picker: ^0.6.1+4
image: ^2.0.8
photo_view:
uuid: ^2.0.1
cached_network_image: ^0.8.0
intl: ^0.15.8
shared_preferences: ^0.5.2+1
url_launcher: ^5.1.2
firebase_messaging: ^5.1.6

我已经迁移到AndroidX,我的应用在模拟器上运行正常,但是当我尝试运行flutter build apk时,Android Studio显示以下错误:

Microsoft Windows [Version 10.0.17134.1006]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\SQ\Documents\FlutterProjects\estudiolegal_app>flutter build apk
You are building a fat APK that includes binaries for android-arm, android-arm64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
    To generate an app bundle, run:
        flutter build appbundle --target-platform android-arm,android-arm64
        Learn more on: https://developer.android.com/guide/app-bundle
    To split the APKs per ABI, run:
        flutter build apk --target-platform android-arm,android-arm64 --split-per-abi
        Learn more on:  https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Initializing gradle...                                              0.8s
Resolving dependencies...                                           3.9s
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preReleaseBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.2) classpath. You should manually set the same version via DependencyResolution

* 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 3s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                       3.6s
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
Building plugin firebase_auth...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done                    2.5s
Built build\app\outputs\repo.
Building plugin firebase_core...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done                    2.7s
Built build\app\outputs\repo.
Building plugin firebase_database...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done                    2.5s
> Task :assembleAarRelease UP-TO-DATE
> Task :preBuild UP-TO-DATE
> Task :preReleaseBuild UP-TO-DATE
> Task :compileReleaseAidl NO-SOURCE
> Task :compileReleaseRenderscript UP-TO-DATE
> Task :checkReleaseManifest UP-TO-DATE
> Task :generateReleaseBuildConfig
> Task :generateReleaseResValues UP-TO-DATE
> Task :generateReleaseResources UP-TO-DATE
> Task :packageReleaseResources
> Task :processReleaseManifest
> Task :generateReleaseRFile
> Task :prepareLintJar UP-TO-DATE
> Task :generateReleaseSources
> Task :javaPreCompileRelease UP-TO-DATE

> Task :compileReleaseJavaWithJavac FAILED

> Task :mergeReleaseConsumerProguardFiles UP-TO-DATE
> Task :mergeReleaseShaders
> Task :compileReleaseShaders UP-TO-DATE
> Task :generateReleaseAssets UP-TO-DATE
> Task :packageReleaseAssets
> Task :packageReleaseRenderscript NO-SOURCE
> Task :processReleaseJavaRes NO-SOURCE
> Task :compileReleaseNdk NO-SOURCE
> Task :mergeReleaseJniLibFolders
> Task :transformNativeLibsWithMergeJniLibsForRelease UP-TO-DATE
> Task :transformNativeLibsWithSyncJniLibsForRelease UP-TO-DATE
17 actionable tasks: 8 executed, 9 up-to-date
         *********************************************************
WARNING: This version of firebase_database will break your Android build if it or its dependencies aren't compatible with AndroidX.
         See  for more information on the problem and how to fix it.
         This warning prints for all Android build failures. The real root cause of the error may be unrelated.
         *********************************************************

C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:10: error: cannot find symbol
import androidx.annotation.NonNull;
                          ^
  symbol:   class NonNull
  location: package androidx.annotation
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:11: error: cannot find symbol
import androidx.annotation.Nullable;
                          ^
  symbol:   class Nullable
  location: package androidx.annotation
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:233: error: cannot find symbol
  public void onMethodCall(final MethodCall call, @NonNull final Result result) {
                                                   ^
  symbol:   class NonNull
  location: class FirebaseDatabasePlugin
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:185: error: cannot find symbol
        String eventType, @NonNull DataSnapshot snapshot, String previousChildName) {
                           ^
  symbol:   class NonNull
  location: class FirebaseDatabasePlugin.EventObserver
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:199: error: cannot find symbol
    public void onCancelled(@NonNull DatabaseError error) {
                             ^
  symbol:   class NonNull
  location: class FirebaseDatabasePlugin.EventObserver
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:207: error: cannot find symbol
    public void onChildAdded(@NonNull DataSnapshot snapshot, String previousChildName) {
                              ^
  symbol:   class NonNull
  location: class FirebaseDatabasePlugin.EventObserver
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:212: error: cannot find symbol
    public void onChildRemoved(@NonNull DataSnapshot snapshot) {
                                ^
  symbol:   class NonNull
  location: class FirebaseDatabasePlugin.EventObserver
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:217: error: cannot find symbol
    public void onChildChanged(@NonNull DataSnapshot snapshot, String previousChildName) {
                                ^
  symbol:   class NonNull
  location: class FirebaseDatabasePlugin.EventObserver
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:222: error: cannot find symbol
    public void onChildMoved(@NonNull DataSnapshot snapshot, String previousChildName) {
                              ^
  symbol:   class NonNull
  location: class FirebaseDatabasePlugin.EventObserver
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:227: error: cannot find symbol
    public void onDataChange(@NonNull DataSnapshot snapshot) {
                              ^
  symbol:   class NonNull
  location: class FirebaseDatabasePlugin.EventObserver
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:166: error: cannot find symbol
    public void onComplete(@Nullable DatabaseError error, @NonNull DatabaseReference ref) {
                            ^
  symbol:   class Nullable
  location: class FirebaseDatabasePlugin.DefaultCompletionListener
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:166: error: cannot find symbol
    public void onComplete(@Nullable DatabaseError error, @NonNull DatabaseReference ref) {
                                                           ^
  symbol:   class NonNull
  location: class FirebaseDatabasePlugin.DefaultCompletionListener
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:333: error: cannot find symbol
                public Transaction.Result doTransaction(@NonNull MutableData mutableData) {
                                                         ^
  symbol: class NonNull
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.0.7\android\src\main\java\io\flutter\plugins\firebase\database\FirebaseDatabasePlugin.java:331: error: cannot find symbol
                @NonNull
                 ^
  symbol: class NonNull
14 errors

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.



BUILD FAILED in 2s


The plugin firebase_database could not be built due to the issue above. 

1
你有解决方案吗?我也遇到了同样的问题 :( - iPatel
3个回答

1
似乎 firebase_database 版本不适合您的应用程序。 您可以采取两种措施: 1. 更改 firebase_database 版本 2. 直接构建 .aap 文件
flutter build appbundle

有时候 APK 构建无法正常工作,但您的应用程序包将完美运行。 这是一个临时解决方案。


1

我在gradle.properties中添加了"android.enableR8=true",在升级flutter后解决了我的问题。


1
从这一行开始
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.2) classpath. You should manually set the same version via DependencyResolution

似乎您遇到了兼容性问题。首先尝试将您的类路径更改为:
com.android.tools.build:gradle:3.3.1

如果这对你不起作用,请按照此答案进行正确的迁移到Android X。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接