-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
disconnected stale, reconnect false error on android #20
Comments
Hello, could you please provide a bit more information:
|
hi |
OOOps!!! |
i trace library code in Client.java at line 617 progress of code stoped and next block not run
|
Hmm, that's strange. Thanks for finding this. Since I never used Kotlin personally will appreciate any help in investigating why this happens. |
Just tried to create basic Kotlin project and it works for me. I started with Basic Activity template, selected Kotlin language. Code inside package com.example.myfirstapp
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
import io.github.centrifugal.centrifuge.*
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
val listener: EventListener = object : EventListener() {
@SuppressLint("SetTextI18n")
override fun onConnect(client: Client?, event: ConnectEvent) {
println("connect")
}
@SuppressLint("SetTextI18n")
override fun onDisconnect(client: Client?, event: DisconnectEvent) {
println("disconnect")
}
}
val client = Client(
"ws://192.168.1.34:8000/connection/websocket?format=protobuf",
Options(),
listener
)
client.setToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0c3VpdGVfand0In0.hPmHsVqvtY88PvK4EmJlcdwNuKFuy3BGaF7dMaKdPlw")
client.connect()
fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
return when (item.itemId) {
R.id.action_settings -> true
else -> super.onOptionsItemSelected(item)
}
}
} Set internet permission inside
After running application I see successful connect in Centrifugo logs:
|
yes, it worked in empty android project I have GRPC backend service and in prohect gradle already implemented
now that add centrifuge-java dependency to gradle, protobuf-java must be excluded on it
if i exclude protobuf-java centrifuge not work 😩 and if don't exclude it duplicated package error occurred |
Maybe GRPC depends on protobuf-javalite package? Could you try an opposite and exclude javalite package from GRPC instead? I found similar problem in Centrifugo Telegram chat history: Solution as text:
So the same problem happened with Firebase. I suppose this should work for GRPC too. By the way there is a pr that migrates centrifuge-java to |
hi i try this solution before, but it does not worked finally i use centrifuge-mobile library , its worked perfect |
Looks like I need to test it out myself at some point in the future then. I believe that finding a root cause of this issue is not too hard having a reproducing example (especially since similar stale case already solved by excluding javalite). Personally, I'd go with a native approach instead of centrifuge-mobile especially since you already using centrifuge-swift. If you can provide a minimal reproducing example this could help a lot |
Greetings I encountered the same issue as puryagh & solved it. It has nothing to do with protobuf. I also suggest updating this file https://github.com/centrifugal/centrifuge-java/blob/master/README.md |
This is happening because he was getting exceptions like this due to the missing libraries I mentioned in my previous comment. It might be a good idea to introduce some try-catch wrapping & logging in the Runnable's you are passing to your executor, like here - https://github.com/centrifugal/centrifuge-java/blob/master/centrifuge/src/main/java/io/github/centrifugal/centrifuge/Client.java#L185 Library erroring out & swallowing & disappearing all of the crashes is super aggravating 🤬... Yes I had an enjoyable time getting to these solutions /s |
@sqrt1764 hello, thanks, do you have time maybe to send pr with fixes you suggest? Since I am not a Java dev at all I could write absolutely non-idiomatic code here. |
Made this more clear in 6871e7b |
I've made a new release 0.0.6 where library migrated to protobuf-javalite and exception in Connect now printed - this may help to detect a dependency issue much faster. Though I still not really understand the root cause here. |
Guys, can someone who experienced this issue try version 0.0.7? |
I have faced with this issue on Android with 0.0.8 lib version.
|
@agent10 thanks, could you elaborate more where this rule should be placed and why this happens? |
I'm getting event: Basically it happens because shrinker removes unused classes from the code. But as I know protobuf generated classes are used with reflection and that's why shrinker will remove them as well without explicit rule to keep them in the code. |
Original issue: protocolbuffers/protobuf#6463 So it looks like Protobuf Javalite uses reflection in releases after @agent10 have you already had a chance to try a rule you posted above - does it fix a problem? |
Right, it fixes the problem for me. |
Unfortunate thing, just documented this in README - I suppose there is nothing else we can do here. |
In my App ,this problem happened too,can you help me ,thank you . when i use your demo ,the error message is connection error |
This is what your project's module's dependencies should look like when using this library.
Centrifuge library could solve this in an alternate way by modifying the dependencies of their own. |
Thank you for answer my question. I use dependencies same with you,but build error like this :
and then ,i change dependencies like this: api("io.github.centrifugal:centrifuge-java:0.1.0") { // but ,still build with same error last,i only dependencies |
Sorry ,I find the question .It's my error , I have not add "?format=protobuf" to my connect url . |
Had the same issue with Stale connection on Android. I was already using protobuf Gradle plugin in my app. There is definitely some problem with how different versions and flavours of protobuf are working with each other. Particularly in my case, there was NoSuchMethodError somewhere in the I updated my protobuf to latest version and also switched from Here is the new configuration that works: protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.20.1"
}
generateProtoTasks {
all().configureEach {
builtins {
register("java") {
option("lite")
}
}
}
}
}
dependencies {
implementation("com.google.protobuf:protobuf-javalite:3.20.1")
} Here is what I had before the change: protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.12.3"
}
plugins {
id("javalite") {
artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
}
}
generateProtoTasks {
all().forEach { task ->
task.plugins {
id("javalite")
}
}
}
}
dependencies {
implementation("com.google.protobuf:protobuf-lite:3.0.1")
} I don't think anything should be changed in centrifuge-java. Just the projects that use protobuf might have some trouble integrating and will have to update their protobuf setup. |
hi dear
i use your java library on android with kotlin implemention
but when i try to connect with JWT token, returns disconnected stale, reconnect false error
but on iOS(swift) and Web version every thing is ok
this is my code
`
val cfListener = object : EventListener() {
override fun onConnect(client: Client?, event: ConnectEvent?) {
Log.d("CENTRIFUGE", "connected")
}
The text was updated successfully, but these errors were encountered: