【问题标题】:Flutter cant buildl apkFlutter 无法构建 apk
【发布时间】:2020-01-27 06:01:16
【问题描述】:

我正在用这个插件列表制作一个颤振应用程序:

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. 

【问题讨论】:

  • 你有解决办法吗?面临同样的问题:(

标签: firebase flutter


【解决方案1】:

听起来 firebase_database 版本不适合您的应用程序。 你可以在这里做两件事。 1.更改firebase_database版本 2.直接构建.aap文件

flutter build appbundle

有时 APK 构建不起作用,但您的 App Bundle 会完美运行。 这是一个临时解决方案。

【讨论】:

    【解决方案2】:

    从这一行

    > 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
    

    如果这对您不起作用,请按照此answer 正确迁移到 android X

    【讨论】:

      【解决方案3】:

      我在 gradle.properties 中添加了“android.enableR8=true”,它在我升级 Flutter 后解决了我的问题。

      【讨论】:

        猜你喜欢
        • 2020-05-15
        • 1970-01-01
        • 1970-01-01
        • 2021-05-08
        • 2021-05-03
        • 2021-04-22
        • 2016-12-15
        • 1970-01-01
        相关资源
        最近更新 更多