Kradle: CLI Tool for Klutter

Kradle is an executable tool to create a new independent Klutter project. Create a new project with the click of a button without having any frameworks installed (including Flutter).

Kradle can be used on any platform using the kradlew or kradlew.bat script. Running your Gradle and/or Flutter commands through the kradle-wrapper ensures you use the correct versions for these libraries. You can send commands through the kradle-wrapper directly or use the interactive wizard to configure.

Installation

Get the executable from GitHub.

Configuration

Kradle can be configured by using 2 files:

Project configuration is stored in the kradle.yaml. User (private) configuration is stored in the kradle.env.

Kradle.yaml

The kradle.yaml is project specific and should be version-controlled and stored with your project sources. The compiler plugin uses the kradle.yaml as input.

The Klutter Compiler is introduced in version 2023.1.1.beta, which the blog post is based on. Check github for latest version.

Full kradle.yaml example:

bom-version: "2023.3.1.beta"
flutter-version: "3.10.6"
dependencies:
    klutter: "2.0.0"
    klutter_ui: "1.0.1"
    squint: "0.1.2"
    embedded:
       - "org.jetbrains.kotlinx:kotlinx-datetime:0.4.0"

Kradle.env

Local or user configuration is stored in the kradle.env. Properties:

Full example:

cache=/Users/alberto/.kradle/cache/
output.path=/Users/alberto/IdeaProjects/my_plugin/platform/build/klutter
skip.codegen=false

Cache

Location where kradle will store its downloads (like Flutter). Using the same cache location for multiple projects ensures kradle won’t download the same Flutter version multiple times.

Output.path

Location where kradle will store project logging and other intermediate files.

Skip.codegen

Boolean value to skip code generation phase of the build task. In general this should be set to false (or omitted entirely) because the generated code should be kept in-line with the Kotlin platform code.

Commands

Kradle

Kradle commands:

Build

Build the iOS and Android artifacts and generate all boilerplate code.

Build is always required to run the app on a device when changes are done in the platform module.

Example:

./kradlew build

Clean

Options:

Cache

Remove all files and/or folders from the kradle cache folder. The cache folder is by default set to user.home/.kradle/cache. It can be overwritten by setting the cache property in kradle.env. The kradle.env is stored next to the kradlew scripts.

Default kradle.env cache setting:

cache=/.kradle/cache/

Example command:

./kradlew clean cache

Create

Create a new Klutter project.

Required arguments:

  • root: The root folder of the project.
  • name: The name of the project (and subsequently the Flutter plugin).
  • group: The group/organisation name of the project.
  • flutter: The Flutter distribution to use.

Example:

./kradlew create --root "./" --name "my_plugin" --group "com.example" --flutter "3.10.6.macos.arm64"

Configuration (Optional)

Path to a configuration file, e.g. kradle.yaml. This yaml can be used to configure project versions and dependencies.

Example yaml:

bom-version: "2023.3.1.beta"
flutter-version: "3.10.6"
dependencies:
    klutter: "2.0.0"
    klutter_ui: "1.0.1"
    squint: "0.1.2"
    embedded:
       - "org.jetbrains.kotlinx:kotlinx-datetime:0.4.0"

Example command:

./kradlew create --config "./foo/bar/kradle.yaml" --root "./" --name "my_plugin" --group "com.example" --flutter "3.10.6.macos.arm64"

Get

Get project dependencies and store them in the kradle cache. Options:

Get Flutter

Get a Flutter distribution which is compatible with Klutter. Options:

Dist

The distribution to download in format major.minor.patch.platform.architecture.

Example command:

./kradlew get flutter --dist "3.10.6.windows.x64"
Overwrite

Overwrite any existing distribution if present.

Example which overwrites any existing distribution:

./kradlew get flutter --dist "3.10.6.windows.x64" --overwrite

Gradle

Gradle commands can be executed by using the -g argument.

# Run gradle clean build in the folder /platform.
./kradlew -g clean build -p "platform"

Flutter

Flutter commands can be executed by using the -f argument.

# Run flutter doctor command.
./kradlew -f doctor

Wizard

When no argument is given then the interactive wizard is started.

./kradlew

Written on November 13, 2023