【发布时间】:2021-03-14 14:41:34
【问题描述】:
我关注this guide将gRPC添加到我的Android项目中,但是proto文件似乎没有生成代码。
我将 book.proto 和我的 Kotlin 代码放在 app\src\main\java\com\example\android 下。
那是我项目的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
}
这是我的模块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'
// }
}
可能是什么问题?
【问题讨论】: