I'm creating 2 apps that shares the same code base (including their models), so I created a base package that I share across them.
The problem is that I'm not able to generate the related *.g.dart files for my respective models from the package.
This is what I got when I run the build command inside the package project:
[INFO] Generating build script...
[INFO] Generating build script completed, took 220ms
[WARNING] Configuring `json_serializable:json_serializable` in target `code_base:code_base` but this is not a known Builder
[SEVERE] Nothing can be built, yet a build was requested.
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 55ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 392ms
[INFO] Running build...
[INFO] Running build completed, took 2ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 54ms
[INFO] Succeeded after 65ms with 0 outputs (0 actions)
This is my pubspec.yaml:
name: code_base
description: Project base code
version: 0.0.1
author:
homepage:
environment:
sdk: ">=2.2.2 <3.0.0"
dependencies:
flutter:
sdk: flutter
dio: ^3.0.7
flutter_bloc: ^2.1.1
shared_preferences: ^0.5.6
connectivity: ^0.4.6+1
firebase_messaging: ^6.0.9
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^1.0.0
json_annotation: ^3.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages
build.yaml:
targets:
$default:
builders:
json_serializable:
options:
# Options configure how source code is generated for every
# `@JsonSerializable`-annotated class in the package.
#
# The default value for each is listed.
any_map: false
checked: false
create_factory: true
create_to_json: true
disallow_unrecognized_keys: false
explicit_to_json: true
field_rename: none
ignore_unannotated: false
include_if_null: true
nullable: true
Flutter 1.12.13+hotfix.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 27321ebbad (2 weeks ago) • 2019-12-10 18:15:01 -0800
Engine • revision 2994f7e1e6
Tools • Dart 2.7.0
You missed the
dev_dependencies:
json_serializable:
json_annotation should in dependencies, and json_serializable should in dev_dependencies.
Yeah, you're right, but install analyzer: ^0.39.2+1 solve my problem. :)
analyzer
Solved mine too but why ?
analyzer
Solved mine too but why ?
pkg:analyzer bug, I'm guessing
Same for me, solved with analyser !
Most helpful comment
You missed the
json_annotationshould independencies, andjson_serializableshould indev_dependencies.