Communication through gRPC/Protobuf - android

I am coming because I can't make work my communication between my API (Go) and my client (Android).
I have this protobuf file:
syntax = "proto3";
option java_package = "com.emixam23.rushpoc.protobuf";
option java_outer_classname = "HelloWorld";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
The protobuf file comes from the example of https://grpc.io/docs/quickstart/go.html, I just didn't implemented the SayHelloAgain. What i am trying to achieve is, from my android app, SayHello to my Go API and get a reply...
For android, I followed that tutorial (https://grpc.io/docs/quickstart/android.html) in order to, from the protobuf file, to communicate with my API. However, there is a stub, comming from I don't know where.
So I searched about how to create a stub (https://grpc.io/docs/tutorials/basic/android.html) and nothing.. ManagedChannelBuilder doesn't exist and I can't find the way to install it..
PS: to generate my Java class from the protobuf file, I followed that tutorial: https://proandroiddev.com/how-to-setup-your-android-app-to-use-protobuf-96132340de5c
Am I in the right direction or totally wrong?
My project structure:
APP build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.rushpoc.emixam23.androidapp"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//Protobuf
implementation 'com.google.protobuf:protobuf-lite:3.0.0'
implementation 'io.grpc:grpc-okhttp:1.13.2'
implementation 'io.grpc:grpc-protobuf-lite:1.13.2'
implementation 'io.grpc:grpc-stub:1.13.2'
}
protobuf {
generatedFilesBaseDir = "$projectDir/generated"
protoc {
// You still need protoc like in the non-Android case
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
// The codegen for lite comes as a separate artifact
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.13.2'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
java
}
task.plugins {
grpc {}
}
}
}
}
TOP-LEVEL/Root build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.protobufVersion = '0.8.6'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "com.google.protobuf:protobuf-gradle-plugin:$protobufVersion"
// 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
}

I haven't checked the entire gradle files yet but I see in your screenshot the .proto file was in src/main/protobufs, which was not following either of the tutorials you mentioned. The protobuf gradle plugin does not detect this directory by default. Therefore I suggest you change it into the default directory src/main/proto. If you would like to insist putting the .proto file in src/main/protobufs, you might need let the protobuf gradle plugin know it by adding
// see https://github.com/google/protobuf-gradle-plugin#customizing-source-directories
sourceSets {
main {
proto {
// In addition to the default 'src/main/proto'
srcDir 'src/main/protobufs'
}
}
}
After that, the protobuf gradle plugin will generate the java code if there's no other mistake.

Related

Error in supressing #InstallIn check whilst migrating from Dagger to Hilt using flag -Adagger.hilt.disableModulesHaveInstallInCheck=true

I have been recently trying to migrate my Android App from Dagger to Hilt.
I would like to carry out the entire migration in phases and hence was trying to suppress the Hilt warning for not using #InstallIn for modules.
Have been following the migration guide given here: https://dagger.dev/hilt/migration-guide.html
Also found the flag which disables the #InstallIn check here: https://dagger.dev/hilt/compiler-options.html#disable-install-in-check
However, I have been struggling to get this flag to work.
To understand the issue better, I tried to migrate the Dagger Codelab (https://codelabs.developers.google.com/codelabs/android-dagger/#0) to Hilt.
Didn't find success even there.
Could someone please point out the error? I have attached the build.gradle files and the errors generated below.
Project Level build.gradle file
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.28-alpha"
// 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
}
App Level build.grade file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.android.dagger"
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.example.android.dagger.MyCustomTestRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
String sharedTestDir = 'src/sharedTest/java'
test {
java.srcDir sharedTestDir
}
androidTest {
java.srcDir sharedTestDir
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
tasks.withType(JavaCompile) {
configure(options) {
options.compilerArgs << "-Adagger.hilt.disableModulesHaveInstallInCheck=true"
}
}
}
dependencies {
def dagger_version = "2.27"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.core:core-ktx:1.2.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-livedata:2.2.0'
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:3.3.1'
testImplementation 'android.arch.core:core-testing:1.1.1'
def androidx_test_version = "1.2.0"
androidTestImplementation "androidx.test:runner:$androidx_test_version"
androidTestImplementation "androidx.test:core-ktx:$androidx_test_version"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
kaptAndroidTest "com.google.dagger:dagger-compiler:$dagger_version"
implementation "com.google.dagger:hilt-android:2.28-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
}
Generated warning and errors:
e: D:\androidLearn\dagger\android-dagger\app\build\tmp\kapt3\stubs\debug\com\example\android\dagger\di\AppSubcomponents.java:7: error: [Hilt]
public final class AppSubcomponents {
^
com.example.android.dagger.di.AppSubcomponents must also be annotated with #InstallIn.
[Hilt] Processing did not complete. See error above for details.
e: D:\androidLearn\dagger\android-dagger\app\build\tmp\kapt3\stubs\debug\com\example\android\dagger\di\StorageModule.java:7: error: [Hilt]
public abstract class StorageModule {
^
com.example.android.dagger.di.StorageModule must also be annotated with #InstallIn.
[Hilt] Processing did not complete. See error above for details.
w: warning: The following options were not recognized by any processor: '[dagger.hilt.android.internal.disableAndroidSuperclassValidation, kapt.kotlin.generated]'
You can add the compiler option to your app/build.gradle file in the android -> defaultConfig block like this:
android {
...
defaultConfig {
...
//TODO: remove this after migration to Hilt
javaCompileOptions.annotationProcessorOptions.arguments['dagger.hilt.disableModulesHaveInstallInCheck'] = 'true'
}
}
You can also add the same thing like below:
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments["dagger.hilt.disableModulesHaveInstallInCheck"]="true"
}
}
}

How to generate gRPC code with protobuf on Kotlin for Android client?

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

gRPC client: error in compiled file (io.grpc.protobuf does not exist)

I made a simple protobuf+gRPC server/client example with Python, and wanted now to complete it with an Android Java client. However, I struggled through the documentation and got it mostly working (.proto compiles in Android Studio), BUT now I get Errors in the output *Grpc.java file (i.e. if I fix it it will just be overwritten by the compiler):
error: package io.grpc.protobuf does not exist
error: package com.google.protobuf.Descriptors does not exist
Since I get errors from io.gprc's and com.google's protobuf, I suspect a definition conflict in my gradle, but I cannot find/resolve it (went through several "tutorials" and it seemed common to use a mix of grpc and google sources).
Here is my build.gradle:
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "***.grpcclient"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'io.grpc:grpc-okhttp:1.25.0'
//implementation 'io.grpc:grpc-protobuf-lite:1.25.0'
implementation 'com.google.protobuf:protobuf-javalite:3.8.0'
implementation 'io.grpc:grpc-stub:1.25.0'
implementation 'org.glassfish:javax.annotation:10.0-b28'
}
apply plugin: 'com.google.protobuf'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.8.0'
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.25.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option "lite"
}
python { }
}
task.plugins {
grpc {outputSubDir = 'java'}
}
}
}
}
Any help is appreciated!
Android uses Protobuf Lite, which is a subset of the normal implementation and optimized for Android. You correctly tried to depend on io.grpc:grpc-protobuf-lite:1.25.0. This provides the io.grpc.protobuf.lite package.
You also correctly configured protoc to generate protobuf-lite messages. However, the grpc plugin is generating "full" protobuf services. That's why you're seeing references to io.grpc.protobuf and classes missing in protobuf like com.google.protobuf.Descriptors.
protobuf {
...
generateProtoTasks {
all().each { task ->
...
task.plugins {
grpc {
outputSubDir = 'java'
option 'lite' // Needed this line
}
}
}
}
}
Since you are using protoc with the 'lite' option, instead of using the older protoc-gen-javalite plugin, you are using the correct protobuf-javalite dependency for protobuf. However, grpc-java 1.25.0 depends on protobuf-lite which will collide. This is discussed some in Issue 6405 and will be fixed in grpc-java 1.26.0. But for the moment you'll need to exclude the protobuf-lite dependency brought in by grpc-protobuf-lite.
dependencies {
...
implementation ('io.grpc:grpc-protobuf-lite:1.25.0') {
// Exclude will not be necessary starting in grpc 1.26
exclude group: 'com.google.protobuf', module: 'protobuf-lite'
}
}
My working build.gradle:
dependencies {
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'io.grpc:grpc-core:1.27.1'
implementation 'io.grpc:grpc-stub:1.27.1'
implementation 'io.grpc:grpc-okhttp:1.27.1'
implementation('io.grpc:grpc-protobuf-lite:1.27.1') {
exclude module: "protobuf-lite"
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.11.4'
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.27.1'
}
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option 'lite'
}
}
task.plugins {
grpc {
// Options added to --grpc_out
option 'lite'
}
}
}
}
}

Could not resolve com.squareup.sqldelight:runtime:1.1.3

I tried to integrate sqldelight in my Multiplatform library project for Android/iOS but I'm having several unresolved dependency errors when syncing gradle.
ERROR: Unable to resolve dependency for ':SharedCode#debug/compileClasspath': Could not resolve com.squareup.sqldelight:runtime:1.1.3.
ERROR: Unable to resolve dependency for ':SharedCode#debug/compileClasspath': Could not resolve com.squareup.sqldelight:runtime-jvm:1.1.3.
ERROR: Unable to resolve dependency for ':SharedCode#release/compileClasspath': Could not resolve com.squareup.sqldelight:runtime:1.1.3.
ERROR: Unable to resolve dependency for ':SharedCode#release/compileClasspath': Could not resolve com.squareup.sqldelight:runtime-jvm:1.1.3.**
Gradle version 5.1.1
Gradle Plugin 3.4.0
sqldelight 1.1.3
enableFeaturePreview('GRADLE_METADATA') is present in my settings.gradle
My project gradle file looks like this:
buildscript {
ext {
kotlin_version = '1.3.31'
ktor_version = '1.2.1'
ktor_json_version = '1.2.1'
kotlinx_coroutines_version = '1.2.1'
serialization_version = '0.11.0'
sqldelight_version = '1.1.3'
dokka_version = '0.9.16'
}
repositories {
google()
jcenter()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version"
classpath "com.squareup.sqldelight:gradle-plugin:$sqldelight_version"
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
}
task clean(type: Delete) {
setDelete rootProject.buildDir
}
my SharedCode lib gradle file:
apply plugin: 'kotlinx-serialization'
apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: 'com.squareup.sqldelight'
group = 'com.example.multiplatform'
version = '1.0'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 15
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
// Specify Kotlin/JVM stdlib dependency.
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7'
implementation "com.squareup.sqldelight:runtime:1.1.3"
testImplementation 'junit:junit:4.12'
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'org.jetbrains.kotlin:kotlin-test'
androidTestImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
kotlin {
targets {
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
fromPreset(iOSTarget, 'ios') {
binaries {
framework('SharedCode')
}
}
fromPreset(presets.android, 'androidLib')
}
sourceSets {
commonMain {
dependencies {
//HTTP
implementation "io.ktor:ktor-client-json:$ktor_json_version"
implementation "io.ktor:ktor-client-serialization:$ktor_version"
//Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlinx_coroutines_version"
//Kotlinx serialization
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
//sqldelight
implementation "com.squareup.sqldelight:runtime:$sqldelight_version"
}
}
androidLibMain {
dependencies {
//HTTP
implementation "io.ktor:ktor-client-json-jvm:$ktor_json_version"
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
//Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinx_coroutines_version"
//Kotlinx serialization
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
//sqldelight
implementation "com.squareup.sqldelight:android-driver:$sqldelight_version"
}
}
iosMain {
dependencies {
//HTTP
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-json-native:$ktor_json_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
//Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$kotlinx_coroutines_version"
//kotlinx serialization
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
//sqldelight
implementation "com.squareup.sqldelight:ios-driver:$sqldelight_version"
}
}
}
}
sqldelight {
MyApp {
packageName = 'com.example.multiplatform'
}
}
configurations {
compileClasspath
}
task packForXCode(type: Sync) {
final File frameworkDir = new File(buildDir, "xcode-frameworks")
final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'
final def framework = kotlin.targets.ios.binaries.getFramework("SharedCode", mode)
inputs.property "mode", mode
dependsOn framework.linkTask
from { framework.outputFile.parentFile }
into frameworkDir
doLast {
new File(frameworkDir, 'gradlew').with {
text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$#\n"
setExecutable(true)
}
}
}
tasks.build.dependsOn packForXCode
I was solved this problem.
First: Apply sqldelight plugin right to all project:
apply plugin: 'com.squareup.sqldelight'
sqldelight {
MyDatabase {
packageName = "ru.trendagent.database"
sourceFolders = ["sqldelight"]
}
}
In android section add:
packagingOptions {
...
exclude 'META-INF/*.kotlin_module'
}
remove all implementations of sqldelight from CommonMain section
add implementation to AndroidMain section:
implementation "com.squareup.sqldelight:android-driver:1.1.3" //DataBase
add implementation to iosMain section if need:
implementation "com.squareup.sqldelight:ios-driver:1.1.3"//DataBase
add Metadata settings to gradle to settings.gradle file:
enableFeaturePreview("GRADLE_METADATA") // IMPORTANT!
Fully clean gradle files, reset gradle wrapper and other.
Don't use kotlin 1.4.0. It unsupport sqldelight 1.1.3 version
Change gradle to latest version. You can download latest gradle manually and set it on IDE. You need gradle 5.3.1 or latest (5.1.1 unsupported)
If error will remain - change IDE to intellij idea comunity edition
This is seems to me as an error occurred due to offline gradle or invalid cache as this error is not specific to com.squareup.sqldelight. To resolve this issue follow the following steps:
File
Settings
Build, Execution, Deployment
Gradle
Uncheck offline work
and then try to invalidate the cache and restart from file menu. Hope it helps!
Change this
classpath "com.squareup.sqldelight:gradle-plugin:$sqldelight_version"
Following
classpath "com.squareup.sqldelight:runtime:$sqldelight_version"
you are passing wrong metadata to sqldelight change with my solution it will work
The Gradle part of the readme of the library indicates, that gradle plugin is needed. There's no such sqldelight library as runtime. They only have android-driver, ios-driver and sqlite-driver.
Using the DroidConKotlin app project as an example, I upgraded gradle from 5.1.1 to 5.3.1 and it resolved all the dependencies issues.
You likely are trying to use a dependency on dependant libraries or even applications and not only in commonMain module. Just change:
commonMain {
dependencies {
...
implementation "com.squareup.sqldelight:runtime:$sqldelight_version"
}
}
to
commonMain {
dependencies {
...
api "com.squareup.sqldelight:runtime:$sqldelight_version"
}
}
Also change it on dependencies section
And do the same with any other dependency uncorrecly resolved
This can happen for example if you define a class that implements an interface provided by the dependency and you use or extend that class on dependant libraries or applications (Just an example of millions that could be).
If this is your case, for further understanding, just take a look to this answer:

Google Speech-to-Text API for Android auto detect language with RPC beta

I'm trying to implement app for Android that will use Google Cloud Speech To Text API with language auto detection. In official documentation I've found sample project for android. But the problem is that it uses google.cloud.speech.v1.Speech, while multiple languages supported only in beta version - google.cloud.speech.v1p1beta1.Speech.
To specify alternative language it is needed to set field alternativeLanguageCodes that is declared only in beta version and I can't find out how to change project to use beta.
I tried to update gradle dependencies, and import new packages, but it does not work.
gradle sript for project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
google()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle script for app:
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
ext {
supportLibraryVersion = '28.0.0'
grpcVersion = '1.20.0'
}
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId ""
targetSdkVersion 28
versionCode 1
versionName '1.0'
minSdkVersion 16
}
signingConfigs {
release {
storeFile file(project.properties.storeFile)
storePassword project.properties.storePassword
keyAlias project.properties.keyAlias
keyPassword project.properties.keyPassword
}
}
flavorDimensions "default"
productFlavors {
dev {
dimension "default"
// Minimum version with platform multi-dex support
minSdkVersion 16
}
prod {
dimension "default"
// Minimum version that can run gRPC (TLS extension)
minSdkVersion 16
}
}
buildTypes {
debug {
minifyEnabled false
multiDexEnabled true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
resolutionStrategy.force "com.android.support:support-annotations:$supportLibraryVersion"
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.3.0'
}
plugins {
javalite {
artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
}
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {}
grpc {
// Options added to --grpc_out
option 'lite'
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Support libraries
compile "com.android.support:design:$supportLibraryVersion"
compile "com.android.support:cardview-v7:$supportLibraryVersion"
compile "com.android.support:recyclerview-v7:$supportLibraryVersion"
// gRPC
compile "io.grpc:grpc-okhttp:$grpcVersion"
compile "io.grpc:grpc-protobuf-lite:$grpcVersion"
compile "io.grpc:grpc-stub:$grpcVersion"
compile 'javax.annotation:javax.annotation-api:1.2'
protobuf 'com.google.protobuf:protobuf-java:3.5.1'
// OAuth2 for Google API
compile('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
exclude module: 'httpclient'
}
// Tests
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:1.0.2'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.2'
}
task copySecretKey(type: Copy) {
File secretKey = file "$System.env.GOOGLE_APPLICATION_CREDENTIALS"
from secretKey.getParent()
include secretKey.getName()
into 'src/main/res/raw'
rename secretKey.getName(), "credential.json"
}
preBuild.dependsOn(copySecretKey)
Trying to import beta package, but it is not resolved:
import com.google.cloud.speech.v1p1beta1.RecognitionAudio;
import com.google.cloud.speech.v1p1beta1.RecognitionConfig;
import com.google.cloud.speech.v1p1beta1.RecognizeRequest;
import com.google.cloud.speech.v1p1beta1.RecognizeResponse;
import com.google.cloud.speech.v1p1beta1.SpeechGrpc;
import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative;
import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult;
import com.google.cloud.speech.v1p1beta1.StreamingRecognitionConfig;
import com.google.cloud.speech.v1p1beta1.StreamingRecognitionResult;
import com.google.cloud.speech.v1p1beta1.StreamingRecognizeRequest;
import com.google.cloud.speech.v1p1beta1.StreamingRecognizeResponse;

Categories

Resources