flutterbuildandroid-productflavors

Flutter flavors


I am developing a flutter app. I want to add two different flavors to separate out few functionalities specific to flavor. I have followed this documentation. Here is my pubspec.yaml file.

name: flutter_app
version: 1.0.20+20

environment:
  sdk: ">=2.3.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  provider: ^4.0.1
  cupertino_icons: ^0.1.2
  intl: ^0.16.0
  shared_preferences:
  http: ^0.12.0+4
  sqflite: ^1.2.0
  path_provider:
  permission_handler: ^4.1.0
  package_info: ^0.4.0+18
  flutter_localizations:
    sdk: flutter
  #flutter_local_notifications: ^0.7.1+1
  #firebase_messaging: ^5.0.1+1
  #fluttertoast: ^3.1.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_flavorizr: ^1.0.7

flavorizr:
  app:
    android:
      flavorDimensions: "flavor-type"
    ios:

  flavors:
    mainapp:
      app:
        name: "Main App"

      android:
        applicationId: "com.example.app1"

      ios:
        bundleId: "com.example.app1"

    banana:
      master:
        name: "App Master"

      android:
        applicationId: "com.example.app2"
      ios:
        bundleId: "com.example.app2"

flutter:
  uses-material-design: true
  assets:
    - assets/
    - assets/fonts/
    - assets/drawables/
    - assets/icon/
    - assets/lang/en.json
    - assets/lang/de.json
    - assets/lang/de-DE.json
    - assets/lang/de-CH.json
    - assets/lang/de-AT.json
    - assets/lang/en-IN.json

  fonts:
    - family: Poppins-Bold
      fonts:
        - asset: assets/fonts/Poppins-Bold.ttf
    - family: Poppins-Medium
      fonts:
        - asset: assets/fonts/Poppins-Medium.ttf

After running flutter pub run flutter_flavorizr, i get the following error.

The following fields were missing: [app]. Read the docs for further details
Unhandled exception:
NoSuchMethodError: The getter 'flavorizr' was called on null.
Receiver: null
Tried calling: flavorizr
       Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
       Processor._initAvailableProcessors (package:flutter_flavorizr/processors/processor.dart:110:18)
       new Processor (package:flutter_flavorizr/processors/processor.dart:88:5)
       execute (package:flutter_flavorizr/flutter_flavorizr.dart:52:25)
       main (file:///D:/Users/Dhaval/Flutter/.pub-cache/hosted/pub.dartlang.org/flutter_flavorizr-1.0.7/bin/flutter_flavorizr.dart:4:3)
       _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
       _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
pub finished with exit code 255

Am I missing out something ? How can I solve this issue ? Any help appreciated. Thank you.


Solution

  • I had the same problem. Posting it in case this helps someone else. I spent quite a bit of time looking around. The error messages are generic and cryptic and I could not find any leads.
    So I reviewed their code. It turns out that the error message is not related to the issue. This error is thrown when the flavorizer block in my pubscpec.yaml was not correct. Once I reviewed the section and corrected the mistakes, the command worked.