android - Unexpected TLS exception with Google PubSub client in kotlinjava - Stack Overflow

I am writing an app on android that utilizes Google pubsub and have a corresponding client already writ

I am writing an app on android that utilizes Google pubsub and have a corresponding client already written in go.

Please five me in advance as this is my first android app and first time using kotlin. I've programmed in Java and go, so if something looks glaringly wrong, apologies in advance.

I've gone through documentation, but am stuck.

The problem I am running into stems from initializing a pubsub client. I believe my credentials json is picked up along with my project, topic, etc. The issue I am running into is that I don't believe I should be adding more dependencies to the project since the google pubsub example does not include those dependencies. I don't know how far that rabbit hole goes, but I would think that the Google example should work out of the box:

I am referencing:

I am not using the gcloud command, but have created a credentials.json and it works in my golang app just fine.

Relative bits: build.gradle.kts

android {
    packagingOptions {
        resources.excludes.add("META-INF/*")
    }
}

dependencies {
    implementation(libs.googlePubSub)
    implementation(libs.grpc)
    implementation(libs.tls)
}

app/src/main/res/raw/credentials.json

gradle/libs.versions.toml

[versions]
googlePubSub = "1.134.2"
grpc = "1.68.1"
tls = "2.0.69.Final"`

[libraries]
googlePubSub = { group = "com.google.cloud", name = "google-cloud-pubsub",    version.ref="googlePubSub"}
grpc = { group = "io.grpc", name = "grpc-netty", version.ref="grpc"}
tls = { group = "ioty", name = "netty-tcnative-boringssl-static",   version.ref="tls"}

Problem occurs here:

fun getPublisher(): Publisher {

    return Publisher.newBuilder(getTopic()).setCredentialsProvider { credentials}.build()
}

fun getTopic(): TopicName {
    val topic = TopicName.of(configuration.project, configuration.requestTopic)

    val topicAdminSettings = TopicAdminSettings.newBuilder().setCredentialsProvider{ credentials }.build()

    TopicAdminClient.create(topicAdminSettings).use { topicAdminClient -> topicAdminClient.createTopic(topic)}

    return topic
}

I first added the grpc library and then added boringssl library, but that didn't seem right. The most recent error I get (even after adding that boringssl library) is:

Could not find TLS ALPN provider; no working netty-tcnative, Conscrypt, or Jetty NPN/ALPN available

I must point out that the configuration and credentials objects are properly populated at this point.

I tried following the online documentation for Google pubsub Java client and was expecting a message to be published. I also referred to an example project, but those libraries appear out of date:

EDIT #1:

I updated the dependencies:

grpc-netty -> grpc-okhttp

and modified the packaging:

resources.excludes.add("META-INF/*") -> resources.excludes.add("META-INF/INDEX.LIST") and resources.excludes.add("META-INF/DEPENDENCIES")

The error I am facing now is as if the application is not connected to the Internet. It complains that pubsub.googleapis cannot be resolved yet on that same machine, a ping resolves to an IP address.

EDIT #2: Upon further debugging, I see I need the Internet permission.

EDIT #3: Pub Sub connectivity is working.

I am writing an app on android that utilizes Google pubsub and have a corresponding client already written in go.

Please five me in advance as this is my first android app and first time using kotlin. I've programmed in Java and go, so if something looks glaringly wrong, apologies in advance.

I've gone through documentation, but am stuck.

The problem I am running into stems from initializing a pubsub client. I believe my credentials json is picked up along with my project, topic, etc. The issue I am running into is that I don't believe I should be adding more dependencies to the project since the google pubsub example does not include those dependencies. I don't know how far that rabbit hole goes, but I would think that the Google example should work out of the box:

I am referencing: https://cloud.google/pubsub/docs/publish-receive-messages-client-library#pubsub-client-libraries-java

I am not using the gcloud command, but have created a credentials.json and it works in my golang app just fine.

Relative bits: build.gradle.kts

android {
    packagingOptions {
        resources.excludes.add("META-INF/*")
    }
}

dependencies {
    implementation(libs.googlePubSub)
    implementation(libs.grpc)
    implementation(libs.tls)
}

app/src/main/res/raw/credentials.json

gradle/libs.versions.toml

[versions]
googlePubSub = "1.134.2"
grpc = "1.68.1"
tls = "2.0.69.Final"`

[libraries]
googlePubSub = { group = "com.google.cloud", name = "google-cloud-pubsub",    version.ref="googlePubSub"}
grpc = { group = "io.grpc", name = "grpc-netty", version.ref="grpc"}
tls = { group = "ioty", name = "netty-tcnative-boringssl-static",   version.ref="tls"}

Problem occurs here:

fun getPublisher(): Publisher {

    return Publisher.newBuilder(getTopic()).setCredentialsProvider { credentials}.build()
}

fun getTopic(): TopicName {
    val topic = TopicName.of(configuration.project, configuration.requestTopic)

    val topicAdminSettings = TopicAdminSettings.newBuilder().setCredentialsProvider{ credentials }.build()

    TopicAdminClient.create(topicAdminSettings).use { topicAdminClient -> topicAdminClient.createTopic(topic)}

    return topic
}

I first added the grpc library and then added boringssl library, but that didn't seem right. The most recent error I get (even after adding that boringssl library) is:

Could not find TLS ALPN provider; no working netty-tcnative, Conscrypt, or Jetty NPN/ALPN available

I must point out that the configuration and credentials objects are properly populated at this point.

I tried following the online documentation for Google pubsub Java client and was expecting a message to be published. I also referred to an example project, but those libraries appear out of date:

https://github/androidthings/weatherstation

EDIT #1:

I updated the dependencies:

grpc-netty -> grpc-okhttp

and modified the packaging:

resources.excludes.add("META-INF/*") -> resources.excludes.add("META-INF/INDEX.LIST") and resources.excludes.add("META-INF/DEPENDENCIES")

The error I am facing now is as if the application is not connected to the Internet. It complains that pubsub.googleapis cannot be resolved yet on that same machine, a ping resolves to an IP address.

EDIT #2: Upon further debugging, I see I need the Internet permission.

EDIT #3: Pub Sub connectivity is working.

Share Improve this question edited Nov 26, 2024 at 20:50 Walter White asked Nov 21, 2024 at 8:31 Walter WhiteWalter White 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The solution to my problem was indeed dependencies. I stumbled upon stale code and the dependencies weren't right.

The solution was:

  1. use grpc-okhttp, not grpc-netty
  2. instead of excluding everything under META-INF, just exclude INDEX.LIST and DEPENDENCIES

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742302046a4418205.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信