I followed this guide to add gRPC to my Android project, but the proto file does not seem to generate code.
I placed book.proto under app\src\main\java\com\example\android together with my Kotlin code.
That's my project's build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Tar's:
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.15' // gRPC
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
That's my module build.gradle:
plugins {
id 'com.android.application'
id 'com.google.protobuf' // Tar's: gRPC
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.android"
minSdkVersion 28
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures { // Tar: for using ObservableList, which is part of the Data Binding Library - see https://stackoverflow.com/questions/66352403/observablelist-is-missing-in-android-studio and https://developer.android.com/topic/libraries/data-binding/start
dataBinding true
}
}
// Tar's: gRPC {
protobuf {
protoc { artifact = 'com.google.protobuf:protoc:3.10.0' }
plugins {
javalite { artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0" }
grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.25.0' // CURRENT_GRPC_VERSION
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {}
grpc { // Options added to --grpc_out
option 'lite' }
}
}
}
}
// }
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// Tar's:
implementation "org.java-websocket:Java-WebSocket:1.5.1" // Webscokets
//implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0" // Tar: for JSON: https://github.com/Kotlin/kotlinx.serialization
// Tar's - gRPC: {
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
implementation 'io.grpc:grpc-okhttp:1.25.0' // CURRENT_GRPC_VERSION
implementation 'io.grpc:grpc-protobuf-lite:1.25.0' // CURRENT_GRPC_VERSION
implementation 'io.grpc:grpc-stub:1.25.0' // CURRENT_GRPC_VERSION
implementation 'javax.annotation:javax.annotation-api:1.3.2'
// }
}
What could be the problem?
Looks like the path of proto file is not correcttly. Try to move proto files to src/main/resouces/proto or set path in protobuf plugin configuration.
This is works well with kotlin DSL.
import com.google.protobuf.gradle.*
plugins {
java
idea
application
id("com.google.protobuf") version "0.8.14"
id("io.freefair.lombok") version "5.3.0"
}
repositories {
mavenCentral()
jcenter()
}
val grpcVersion = "1.34.1"
val protocVersion = "3.12.0"
val slf4jVersion = "1.7.25"
dependencies {
implementation("io.grpc:grpc-netty:${grpcVersion}")
implementation("io.grpc:grpc-protobuf:${grpcVersion}")
implementation("io.grpc:grpc-stub:${grpcVersion}")
implementation("org.slf4j:slf4j-api:${slf4jVersion}")
implementation("org.slf4j:slf4j-simple:${slf4jVersion}")
testImplementation("junit:junit:4.13")
}
// Look here for set path
sourceSets {
main {
proto {
srcDir("src/main/resources/proto")
}
}
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
plugins {
id("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
ofSourceSet("main").forEach {
it.plugins {
id("grpc")
}
}
}
}
Related
I have Two lines of error when i run the simple Jetpack Compose Material 3 Project
build.gradle(Project:)
buildscript {
ext {
compose_version = '1.3.0-beta02'
core_ktx_version = '1.9.0-rc01'
material3_version = 'material3:1.3.0-beta02'
lifecycle_version = '2.4.1'
activity_compose_version = '1.5.1'
nav_version = "2.5.2"
hilt_version = "2.42"
hilt_nav_fragment = "1.0.0"
lottieVersion = "5.2.0"
timber_version = "5.0.1"
hilt_navigation_compose = "1.0.0"
room_version = "2.3.0-beta02"
kotlin_version = "1.6.21"
}
dependencies {
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
classpath "com.android.tools.build:gradle:4.2.1"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (Module : )
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
android {
compileSdk 33
defaultConfig {
applicationId "com.jetpackcompose.jp1"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation "androidx.core:core-ktx:$core_ktx_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material3:$material3_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.activity:activity-compose:$activity_compose_version"
implementation "androidx.compose.compiler:compiler:1.3.1"
implementation 'androidx.appcompat:appcompat:1.6.0-beta01'
// hilt -android
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
// To Integrate Navigation
implementation "androidx.navigation:navigation-compose:$nav_version"
// To use additional extensions of navigation frameworks like hiltViewModel()
implementation "androidx.hilt:hilt-navigation-fragment:$hilt_nav_fragment"
implementation "androidx.hilt:hilt-navigation-compose:$hilt_navigation_compose"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
settings.gradle:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
}
rootProject.name = "jp1"
include ':app'
when i run the project i have an error of :
Execution failed for task ':app:desugarDebugFileDependencies'.
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find androidx.compose.material3:material3:1.3.0-beta02.
Compose compiler and the other compose dependencies have different releases.
The version androidx.compose.compiler:compiler:1.3.0-beta02 doesn't exist.
You can check it in the google maven repo
You can in any case use the stable version of the module compiler 1.3.1 and all the other compose dependencies at 1.2.1 or 1.3.0-beta02:
buildscript {
ext {
compose_compiler = '1.3.1' //compiler
compose_version = '1.3.0-beta02' //compose dependencies
compose_material3 = '1.0.0-beta02' //material3 release
}
//...
}
and then:
composeOptions {
kotlinCompilerExtensionVersion compose_compiler
}
dependencies {
// beta 1.3.0 releases
implementation "androidx.compose.material:material:$compose_version"
//...
//material3
implementation "androidx.compose.material3:material3:$compose_material3"
}
As described in the documentation the compiler 1.3.x requires kotlin 1.7.10:
I am trying to implement MapBox SDK to my Android Application. I followed the official documentation but I am getting this error.
Unable to resolve dependency for
':app#debugUnitTest/compileClasspath': Could not resolve
com.mapbox.maps:android:10.6.1.
I have tried following the legacy documentation, but still no luck. I would like to ask if there are any other ways to implement the SDK or did I miss something. TYIA.
Here are my gradle scripts:
build.gradle (Project Level)
buildscript {
ext.kotlin_version = "1.5.31"
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins
{
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false
}
allprojects {
final def var = repositories
{
google()
mavenCentral()
maven { url 'https://esri.jfrog.io/artifactory/arcgis' }
maven { url 'https://olympus.esri.com/artifactory/arcgisruntime-repo/' }
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = "mapbox"
// Use the secret token you stored in gradle.properties as the password
password = MAPBOX_DOWNLOADS_TOKEN
}
}
}
var
}
subprojects {
afterEvaluate { project ->
if (project.hasProperty("dependencies"))
{
dependencies {
implementation "androidx.appcompat:appcompat:1.4.1"
implementation "com.google.android.material:material:1.5.0"
implementation "com.esri.arcgisruntime:arcgis-android:$arcgisVersion"
implementation "androidx.multidex:multidex:2.0.1"
}
}
project.android {
defaultConfig {
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
}
}
}
task clean(type: Delete)
{
delete rootProject.buildDir
}
build.gradle (Module level)
plugins
{
id 'com.android.application'
id 'com.google.gms.google-services'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
id 'kotlin-android'
}
ext {
arcgisVersion = '100.13.0'
}
android
{
compileSdk 32
defaultConfig
{
applicationId "com.example.project1"
minSdk 26
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes
{
release
{
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions
{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures
{
viewBinding true
}
}
dependencies
{
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.navigation:navigation-fragment:2.4.1'
implementation 'androidx.navigation:navigation-ui:2.4.1'
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.google.firebase:firebase-messaging:21.1.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.gms:google-services:3.0.0'
implementation "androidx.appcompat:appcompat"
implementation "com.google.android.material:material"
implementation "com.esri.arcgisruntime:arcgis-android"
implementation "androidx.multidex:multidex"
implementation 'com.google.android.libraries.places:places:2.6.0'
implementation 'com.mapbox.maps:android:10.6.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
rootProject.name = "proect1"
include ':app'
just started working in Android Studio and trying to add the navigation safeargs, when this error occurred: com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
No idea what I did. Here are my build.gradle files:
plugins {
id 'com.android.application'
id 'androidx.navigation.safeargs'
}
[...]
android {
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.4.2"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" }
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.navigation:navigation-fragment:2.4.2'
implementation 'androidx.navigation:navigation-ui:2.4.2'
implementation 'androidx.navigation.safeargs:androidx.navigation.safeargs.gradle.plugin:2.4.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
and
// Top-level build file where you can add configuration options common to all sub-projects/modules.
// no idea but this block seems to be also in this file?
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.4.2"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" }
}
plugins {
id 'com.android.application' version '7.1.3' apply false
id 'com.android.library' version '7.1.3' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The plugin androidx.navigation.safeargs just worked, after adding the
repositories {
google()
}
dependencies {
def nav_version = "2.4.2"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" }
}
additionally to the top-level build.gradle-file. Originally this code was generated in the module part. Could this be somehow part of the error?
So far I tried Tutorials like:https://developer.android.com/guide/navigation/navigation-pass-data#java
and
https://developer.android.com/jetpack/androidx/releases/navigation#groovy
Im trying to pass enums using AIDL and it's wrapping a Parcelable but it's still failing to compile with the following error:
> Task :app:compileDebugAidl FAILED
ERROR: uk.ac.liverpool.altphone.service.Mode: couldn't find import for class uk.ac.liverpool.altphone.service.Mode
My files are as follows:
Project Level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.20"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
def nav_version = "2.3.3"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module Level build.gradle:
plugins {
id 'com.android.application'
id "androidx.navigation.safeargs"
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-parcelize'
id "com.google.protobuf" version "0.8.12"
}
preBuild {
doFirst {
new ProcessBuilder("java", "$rootDir/scripts/Zipper.java")
.directory(new File("$rootDir"))
.start()
.waitFor()
}
}
android {
compileSdkVersion 29
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "uk.ac.liverpool.altphone"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding true
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
tasks.withType(JavaCompile) {
configure(options) {
options.debug = true
options.warnings = true
options.compilerArgs << '-Xlint:all' << '-parameters' << '-g:source,lines,vars'
}
}
}
dependencies {
implementation 'androidx.activity:activity-ktx:1.2.0-beta02'
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0-alpha1'
implementation 'androidx.core:core-ktx:1.5.0-alpha05'
implementation 'androidx.datastore:datastore:1.0.0-alpha06'
implementation 'androidx.datastore:datastore-core:1.0.0-alpha06'
implementation 'androidx.fragment:fragment-ktx:1.3.0-beta02'
def nav_version = "2.3.3"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation 'androidx.recyclerview:recyclerview:1.2.0-beta01'
def room_version = "2.3.0-alpha03"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation 'androidx.startup:startup-runtime:1.0.0'
implementation 'com.google.android.material:material:1.3.0-alpha04'
implementation "com.google.protobuf:protobuf-javalite:3.10.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1'
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.10.0"
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option 'lite'
}
}
}
}
}
AIDL File app/src/main/aidl/uk/ac/liverpool/altphone/service/IAltPhoneServiceInterface.aidl:
// IAltPhoneServiceInterface.aidl
package uk.ac.liverpool.altphone.service;
// Declare any non-default types here with import statements
import uk.ac.liverpool.altphone.service.Mode;
interface IAltPhoneServiceInterface {
oneway void setMode(in Mode mode);
oneway void updateSettings(in Mode mode, in int headphone);
oneway void stop();
}
Kotlin File app/src/main/java/uk/ac/liverpool/altphone/service/AltPhoneService.kt:
package uk.ac.liverpool.altphone.service
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import uk.ac.liverpool.altphone.R
class AltPhoneService : Service() {
override fun onBind(intent: Intent): IBinder {
return null!!
}
}
#Parcelize
public enum class Mode : Parcelable {
SINGLE, ALTERNATE;
companion object {
fun getModeByID(id: Int): Mode? = when (id) {
R.id.single_mode_mi -> SINGLE
R.id.alternate_mode_mi -> ALTERNATE
else -> null
}
}
}
I created a gRPC server (hosted by AWS) in nodejs and I can connect to it with a nodejs client implementation from my local machine.
I'm using the com.google.protobuf plugin to auto generate code from my .proto file.
My gradle sync works and the app builds successfully but I can't find the generated code classes.
I'm struggling to find a good implementation example for a Kotlin for Android gRPC client but I followed these articles:
gRPC In Kotlin(Android)
Java Basic Tutorial
My app/src/main/protos/responder.proto file
syntax = "proto3";
option java_package = "protos.grpc";
package responder;
message ConnectionRequest {
int32 userId = 2;
}
message ConnectionResponse {
string response = 1;
}
service ResponderService {
rpc responderConnect (stream ConnectionRequest) returns (stream ConnectionResponse) {};
}
Project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
kotlin_version = '1.3.72'
protobufPluginVersion = '0.8.6'
grpcVersion = '1.12.0'
protocVersion = '3.2.0'
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.protobuf:protobuf-gradle-plugin:$protobufPluginVersion"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
def nav_version = "2.2.2"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And my app's build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "organisation.responder.two"
minSdkVersion 19
targetSdkVersion 29
versionCode 31
versionName "2.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
...
implementation 'io.grpc:grpc-okhttp:1.30.0'
implementation 'io.grpc:grpc-protobuf-lite:1.30.0'
implementation 'io.grpc:grpc-stub:1.30.0'
implementation 'io.grpc:grpc-core:1.30.0'
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
def multidex_version = "2.0.1"
implementation "androidx.multidex:multidex:$multidex_version"
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.12.0"
}
plugins {
javalite {
artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
}
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:1.30.0"
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove java
}
task.plugins {
javalite {}
grpc {
// Options added to --grpc_out
option 'lite'
}
}
}
}
}
As I said above, the gradle sync is successful and the project builds successfully. But where is the autogenerated code?
After following this build.gradle file as an example, I managed to generate the grpc code using the gradle protobuf plugin.
Major changes to my app level build.gradle file included:
Adding path to .proto file in sourceSets block under android block.
android {
...
sourceSets {
main {
proto {
srcDir 'src/main/protos' <-- path to .proto file
}
}
}
}
Change the protobuf block in app level build.gradle file
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.12.0"
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:1.30.0"
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove javanano
java {
option 'lite'
}
}
task.plugins {
grpc {
// Options added to --grpc_out
option 'lite'
}
}
}
}
}
After a successful sync and build, the generated code files where located under app/build/generated/source/proto/debug/grpc/protos/grpc/ResponderServiceGrpc.java and app/build/generated/source/proto/debug/java/protos/grpc/Responder.java