efortuna / memechat

a meme-based chat application
542 stars 150 forks source link

Build errors with new flutter SDKs? #41

Closed chonghorizons closed 2 years ago

chonghorizons commented 4 years ago

I am having problems building this repo after cloning the github. You can reproduce this by trying to clone this repo and then build it.

TLDR version:

Getting build errors that I couldn't fix. I think it may be just a needing to update old pubspec.yaml and build.gradle files (mostly). However, my attempts so far have failed. I'll keep trying.

Loved the memechat video from 2017. Want to try to study this code, but having problems with getting the firebase to run. (Yes, I checked google-services.json)

Build.gradle missing or old

The android/app level build.gradle is missing the firebase implementation documents. My guess: this is because firebase for flutter was different in 2017 vs today.

One might need to add something like

    implementation 'com.google.firebase:firebase-analytics:17.3.0'
    implementation 'com.google.firebase:firebase-auth:19.3.0'
    implementation 'com.google.firebase:firebase-firestore:21.4.2'
    implementation 'com.google.firebase:firebase-storage:19.1.1'
    implementation 'com.google.firebase:firebase-database:19.2.1'

The android level build.gradle has an older version of google services (from 2017).

    // classpath 'com.google.gms:google-services:3.2.1'
        classpath 'com.google.gms:google-services:4.3.3'

AddListener type checks in 2020.

The addListener method gives a type checking error. This can be fixed by declaring the type. This is the fix I implemented.

    if (imageUrl != null) {
      NetworkImage image = NetworkImage(imageUrl);
      ImageStreamListener isl = ImageStreamListener((_, __) {
        animationController?.forward();
      });
      image
          .resolve(createLocalImageConfiguration(context))
          .addListener(isl);

Still can't build with Android Studio.

I'm still getting build errors with Android Studio. I've tried a few different things and they don't work.

If I don't include the implementation lines for firebase, I get Database can't connect errors. (makes sense... some files missing).

If I do include them, I get other errors.

I also tried starting a blank flutter repo and then copying in the code. Similar errors.

Here is one set of the errors I am getting:

Launching lib/main.dart on PH 1 in debug mode...
[!] Your app isn't using AndroidX.
    To avoid potential build failures, you can quickly migrate your app by following the steps on https://goo.gl/CP92wY.
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/howardchong/Proj2019/flutterDev/memechathocho/android/app/build.gradle' line: 65

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method implementation() for arguments [com.google.firebase:firebase-analytics:17.3.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* 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 18s
Finished with error: Gradle task assembleDebug failed with exit code 1

My flutter doctor in case it's helpful:

Macs-MacBook-Air:~ howardchong$ flutter doctor -v
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.14.6 18G2022,
    locale en-US)
    • Flutter version 1.12.13+hotfix.9 at
      /Users/howardchong/Proj2019/flutterDev/flutter
    • Framework revision f139b11009 (10 days ago), 2020-03-30 13:57:30 -0700
    • Engine revision af51afceb8
    • Dart version 2.7.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/howardchong/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.2, Build version 11B52
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 39.0.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1343-b01)

[✓] VS Code (version 1.39.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.6.0

[✓] Connected device (1 available)
    • PH 1 • PM1LHMA7B1300032 • android-arm64 • Android 10 (API 29)

• No issues found!
chonghorizons commented 4 years ago

Update: Getting the build to work, but I'm now getting database not connecting errors.


D/FlutterActivity(23758): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate(23758): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate(23758): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate(23758): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView(23758): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@5d7d4cc
D/FlutterActivityAndFragmentDelegate(23758): Executing Dart entrypoint: main, and sending initial route: /
Syncing files to device PH 1...
W/Gralloc3(23758): mapper 3.x is not supported
I/BiChannelGoogleApi(23758): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@335a92c
E/AccessibilityBridge(23758): VirtualView node must not be the root node.
D/FirebaseAuth(23758): Notifying id token listeners about user ( cfUQD68LScMy4g4zRPB1NwukeAC2 ).
D/FirebaseAuth(23758): Notifying auth state listeners about user ( cfUQD68LScMy4g4zRPB1NwukeAC2 ).
D/NetworkSecurityConfig(23758): No Network Security Config specified, using platform default
W/SyncTree(23758): Listen at / failed: DatabaseError: Permission denied
E/flutter (23758): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: DatabaseError(-3, Permission denied, )```

My hunch is this is a breaking change related to how firebase changed from 2017 to today. Still troubleshooting
chonghorizons commented 4 years ago

I think I might have figured out my error. I think I didn't enable Realtime Database and had Cloud Firestore enabled instead.

image

Testing.

chonghorizons commented 4 years ago

Can't get it to work with all the build.gradle stuff. I ended up making a new flutter project and copying the code in. That worked.

chonghorizons commented 4 years ago

This repo works for me, but it is kinda a mess.

TODO later: figure out what the gradle and AndroidManifest changes were that allowed this to work.

https://github.com/chonghorizons/memechat/

chonghorizons commented 2 years ago

Closing because it's old and other chat implementations have been shared. Underlying code is still interesting.