본문 바로가기
IT-dev

Fluttre news toolkit Build Error Troubleshooting

by 김현진_ 2023. 9. 5.

안녕하세요.

올초 flutter_news_toolkit을 이제서야 설치하다가 설치중 오류가 발생했는데, 유튜브나 스택오버플로우등 많은데서 어려움을 겪고 있더라구요. 저는 다음과 같은 방법으로 해결하여 방법을 공유드립니다.

 


This is Flutter News Toolkit build at 9 Sep. 2023
Official Doc: https://flutter.github.io/news_toolkit/

Fluter doctor -v

더보기
[✓] Flutter (Channel stable, 3.13.2, on Ubuntu 22.04.3 LTS 6.2.0-31-generic,
    locale en_US.UTF-8)
    • Flutter version 3.13.2 on channel stable at /home/ubu/Programs/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ff5b5b5fa6 (11 days ago), 2023-08-24 08:12:28 -0500
    • Engine revision b20183e040
    • Dart version 3.1.0
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /home/ubu/Android/Sdk
    • Platform android-33-ext5, build-tools 33.0.2
    • Java binary at:
      /home/ubu/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841/jbr/bin
      /java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 14.0.0-1ubuntu1.1
    • cmake version 3.22.1
    • ninja version 1.10.1
    • pkg-config version 0.29.2

[✓] Android Studio (version 2022.2)
    • Android Studio at
      /home/ubu/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841
    • Flutter plugin version 74.0.2
    • Dart plugin version 222.4582
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] Android Studio (version 2022.1)
    • Android Studio at /usr/local/android-studio
    • Flutter plugin version 73.0.2
    • Dart plugin version 221.6103.1
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.81.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.70.0

[✓] Connected device (3 available)

 

dart pub global activate mason_cli
dart pub global activate dart_frog_cli
mason add -g flutter_news_template
mason make flutter_news_template
dart_frog dev

Case 1. html dependendy not matched

packages/news_blocks_ui/lib/src/html.dart

html.dart  packages/news_blocks_ui/lib/src
	The argument type 'void Function(String?, Map<String, String>, Element?, dynamic)' can't be assigned to the parameter type 'void Function(String?, Map<String, String>, Element?)?'.

According to the flutter_news_example:

https://github.com/flutter/news_toolkit/blob/main/flutter_news_example/packages/news_blocks_ui/lib/src/html.dart

1. Change (url, context, attributes, element) to (url, attributes, element) 

        onLinkTap: (url, attributes, element) {
          if (url == null) return;
          final uri = Uri.tryParse(url);
          if (uri == null) return;
          launchUrl(uri).ignore();
        },

 

2. Change the version of flutter_html from ^3.0.0-alpha.6 to ^3.0.0-beta.2 on packages/news_blocks_ui/pubspec.yaml

	flutter_html: ^3.0.0-beta.2

 

3. Don't forget "flutter clean" & "flutter pub get" after these changes

flutter clean
flutter pub get

If not, you might see this error

packages/news_blocks_ui/lib/src/html.dart:24:20: Error: The argument type 'void Function(String?, RenderContext, Map<String, String>)' can't be assigned to the parameter type 'void Function(String?, RenderContext, Map<String, String>, Element?)?'.
 - 'RenderContext' is from 'package:flutter_html/html_parser.dart' ('../../.pub-cache/hosted/pub.dev/flutter_html-3.0.0-alpha.6/lib/html_parser.dart').
 - 'Map' is from 'dart:core'.
 - 'Element' is from 'package:html/dom.dart' ('../../.pub-cache/hosted/pub.dev/html-0.15.1/lib/dom.dart').
        onLinkTap: (url, attributes, element) {

Case 2. Update build.gradle

After Case1, some compile errors occur.

* Where:
Script '/home/$USER/Programs/flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' line: 1297

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDevelopmentDebug'.
> Process 'command '/home/$USER/Programs/flutter/bin/flutter'' finished with non-zero exit value 1

 

1.Update Root-level (project-level) Gradle file (<project>/build.gradle):

buildscript {
    ext.kotlin_version = '1.9.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath 'com.google.gms:google-services:4.3.15'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

 

2. Update Module (app-level) Gradle file (<project>/<app-module>/build.gradle):

https://developer.android.com/build/migrate-to-kotlin-dsl#migrate-buildscript

  1. add compileOptions
  2. change GradleException -> FileNotFoundException
// if (flutterRoot == null) {
//     throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
// }
if (flutterRoot == null) {
    throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

android {
	compileOptions {
		sourceCompatibility kotlin_version
		targetCompatibility kotlin_version
	}
    ...
}

And I also suggest you to change the SdkVersion to 33.
Because new apps must target at lease 33. [https://developer.android.com/google/play/requirements/target-sdk]

And update dependencies latest.

android {
	defaultConfig {
        applicationId "com.flutter.news.dev"
        minSdkVersion 33
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
 }
    
 
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.guava:guava:32.1.2-jre'
    implementation(platform("com.google.firebase:firebase-bom:32.2.3"))
    implementation("com.google.firebase:firebase-crashlytics-ktx")
    implementation("com.google.firebase:firebase-analytics-ktx")    
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

 

3. If you have some kind of watcher error

flutter pub upgrade

This worked for me.

Warning: unexpected element (uri:"", local:"extension-level"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
../../.pub-cache/hosted/pub.dev/watcher-1.0.2/lib/src/constructable_file_system_event.dart:7:57: Error: The class 'FileSystemEvent' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
abstract class _ConstructableFileSystemEvent implements FileSystemEvent {
                                                        ^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script '/home/ubu/Programs/flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' line: 1297

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDevelopmentDebug'.
> Process 'command '/home/ubu/Programs/flutter/bin/flutter'' finished with non-zero exit value 1

* 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 16s
Running Gradle task 'assembleDevelopmentDebug'...                  17.2s
Exception: Gradle task assembleDevelopmentDebug failed with exit code 1

 

Suggestion 1. update dart_frog version

If you followed the https://flutter.github.io/news_toolkit/, the installed dart_frog version is 1.0.0

user@user-System:~$ dart_frog --version
1.0.0

However, mason made flutter_news_template with the old version of dart_frog 0.3.2 on $PROEJCT/api/pubspec.yaml

dependencies:
  dart_frog: ^1.0.0

 

댓글