Search code examples
androidflutterbuildapkcross-platform

Are code generation packages like json_serializable and freezed automatically excluded from release builds in Flutter?


Is there any information if code generation packages like (json_serializable, freezed) are automatically ignored when I build a release version (apk/appbundle) or shall I remove them manually from pubspec.yaml?

build a release version while I am using code generation packages


Solution

  • In pubspec.yaml, there are two sections for the packages your project uses: dependencies and dev_dependencies.

    • dependencies: These packages affect both the compilation and runtime behavior of your app since they are part of the app's package.
    • dev_dependencies: These packages are used during development (e.g., for testing or code generation) but do not impact the app's runtime behavior. Read more.

    Code generation packages, like the ones you mentioned, typically provide separate packages for dependencies and dev_dependencies. Therefore, you don't need to remove anything manually when building a release version of your app.

    For example:

    dependencies: # Affects both compilation and runtime
      freezed_annotation: ^2.4.4
      json_annotation: ^4.9.0
    
    dev_dependencies: # No impact on runtime behavior
      build_runner: ^2.4.12
      freezed: ^2.5.7
      json_serializable: ^6.8.0