Skip to content

Commit 279fa9d

Browse files
authored
Build Protobuf Files for App (eclipse-velocitas#4)
This PR makes sure, that the proto file which is put inside the app/src/main/proto folder correctly generates the corresponding services.
1 parent 403eb41 commit 279fa9d

File tree

5 files changed

+143
-13
lines changed

5 files changed

+143
-13
lines changed

app/build.gradle.kts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
plugins {
1818
alias(libs.plugins.android.application)
1919
alias(libs.plugins.kotlin.android)
20+
alias(libs.plugins.protobuf)
2021
}
2122

2223
android {
@@ -51,9 +52,53 @@ android {
5152
}
5253
}
5354

55+
protobuf {
56+
protoc {
57+
artifact = libs.protoc.asProvider().get().toString()
58+
}
59+
plugins {
60+
create("java") {
61+
artifact = libs.protoc.gen.grpc.java.get().toString()
62+
}
63+
create("grpc") {
64+
artifact = libs.protoc.gen.grpc.java.get().toString()
65+
}
66+
create("grpckt") {
67+
artifact = libs.protoc.gen.grpc.kotlin.get().toString() + ":jdk8@jar"
68+
}
69+
}
70+
generateProtoTasks {
71+
all().forEach {
72+
it.builtins {
73+
create("java") {
74+
option("lite")
75+
}
76+
create("kotlin") {
77+
option("lite")
78+
}
79+
}
80+
it.plugins {
81+
create("grpc") {
82+
option("lite")
83+
}
84+
create("grpckt") {
85+
option("lite")
86+
}
87+
}
88+
}
89+
}
90+
}
91+
5492
dependencies {
5593
implementation(project(":sdk"))
5694

95+
implementation(libs.grpc.okhttp)
96+
implementation(libs.grpc.protobuf.lite)
97+
implementation(libs.grpc.stub)
98+
implementation(libs.grpc.kotlin.stub)
99+
100+
implementation(libs.protobuf.kotlin.lite)
101+
57102
implementation(libs.androidx.fragment.ktx)
58103

59104
implementation(libs.androidx.car.app)

app/gradle.lockfile

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,35 @@ com.almworks.sqlite4java:sqlite4java:1.0.392=debugUnitTestRuntimeClasspath,relea
5252
com.google.android:annotations:4.1.1.4=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
5353
com.google.auto.value:auto-value-annotations:1.10.1=debugUnitTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
5454
com.google.auto.value:auto-value-annotations:1.6.3=debugRuntimeClasspath,releaseRuntimeClasspath
55-
com.google.code.findbugs:jsr305:3.0.2=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
55+
com.google.code.findbugs:jsr305:3.0.2=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
5656
com.google.code.gson:gson:2.10.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
57-
com.google.errorprone:error_prone_annotations:2.23.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
58-
com.google.guava:failureaccess:1.0.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
59-
com.google.guava:guava:32.1.3-android=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
57+
com.google.errorprone:error_prone_annotations:2.23.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
58+
com.google.guava:failureaccess:1.0.1=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
59+
com.google.guava:guava:32.1.3-android=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
6060
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
61-
com.google.protobuf:protobuf-javalite:3.25.3=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
62-
com.google.protobuf:protobuf-kotlin-lite:3.25.3=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
61+
com.google.j2objc:j2objc-annotations:2.8=debugAndroidTestCompileClasspath,debugCompileClasspath,debugUnitTestCompileClasspath,releaseCompileClasspath,releaseUnitTestCompileClasspath
62+
com.google.protobuf:protobuf-javalite:3.25.3=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
63+
com.google.protobuf:protobuf-kotlin-lite:3.25.3=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
6364
com.google.protobuf:protoc:3.25.3=protobufToolsLocator_protoc
6465
com.ibm.icu:icu4j:72.1=debugUnitTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
6566
com.squareup.okio:okio-jvm:3.4.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
6667
com.squareup.okio:okio:3.4.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
67-
io.grpc:grpc-api:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
68+
io.grpc:grpc-api:1.64.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
6869
io.grpc:grpc-context:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
6970
io.grpc:grpc-core:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
70-
io.grpc:grpc-kotlin-stub:1.4.1=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
71-
io.grpc:grpc-okhttp:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
72-
io.grpc:grpc-protobuf-lite:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
73-
io.grpc:grpc-stub:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
71+
io.grpc:grpc-kotlin-stub:1.4.1=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
72+
io.grpc:grpc-okhttp:1.64.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
73+
io.grpc:grpc-protobuf-lite:1.64.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
74+
io.grpc:grpc-stub:1.64.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
7475
io.grpc:grpc-util:1.64.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
7576
io.grpc:protoc-gen-grpc-java:1.64.0=protobufToolsLocator_grpc
7677
io.grpc:protoc-gen-grpc-kotlin:1.4.1=protobufToolsLocator_grpckt
7778
io.perfmark:perfmark-api:0.26.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
78-
javax.annotation:javax.annotation-api:1.3.2=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
79+
javax.annotation:javax.annotation-api:1.3.2=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
7980
javax.inject:javax.inject:1=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
8081
junit:junit:4.13.2=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
8182
org.bouncycastle:bcprov-jdk18on:1.72=debugUnitTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
82-
org.checkerframework:checker-qual:3.37.0=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
83+
org.checkerframework:checker-qual:3.37.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
8384
org.codehaus.mojo:animal-sniffer-annotations:1.23=debugRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseUnitTestRuntimeClasspath
8485
org.conscrypt:conscrypt-openjdk-uber:2.5.2=debugUnitTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
8586
org.hamcrest:hamcrest-core:1.3=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2024 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Apache License, Version 2.0 which is available at
6+
* https://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
* License for the specific language governing permissions and limitations
12+
* under the License.
13+
*
14+
* SPDX-License-Identifier: Apache-2.0
15+
*/
16+
17+
package com.example.service
18+
19+
interface CarService {
20+
fun lockDoor(): Boolean
21+
fun unlockDoor(): Boolean
22+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2024 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Apache License, Version 2.0 which is available at
6+
* https://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
* License for the specific language governing permissions and limitations
12+
* under the License.
13+
*
14+
* SPDX-License-Identifier: Apache-2.0
15+
*/
16+
17+
package com.example.service
18+
19+
import android.util.Log
20+
import door.DoorGrpc
21+
import door.DoorGrpc.DoorFutureStub
22+
import door.DoorService
23+
import io.grpc.Grpc
24+
import io.grpc.InsecureChannelCredentials
25+
26+
private const val TAG = "SampleServiceImpl"
27+
28+
class GrpcCarService(
29+
host: String,
30+
port: Int,
31+
) : CarService {
32+
33+
private val doorService: DoorFutureStub
34+
35+
init {
36+
Log.i(TAG, "Connecting to gRPC service at $host:$port")
37+
38+
val channelCredentials = InsecureChannelCredentials.create()
39+
val channel = Grpc.newChannelBuilderForAddress(host, port, channelCredentials).build()
40+
41+
doorService = DoorGrpc.newFutureStub(channel)
42+
}
43+
44+
// Door service
45+
override fun lockDoor(): Boolean {
46+
val request = DoorService.LockRequest.newBuilder().build()
47+
val response = doorService.lock(request).get() // blocking call
48+
Log.i(TAG, "lockDoor: Got response: " + response.getCode())
49+
return response.getCode() == DoorService.BCMReturnCode.BCM_RETURN_CODE_SUCCESS
50+
}
51+
52+
override fun unlockDoor(): Boolean {
53+
val request = DoorService.UnlockRequest.newBuilder().build()
54+
val response = doorService.unlock(request).get() // blocking call
55+
Log.i(TAG, "unlockDoor: Got response: " + response.getCode())
56+
return response.getCode() == DoorService.BCMReturnCode.BCM_RETURN_CODE_SUCCESS
57+
}
58+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
* Provides door control and status service, one atomic service for each door.
33
*/
44
syntax = "proto3";
5+
56
package door;
7+
8+
option java_outer_classname = "DoorService";
9+
610
service Door {
711
/* Unlock the door. */
812
rpc Unlock(UnlockRequest) returns (UnlockResponse);

0 commit comments

Comments
 (0)