Kotlin on google cloud platform

A community-supported project

Quickstart Community Tutorials

Build rich backends in your favorite language

  • Create and deploy autoscaling Kotlin backends for your mobile apps
  • Write Kotlin using your favorite Java frameworks and libraries
  • Use fully-managed MySQL/PostgreSQL or Firebase for your application database
  • Run Kotlin in a containerized application at scale on Google Kubernetes Engine
  • Use IntelliJ with Google Cloud Tools Plugins to add Google Cloud API libraries and deploy to App Engine.
Kotlin IDE

Build autoscaling backends for your mobile apps

Quickly develop autoscaling backends to do the work for your Android applications.

Start Codelab
Train Custom Machine Learning Models image

Write Kotlin using your favorite Java and Kotlin frameworks

Learn how to build an application on Spring Boot, Spark, and Ktor. Integrate your applications with MySQL using Cloud SQL.

View Tutorials
Access all of google cloud with kotlin

Build your applications in Kotlin using Google Cloud APIs and services.

Upload files to Google Cloud Storage
Analyze images with the Cloud Vision API
Call Firestore from a Kotlin Backend
Upload Files to Google Cloud Storage
1
Set up a Google Cloud Platform project
2
Add dependencies to your project
Add the Google Cloud Storage client library to your gradle.build under dependencies:
compile group: 'com.google.cloud', name: 'google-cloud-storage', version: '1.36.0'
3
Write your code
// import com.google.cloud.storage.StorageOptions
val storage = StorageOptions.getDefaultInstance().service
val bucket = storage.get(bucketName) ?: error("Bucket $bucketName does not exist.")

println("Listing all blobs in bucket $bucketName:")
bucket.list().iterateAll().forEach { blob ->
    println("${blob.name} (content-type: ${blob.contentType}, size: ${blob.size})")
}
Analyze images with the Cloud Vision API
1
Set up a Google Cloud Platform project
2
Add dependencies to your project
Add the Google Cloud Vision client library to your gradle.build under dependencies:
compile group: 'com.google.cloud', name: 'google-cloud-vision', version: '1.35.0'
3
Write your code
// import com.google.cloud.vision.v1.ImageAnnotatorClient
// import java.io.File
val imgProto = ByteString.copyFrom(File(imageFileName).readBytes())
val vision = ImageAnnotatorClient.create()

// Set up the Cloud Vision API request.
val img = Image.newBuilder().setContent(imgProto).build()
val feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build()
val request = AnnotateImageRequest.newBuilder()
    .addFeatures(feat)
    .setImage(img)
    .build()

// Call the Cloud Vision API and perform label detection on the image.
val result = vision.batchAnnotateImages(arrayListOf(request))

// Print the label annotations for the first response.
result.responsesList[0].labelAnnotationsList.forEach { label ->
    println("${label.description} (${(label.score * 100).toInt()}%)")
}
Call Firestore from a Kotlin Backend
1
Set up a Google Cloud Platform project
2
Add dependencies to your project
Add the Google Cloud Firestore client library to your gradle.build under dependencies:
compile group: 'com.google.cloud', name: 'google-cloud-firestore', version: '0.58.0-beta'
3
Write your code
// Create the client.
val db = FirestoreOptions.newBuilder()
    .setTimestampsInSnapshotsEnabled(true)
    .build()
    .service

// Fetch the document reference and data object.
val docRef = db.collection(collectionName).document(documentName)
val data = docRef
        .get() // future
        .get() // snapshot
        .data ?: error("Document $collectionName:$documentName not found") // MutableMap

// Print the retrieved data.
data.forEach { key, value -> println("$key: $value") }
Quickly find and debug issues

Google Stackdriver provides powerful monitoring, logging, and diagnostics. It equips you with insight into the health, performance, and availability of cloud-powered applications, enabling you to find and fix issues faster.

Google Stackdriver
Google Stackdriver
Unified monitoring, logging, and diagnostics for applications on Google Cloud Platform and AWS.
Stackdriver Error Reporting
Stackdriver Error Reporting
A walk through of getting an error alert and investigating the error in the Google Cloud Console.
Stackdriver Monitor, diagnose, and fix
Stackdriver Monitor, diagnose, and fix
In this video, Aja Hammerly uses Stackdriver to find and fix some subtle errors in an example app, and you'll learn how to use Stackdriver on your own projects.
Learn more
Kotlin on GCP communities

Got something to say? Join our community to ask questions, or just chat with the experts at Google who help build Kotlin for Google Cloud Platform.