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 native executable. Running your Gradle and/or Flutter commands through kradle ensures you use the correct versions for these libraries. You can send commands through kradle directly or use the interactive wizard to configure.

Installation

A native kradle executable is added to the project workspace, when creating a new project using the Intellij/Android Studio IDE plugin. Simply create a new project using the project wizard.

You can also install the kradle tool from git or pub:

## Get from pub 
dart pub global activate klutter

## Get from git
dart pub global activate --source git https://github.com/buijs-dev/klutter-dart.git

## Use it globally
dart pub global run klutter:kradle

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. This blog post is updated for version 2024.1.beta. Check github for latest version.

Full kradle.yaml example:

bom-version: "2024.1.1.beta"
flutter-version: "3.10.6"
feature-protobuf-enabled: false
dependencies:
    klutter: "3.0.0"
    klutter_ui: "1.1.0"
    squint: "0.1.2"

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
protoc.url=https://github.com/protocolbuffers/protobuf/releases/download/v25.3/protoc-25.3-osx-universal_binary.zip

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.

Protoc.url

The URL used to download protoc. Protoc is required when using the protobuf feature.

Protobuf is available since klutter 2024.1.1.beta

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:

./kradle 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:

./kradle 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:

./kradle create 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. Option value is required to be the distribution to download in format major.minor.patch.platform.architecture.

Example command:

./kradle get flutter=3.10.6.windows.x64
Overwrite

Use the overwrite option to overwrite any existing distribution if present.

Example which overwrites any existing distribution:

./kradle get flutter=3.10.6.windows.x64 overwrite=true

Gradle

Gradle commands can be executed by using the gradle argument.

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

Flutter

Flutter commands can be executed by using the flutter argument.

# Run flutter doctor command.
./kradle flutter doctor

Wizard

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

./kradle

Written on November 13, 2023