Skip to content

Commit

Permalink
Build Protobuf Files for App (eclipse-velocitas#4)
Browse files Browse the repository at this point in the history
This PR makes sure, that the proto file which is put inside
the app/src/main/proto folder correctly generates the corresponding
services.
  • Loading branch information
wba2hi authored Oct 9, 2024
1 parent 403eb41 commit 279fa9d
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 13 deletions.
45 changes: 45 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.protobuf)
}

android {
Expand Down Expand Up @@ -51,9 +52,53 @@ android {
}
}

protobuf {
protoc {
artifact = libs.protoc.asProvider().get().toString()
}
plugins {
create("java") {
artifact = libs.protoc.gen.grpc.java.get().toString()
}
create("grpc") {
artifact = libs.protoc.gen.grpc.java.get().toString()
}
create("grpckt") {
artifact = libs.protoc.gen.grpc.kotlin.get().toString() + ":jdk8@jar"
}
}
generateProtoTasks {
all().forEach {
it.builtins {
create("java") {
option("lite")
}
create("kotlin") {
option("lite")
}
}
it.plugins {
create("grpc") {
option("lite")
}
create("grpckt") {
option("lite")
}
}
}
}
}

dependencies {
implementation(project(":sdk"))

implementation(libs.grpc.okhttp)
implementation(libs.grpc.protobuf.lite)
implementation(libs.grpc.stub)
implementation(libs.grpc.kotlin.stub)

implementation(libs.protobuf.kotlin.lite)

implementation(libs.androidx.fragment.ktx)

implementation(libs.androidx.car.app)
Expand Down
27 changes: 14 additions & 13 deletions app/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,35 @@ com.almworks.sqlite4java:sqlite4java:1.0.392=debugUnitTestRuntimeClasspath,relea
com.google.android:annotations:4.1.1.4=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.auto.value:auto-value-annotations:1.10.1=debugUnitTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.auto.value:auto-value-annotations:1.6.3=debugRuntimeClasspath,releaseRuntimeClasspath
com.google.code.findbugs:jsr305:3.0.2=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.code.findbugs:jsr305:3.0.2=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
com.google.code.gson:gson:2.10.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.errorprone:error_prone_annotations:2.23.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.guava:failureaccess:1.0.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.guava:guava:32.1.3-android=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.errorprone:error_prone_annotations:2.23.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
com.google.guava:failureaccess:1.0.1=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
com.google.guava:guava:32.1.3-android=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
com.google.protobuf:protobuf-javalite:3.25.3=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.protobuf:protobuf-kotlin-lite:3.25.3=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.google.j2objc:j2objc-annotations:2.8=debugAndroidTestCompileClasspath,debugCompileClasspath,debugUnitTestCompileClasspath,releaseCompileClasspath,releaseUnitTestCompileClasspath
com.google.protobuf:protobuf-javalite:3.25.3=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
com.google.protobuf:protobuf-kotlin-lite:3.25.3=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
com.google.protobuf:protoc:3.25.3=protobufToolsLocator_protoc
com.ibm.icu:icu4j:72.1=debugUnitTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.squareup.okio:okio-jvm:3.4.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
com.squareup.okio:okio:3.4.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-api:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-api:1.64.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-context:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-core:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-kotlin-stub:1.4.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-okhttp:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-protobuf-lite:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-stub:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-kotlin-stub:1.4.1=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-okhttp:1.64.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-protobuf-lite:1.64.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-stub:1.64.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
io.grpc:grpc-util:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
io.grpc:protoc-gen-grpc-java:1.64.0=protobufToolsLocator_grpc
io.grpc:protoc-gen-grpc-kotlin:1.4.1=protobufToolsLocator_grpckt
io.perfmark:perfmark-api:0.26.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
javax.annotation:javax.annotation-api:1.3.2=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
javax.annotation:javax.annotation-api:1.3.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
javax.inject:javax.inject:1=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
junit:junit:4.13.2=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
org.bouncycastle:bcprov-jdk18on:1.72=debugUnitTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
org.checkerframework:checker-qual:3.37.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
org.checkerframework:checker-qual:3.37.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
org.codehaus.mojo:animal-sniffer-annotations:1.23=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
org.conscrypt:conscrypt-openjdk-uber:2.5.2=debugUnitTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
org.hamcrest:hamcrest-core:1.3=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/example/service/CarService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.example.service

interface CarService {
fun lockDoor(): Boolean
fun unlockDoor(): Boolean
}
58 changes: 58 additions & 0 deletions app/src/main/java/com/example/service/GrpcCarService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.example.service

import android.util.Log
import door.DoorGrpc
import door.DoorGrpc.DoorFutureStub
import door.DoorService
import io.grpc.Grpc
import io.grpc.InsecureChannelCredentials

private const val TAG = "SampleServiceImpl"

class GrpcCarService(
host: String,
port: Int,
) : CarService {

private val doorService: DoorFutureStub

init {
Log.i(TAG, "Connecting to gRPC service at $host:$port")

val channelCredentials = InsecureChannelCredentials.create()
val channel = Grpc.newChannelBuilderForAddress(host, port, channelCredentials).build()

doorService = DoorGrpc.newFutureStub(channel)
}

// Door service
override fun lockDoor(): Boolean {
val request = DoorService.LockRequest.newBuilder().build()
val response = doorService.lock(request).get() // blocking call
Log.i(TAG, "lockDoor: Got response: " + response.getCode())
return response.getCode() == DoorService.BCMReturnCode.BCM_RETURN_CODE_SUCCESS
}

override fun unlockDoor(): Boolean {
val request = DoorService.UnlockRequest.newBuilder().build()
val response = doorService.unlock(request).get() // blocking call
Log.i(TAG, "unlockDoor: Got response: " + response.getCode())
return response.getCode() == DoorService.BCMReturnCode.BCM_RETURN_CODE_SUCCESS
}
}
4 changes: 4 additions & 0 deletions app/src/proto/door.proto → app/src/main/proto/door.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* Provides door control and status service, one atomic service for each door.
*/
syntax = "proto3";

package door;

option java_outer_classname = "DoorService";

service Door {
/* Unlock the door. */
rpc Unlock(UnlockRequest) returns (UnlockResponse);
Expand Down

0 comments on commit 279fa9d

Please sign in to comment.