⌘K

Nativeblocks Gradle Plugin

This document describes the functionality of the Nativeblocks Gradle Plugin, its associated tasks, and how to use them effectively in your Android development workflow.


Plugin Description

The Nativeblocks Gradle Plugin provides essential tools to streamline the upload and schema preparation process for server-driven blocks and actions generated by the Nativeblocks compiler.

Key Features:

  1. Sync Task: Uploads JSON files of Blocks and Actions to the Nativeblocks Studio.
  2. PrepareSchema Task: Prepares JSON schemas and saves them locally for integration with Nativeblocks DSL and CLI.

Plugin Overview

The Nativeblocks Gradle Plugin integrates seamlessly with Android Gradle projects. It introduces tasks that allow you to prepare and upload data with minimal configuration.


Available Tasks

1. Sync Task

  • Name: nativeblocksSync
  • Description: Uploads JSON files of Blocks and Actions to the Nativeblocks Studio.

How to Use:

  1. Add a nativeblocks.properties File:

    Create a nativeblocks.properties file in the root of your project and add the following details:

    endpoint=
    authToken=
    organizationId=
    

    These properties are specific to each Nativeblocks Studio account. You can find them in the Link Device section of Nativeblocks Studio.
    Note: If you are using the Community Version, you do not need to include endpoint, authToken, and organizationId.

  2. Add Plugin Configuration:

    Load the properties in your build.gradle file:

    def nativeblocksProps = new Properties()
    file("nativeblocks.properties").withInputStream { props.load(it) }
    
    nativeblocks {
        endpoint = nativeblocksProps.getProperty("endpoint").toString()
        authToken = nativeblocksProps.getProperty("authToken").toString()
        organizationId = nativeblocksProps.getProperty("organizationId").toString()
        basePackageName = "your.packagename.appname"
        moduleName = "your_module_name"
    }
    
  3. Run the Sync Command:

    #./gradlew nativeblocksSync+Flavor
    ./gradlew :app:nativeblocksSyncDebug
    

2. PrepareSchema Task

  • Name: nativeblocksPrepareSchema
  • Description: Prepares JSON schemas for use with the Nativeblocks DSL and CLI.

How to Use:

  1. Run the PrepareSchema Command:

    #./gradlew nativeblocksPrepareSchema+Flavor
    ./gradlew :app:nativeblocksPrepareSchemaDebug
    
  2. The task will generate JSON schema files in the .nativeblocks directory within your project.


How to Set Up the Plugin

Step 1: Add Plugin Dependency

Include the Nativeblocks Gradle plugin in your build.gradle file:

plugins {
    id("io.nativeblocks.nativeblocks-gradle-plugin").version("1.1.0")
}

Step 2: Configure Plugin Arguments

Define the required properties in the nativeblocks.properties file. These arguments ensure the plugin can communicate with the Nativeblocks Studio.


Step 3: Integrate Tasks in Your Workflow

Run the provided tasks (nativeblocksSync or nativeblocksPrepareSchema) based on your development needs.


Command Examples

Sync Command

Upload the generated JSON files to Nativeblocks Studio: nativeblocksSyncFlaver

#./gradlew nativeblocksSync+Flavor
./gradlew :app:nativeblocksSyncDebug

PrepareSchema Command

Prepare JSON schemas for local use or CLI tools:

#./gradlew nativeblocksPrepareSchema+Flavor
./gradlew :app:nativeblocksPrepareSchemaDebug

Workflow Integration

1. Setup:

Add the Nativeblocks Gradle Plugin to your project and configure the nativeblocks block in build.gradle.

2. Run Tasks:

Use the Gradle tasks (nativeblocksSync or nativeblocksPrepareSchema) to handle uploads and schema preparation.

3. Automate:

Integrate these tasks into your CI/CD pipeline to streamline the development and deployment process.