Git Product home page Git Product logo

hellokts's Introduction

HelloKTS

KTS project practise

Tech-stack

Extra

How to integrate with Protobuf into Android with Kotlin & KTS

I speed more than two hours to add protobuf dependence into my project, because the reference is so limited, I mired down in mud. Finally, I make my project with protobuf work.

Here are some key steps:

  1. Add protobuf gradle in classpath

    buildscript {
        repositories {
            maven("https://plugins.gradle.org/m2/")
        }
        dependencies {
            classpath(Gradle.Dependency.PROTOBUF_GRADLE)
        }
    }
    
  2. Import protobuf into your app.gradle to use protobuf

    import com.google.protobuf.gradle.*
    
  3. Add protobuf plugin

    plugins {
        id(Gradle.Plugins.PROTOBUF)
    }
    
  4. Add protobuf-java dependence

    implementation("com.google.protobuf:protobuf-java:${Deps.Protobuf.PROTO_VERSION}")
    
  5. Config protobuf with grpc and javalite to avoid package com.google.protobuf does not exist

    protobuf {
        protoc {
            artifact = Deps.Protobuf.PROTO_C
        }
        plugins {
            id("grpc") {
                artifact = Deps.Protobuf.Plugin.GRPC
            }
            id("javalite") {
                artifact = Deps.Protobuf.Plugin.JAVALITE
            }
        }
        generateProtoTasks {
            all().forEach {
                it.plugins {
                    id("grpc") {
                        option("lite")
                    }
                    id("javalite")
                }
            }
        }
    }
    

References:

  1. https://github.com/JetBrains/Arend/blob/master/build.gradle.kts
  2. https://github.com/google/protobuf-gradle-plugin/blob/master/examples/exampleKotlinDslProject/build.gradle.kts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.