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)
Related
I just found out that my Google Play Services are adding into merged manifest AD permission and for that reason I cant upload app to my playstore because it requires reasoning why I want ads in my app (I don't).
These are my gradle libraries:
//Google SDK
implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.gms:play-services-auth:20.3.0'
implementation 'com.google.android.gms:play-services-location:20.0.0'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.google.maps.android:android-maps-utils:2.0.3'
//GCM for internet connection monitoring
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
//GooglePay
implementation 'com.google.android.gms:play-services-wallet:19.1.0'
//Google Firebase SDK - Crashlytics, Firebase Messaging
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation ('com.google.firebase:firebase-crashlytics:18.2.13') {
transitive = true
}
implementation 'com.google.firebase:firebase-messaging:23.0.8'
This is merged manifest:
It seems like its google analytics (firebase). But I don't want and don't use any ad content in my app so I don't understand why is Google adding this stuff into my app without my approval.
I just tried to do this:
implementation 'com.google.firebase:firebase-core:21.1.1' {
exclude module: "play-services-ads-identifier"
exclude module: "play-services-measurement"
exclude module: "play-services-measurement-sdk"
}
as I found out but its not even compiling (got GradleScriptException):
Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method com.google.firebase:firebase-core:21.1.1() for arguments [build_ballt3q1t2mmz35mzah3ugy17$_run_closure2$_closure23#69dcec81] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
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.
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'
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'
}
I created Google Cloud endpoint library and follow the instructions from Calling Google Apis from Android
But I'm not able to use my endpoints. I created a new project in Android Studio
and copy all the dependencies in gradle.build But When I run the project I see following errors.
Java Compiler:
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\DELL\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\22.0\3564ef3803de51fb0530a8377ec6100b33b0d073\guava-22.0.jar
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Caused by: com.android.tools.r8.utils.AbortException
Android Issue:
Default interface methods are only supported starting with Android N (--min-api 24): java.util.Collection com.google.common.collect.BiMap.values()
Message{kind=ERROR, text=Default interface methods are only supported starting with Android N (--min-api 24): java.util.Collection com.google.common.collect.BiMap.values(), sources=[Unknown source file], tool name=Optional.of(D8)}
Default interface methods are only supported starting with Android N (--min-api 24): boolean com.google.common.base.Predicate.test(java.lang.Object)
Message{kind=ERROR, text=Default interface methods are only supported starting with Android N (--min-api 24): boolean com.google.common.base.Predicate.test(java.lang.Object), sources=[Unknown source file], tool name=Optional.of(D8)}
My MainActivity.java is empty right now.
Here is my gradle.build
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.azeem.endpointtest"
minSdkVersion 15
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(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
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'
// Add the Google API client library.
implementation(group: 'com.google.api-client', name: 'google-api-client', version: '1.21.0') {
// Exclude artifacts that the Android SDK/Runtime provides.
exclude(group: 'xpp3', module: 'xpp3')
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
exclude(group: 'junit', module: 'junit')
exclude(group: 'com.google.android', module: 'android')
}
// Add the Android extensions for the Google API client library.
// This will automatically include play services as long as you have download that library
// from the Android SDK manager.
// Add the Android extensions for the Google API client library.
implementation(group: 'com.google.api-client', name: 'google-api-client-android',
version: '1.21.0')
{
// Exclude play services, since we're not using this yet.
exclude(group: 'com.google.android.gms:play-services', module: 'google-play-services')
}
// END Google APIs
// The following client libraries make HTTP/JSON on Android easier.
// Android extensions for Google HTTP Client.
implementation(group: 'com.google.http-client', name: 'google-http-client-android',
version: '1.21.0') {
exclude(group: 'com.google.android', module: 'android')
}
// This is used by the Google HTTP client library.
implementation(group: 'com.google.guava', name: 'guava', version: '22.0')
implementation files('libs/endpointapi-v1-1.23.0-SNAPSHOT.jar')
}
In my whole Api I don't need to make any authenticated calls So, please let me know what library is not required so I removed. I want to implement mini library that are necessary. And please let me know why I'm facing this error.
I found it myself, Only two dependencies are required for this.
One is google-api-client-android and the other is Your_endpoint_lib
implementation 'com.google.api-client:google-api-client-android:1.23.0';
implementation files('libs/endpointapi-v1-1.23.0-SNAPSHOT.jar')