Bryansq2nt
Bryansq2nt

Reputation: 394

Flutter cant buildl apk

I am making a flutter app with this list of plugins:

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

I already migrated to AndroidX, my app runs in my emulator but when I try to run flutter build apk, android studio show me this error:

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. 

Upvotes: 4

Views: 7114

Answers (3)

Manuel Mühlemann
Manuel Mühlemann

Reputation: 1051

I added "android.enableR8=true" to gradle.properties and it fixed my issue after i upgraded flutter.

Upvotes: 1

griffins
griffins

Reputation: 8246

from this line

> 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

seems like you have compatibility issues. First try changing your classpath to

com.android.tools.build:gradle:3.3.1

if this doesn't work for you, follow this answer to migrate properly to android X

Upvotes: 1

Akram Chauhan
Akram Chauhan

Reputation: 1156

Sounds like firebase_database version is not correct for your application. You can do two things here. 1. Change firebase_database version 2. Direct build .aap file

flutter build appbundle

Some time APK build not works but your App Bundle will work perfectly. This is a temp solution.

Upvotes: 1

Related Questions