Using Firestore causes 'No static method checkArgument' - android

All related posts seem to indicate a version mismatch between Firebase and Playservices, but I didn't find one wrt. Firestore. I tried all kinds of permutations, but didn't find a fix. Here is my gradle:
dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
//----------------------------------------------------------------------------------------------
//--- FireBase
//----------------------------------------------------------------------------------------------
// Firebase DataBase
// implementation 'com.google.firebase:firebase-database:18.0.0'
// implementation 'com.google.firebase:firebase-auth:18.0.0'
// Firebase Firestore
// Need to exclude 'guava' to avoid dreaded 'Duplicate class' Errors during compile
implementation ('com.google.firebase:firebase-firestore:20.1.0')
{
exclude group: 'com.google.guava'
}
//----------------------------------------------------------------------------------------------
//--- Google Oauth and Google Sheets
//----------------------------------------------------------------------------------------------
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'pub.devrel:easypermissions:0.2.1'
implementation('com.google.api-client:google-api-client-android:1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
implementation('com.google.apis:google-api-services-sheets:v4-rev465-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
sourceSets {
main.java.srcDirs += 'src/main/<YOUR DIRECTORY>'
}
}
I tried to align it with playservices ie. 17.0.0 , also tried 18.x versions to no avail. Funny that it worked when I used the Firebase Realtime Database, so no incompatibility there. But I want to switch over to Firestore to take advantage of better ArrayList handling in the classes I want to write/read.
I also had to exclude the guava group or I would get those 'Duplicated class' errors (again, only with Firestone, not with the database).
Here is the full logcat:
2019-07-06 12:12:48.397 1671-1684/? E/memtrack: Couldn't load memtrack module
2019-07-06 12:12:48.541 7857-7857/com.mairyu.app.lingoflash E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mairyu.app.lingoflash, PID: 7857
java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$5(com.google.firebase:firebase-firestore##18.0.0:379)
at com.google.firebase.firestore.util.AsyncQueue$$Lambda$5.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NoSuchMethodError: No static method checkArgument(ZLjava/lang/String;I)V in class Lcom/google/common/base/Preconditions; or its super classes (declaration of 'com.google.common.base.Preconditions' appears in /data/app/com.mairyu.app.lingoflash-_VKmE7anO3pKy3BbdIRr4w==/base.apk)
at com.google.firebase.Timestamp.validateRange(com.google.firebase:firebase-firestore##18.0.0:160)
at com.google.firebase.Timestamp.<init>(com.google.firebase:firebase-firestore##18.0.0:65)
at com.google.firebase.firestore.model.SnapshotVersion.<clinit>(com.google.firebase:firebase-firestore##18.0.0:26)
at com.google.firebase.firestore.local.SQLiteQueryCache.<init>(com.google.firebase:firebase-firestore##18.0.0:40)
at com.google.firebase.firestore.local.SQLitePersistence.<init>(com.google.firebase:firebase-firestore##18.0.0:111)
at com.google.firebase.firestore.core.FirestoreClient.initialize(com.google.firebase:firebase-firestore##18.0.0:226)
at com.google.firebase.firestore.core.FirestoreClient.lambda$new$2(com.google.firebase:firebase-firestore##18.0.0:114)
at com.google.firebase.firestore.core.FirestoreClient$$Lambda$2.run(Unknown Source:8)
at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$4(com.google.firebase:firebase-firestore##18.0.0:311)
at com.google.firebase.firestore.util.AsyncQueue$$Lambda$4.call(Unknown Source:2)
at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$3(com.google.firebase:firebase-firestore##18.0.0:287)
at com.google.firebase.firestore.util.AsyncQueue$$Lambda$3.run(Unknown Source:4)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.firebase.firestore.util.AsyncQueue$DelayedStartFactory.run(com.google.firebase:firebase-firestore##18.0.0:205)
at java.lang.Thread.run(Thread.java:764)

In my very similar case the problem was because I haven't tried to exclude Guava from some dependency except Firestore. So at first I had similar implementation (just with newer version)
implementation ('com.google.firebase:firebase-firestore:21.3.1') {
exclude group: 'com.google.guava'
}
, but then I tried to move exclusion to the other dependency where it was affordable and acceptable. For me it was google api client:
implementation ('com.google.api-client:google-api-client:1.22.0') {
exclude group: 'com.google.guava'
}
Therefore, I left Firestore dependency without exclusions and it's just working fine now.
implementation 'com.google.firebase:firebase-firestore:21.3.1'

Related

Okta AuthenticationClientBuilder client builder causing app to crash

I have my app calling the AuthenicationClient builder on a button click. This is being tested on a physical Android 12 device.
handler.post(() -> runOnUiThread(() -> authenticationClient = AuthenticationClients.builder()
.setOrgUrl(getResources().getString(R.string.octa_issuer))
.build()));
Inside grade.build(:app) I have
implementation 'com.okta.android:okta-oidc-android:1.0.19'
implementation 'com.okta.authn.sdk:okta-authn-sdk-api:2.0.9'
implementation('com.okta.authn.sdk:okta-authn-sdk-impl:2.0.9') {
exclude group: 'com.okta.sdk', module: 'okta-sdk-httpclient'
}
implementation 'com.okta.sdk:okta-sdk-okhttp:2.0.0'
Error I receive when hitting the button and calling this builder. I have followed every document Okta has and some and just lost at this point. I get this error even without putting the builder on another thread.
FATAL EXCEPTION: main
Process: com.chrobinson.navispherecarrier.dev, PID: 22005
java.lang.NoSuchMethodError: No static method format(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String; in class Lorg/slf4j/helpers/MessageFormatter; or its super classes (declaration of 'org.slf4j.helpers.MessageFormatter' appears in /data/app/~~bfiUKjOLLeBPi-tTbkPssg==/com.chrobinson.navispherecarrier.dev-Bm0xcVwmy5sQv_7p0YZRcQ==/base.apk!classes21.dex)
at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:223)
at com.okta.sdk.impl.config.OptionalPropertiesSource.getProperties(OptionalPropertiesSource.java:42)
at com.okta.authn.sdk.impl.client.DefaultAuthenticationClientBuilder.(DefaultAuthenticationClientBuilder.java:117)
at com.okta.authn.sdk.impl.client.DefaultAuthenticationClientBuilder.(DefaultAuthenticationClientBuilder.java:85)
at java.lang.Class.newInstance(Native Method)
at com.okta.commons.lang.Classes.newInstance(Classes.java:164)
at com.okta.commons.lang.Classes.newInstance(Classes.java:150)
at com.okta.authn.sdk.client.AuthenticationClients.builder(AuthenticationClients.java:43)
at com.chrobinson.navispherecarrier.view.activities.LoginActivity.lambda$onSignIn$6$com-chrobinson-navispherecarrier-view-activities-LoginActivity(LoginActivity.java:208)
at com.chrobinson.navispherecarrier.view.activities.LoginActivity$$ExternalSyntheticLambda6.run(Unknown Source:2)
at android.app.Activity.runOnUiThread(Activity.java:7173)
at com.chrobinson.navispherecarrier.view.activities.LoginActivity.lambda$onSignIn$7$com-chrobinson-navispherecarrier-view-activities-LoginActivity(LoginActivity.java:208)
at com.chrobinson.navispherecarrier.view.activities.LoginActivity$$ExternalSyntheticLambda7.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:250)
at android.app.ActivityThread.main(ActivityThread.java:7877)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
Believe this was a library merge issue and this lib mimeutil was bringing in different versions than Okta was. I was able to fix the crash by excluding some parts the lib.
implementation ('eu.medsea.mimeutil:mime-util:2.1.3') {
exclude group: 'org.slf4j', module: 'slf4j-api'
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
}

Firebase and Socket.io compatibility issue crash my app

Every time add firebase dependencies, run my app and socket connect to endpoint, my app crashes immediately.
I'm using firebase and socket.io together and is causing the crash due to compatibility issues. Can firebase and socket.io be used together?
I get the following error when i added firebase and try to connect to socket.io in my project
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.project.hubrydemanagerapp, PID: 30101
java.lang.NoSuchMethodError: No virtual method callEngineGetConnection(Lcom/squareup/okhttp/Call;)Lcom/squareup/okhttp/Connection; in class Lcom/squareup/okhttp/internal/Internal; or its super classes (declaration of 'com.squareup.okhttp.internal.Internal' appears in /data/app/com.project.hubrydemanagerapp-t3ZbPD-QZAE9y2BMT64Cdg==/base.apk!classes3.dex)
at com.squareup.okhttp.ws.WebSocketCall.createWebSocket(WebSocketCall.java:154)
at com.squareup.okhttp.ws.WebSocketCall.access$000(WebSocketCall.java:42)
at com.squareup.okhttp.ws.WebSocketCall$1.onResponse(WebSocketCall.java:102)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
My dependencies:
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'com.google.firebase:firebase-firestore:21.3.0'
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation('com.github.nkzawa:socket.io-client:0.6.0') {
exclude group: 'org.json', module: 'json'
}
Endpoint
"https://hubryde-trip-service.herokuapp.com/";
"https://hubryde-request-service.herokuapp.com/";
Connection. I'm using Application class to create socket model.
tripSocket = IO.socket(TRIP_URL);
socket2 = IO.socket(BUS_URL);
SocketEndpoint app = (SocketEndpoint) getApplication();
tripSocket = app.getmTripSocket();
if(!tripSocket.connected()) {
tripSocket.connect();
}
socket2 = app.getmBusLocationSocket();
if(!socket2.connected()) {
socket2.connect();
}
}
Im also Using com.github.nkzawa:socket.io-client:0.6.0.
That crash also happened to me after adding firebase in app messaging module,
for me the quick fix (until this will be fixed, hopefully soon..)
was to add exclude..
hope it helps..
implementation ('com.google.firebase:firebase-inappmessaging-display:19.0.3') {
exclude group: 'com.squareup.okhttp', module: 'okhttp'
}
my full gradle file: (Using AndroidX)
implementation 'com.github.nkzawa:socket.io-client:0.6.0'
implementation 'tech.gusavila92:java-android-websocket-client:1.2.2'
implementation "com.google.firebase:firebase-messaging:20.1.4"
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation 'com.google.firebase:firebase-analytics:17.3.0'
implementation 'com.google.firebase:firebase-auth:19.3.0'
implementation ('com.google.firebase:firebase-inappmessaging-display:19.0.3') {
exclude group: 'com.squareup.okhttp', module: 'okhttp'
}
I have tested your dependencies and i realized firestore dependency is the reason for the crash not the entire firebase dependencies. It seems not to support The type of socket.io you are using OR not even support socket.io at all.
I even went further to test older version of cloud firestore, but no luck - The app keeps crashing with the same error.
So remove firestore and sync your project if you will see the error.

integrating Google Translation API and Google Speech API in android

App crashing when i am integrating Google Translation API into Google Speech API in android
Gradle :
implementation "io.grpc:grpc-okhttp:$grpcVersion"
implementation "io.grpc:grpc-protobuf-lite:$grpcVersion"
implementation "io.grpc:grpc-stub:$grpcVersion"
implementation 'javax.annotation:javax.annotation-api:1.2'
protobuf 'com.google.protobuf:protobuf-java:3.3.1'
implementation 'com.android.support:multidex:1.0.3'
// OAuth2 for Google API
implementation('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
exclude module: 'httpclient'
}
implementation ('com.google.cloud:google-cloud-translate:1.53.0'){
exclude module: 'httpclient'
}
Error:
Caused by: java.lang.NoSuchMethodError: No static method decodeBase64(Ljava/lang/String;)[B in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
at com.google.api.client.util.Base64.decodeBase64(Base64.java:101)
at com.google.api.client.util.PemReader.readNextSection(PemReader.java:106)
at com.google.api.client.util.PemReader.readFirstSectionAndClose(PemReader.java:135)
at com.google.auth.oauth2.ServiceAccountCredentials.privateKeyFromPkcs8(ServiceAccountCredentials.java:296)
at com.google.auth.oauth2.ServiceAccountCredentials.fromPkcs8(ServiceAccountCredentials.java:286)
at com.google.auth.oauth2.ServiceAccountCredentials.fromJson(ServiceAccountCredentials.java:210)
at com.google.auth.oauth2.GoogleCredentials.fromStream(GoogleCredentials.java:174)
at com.google.auth.oauth2.GoogleCredentials.fromStream(GoogleCredentials.java:141)
at com.google.cloud.android.speech.SpeechService$AccessTokenTask.doInBackground(SpeechService.java:361)
at com.google.cloud.android.speech.SpeechService$AccessTokenTask.doInBackground(SpeechService.java:337)
at android.os.AsyncTask$2.call(AsyncTask.java:295)

com.android.builder.merge.DuplicateRelativeFileException

When I implement these two dependencies in my project:
For BTC implementation 'org.bitcoinj:bitcoinj-core:0.14.7'
For BCH implementation 'cash.bitcoinj:bitcoincashj-examples:0.14.5.2'
This error will occur:
Caused by: com.android.builder.merge.DuplicateRelativeFileException: More than one file was found with OS independent path 'org.bitcoin.production.checkpoints.txt'
How can I resolve this?
This issue appears because bitcoincashj-examples library also transit org.bitcoinj:bitcoinj-core:0.14.5.2 dependency.
All that you need to do is exclude org.bitcoinj:bitcoinj-core:0.14.5.2 dependency from bitcoincashj-examples library.
implementation 'org.bitcoinj:bitcoinj-core:0.14.7'
implementation ('cash.bitcoinj:bitcoincashj-examples:0.14.5.2'){
exclude group: 'cash.bitcoinj', module: 'bitcoinj-core'
}

Program type already present: com.google.android.gms.common.util.VisibleForTesting

Hello I am getting following Error. I searched a lot, But none of the solution worked for me.
Caused by: com.android.builder.multidex.D8MainDexList$MainDexListException: com.android.tools.r8.errors.CompilationError: Program type already present: com.google.android.gms.common.util.VisibleForTesting
My Gradle
dependencies {
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true;
}
implementation 'com.android.support:multidex:1.0.3'
implementation files('libs/AdiquityAndroidSDK.jar')
implementation files('libs/gdx-backend-android.jar')
implementation files('libs/libGoogleAnalyticsServices.jar')
implementation files('src/main/jniLibs/gdx.jar')
// implementation files('src/main/jniLibs/gdx-backend-android.jar')
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.facebook.android:facebook-android-sdk:4.33.0'
}
I have also used latest gms plugin.
classpath 'com.google.gms:google-services:4.0.1'
with gradle-wrapper 4.4 and build gradle 3.1.3.
Please Help me How to solve this.
After Searching a lot, getting Solution.
after remove implementation files('libs/libGoogleAnalyticsServices.jar') issue solved.
The issue was that the file with the same package and file name was present in two different jars one jar was of old google analytics services jar.
We have to resolve this conflict (I had removed my old jar as it was no longer needed) and the project would build.
In My case after downgrading "play services" back to version 12 issue is successfully fixed.
change
implementation('com.google.android.gms:play-services-gcm:16.0.0') {
exclude module: 'guava-jdk5'
}
implementation ('com.google.android.gms:play-services-maps:16.0.0'){
exclude module: 'guava-jdk5'
}
to
implementation('com.google.android.gms:play-services-gcm:12.0.0') {
exclude module: 'guava-jdk5'
}
implementation ('com.google.android.gms:play-services-maps:12.0.0'){
exclude module: 'guava-jdk5'
}

Categories

Resources