Running google cloud speech api on Android 4.2 - android

I have a problem running io.grpc:grpc-okhttp on Android 4.2 devices.
I have implemented SpeechClient with Credentials, for running Google cloud speech to text.
On Android 7.1 device I don't have a problem. The problems happen on Android 4.2
So in my starting gradle I had
implementation 'io.grpc:grpc-okhttp:1.35.0'
implementation 'io.grpc:grpc-android:1.35.0'
implementation 'com.google.cloud:google-cloud-speech:1.24.0'
Problems.
First problem was with TLS security for SSL (which is too old on Android 4.2). For this, I added dependency
implementation 'org.conscrypt:conscrypt-android:2.5.1'
and implemented in my DialogFragment (which is running the code)
Security.insertProviderAt(Conscrypt.newProvider(), 1)
After I implemented this, I am getting
Duplicate class org.conscrypt.AbstractConscryptEngine found in modules jetified-conscrypt-android-2.5.1-runtime (org.conscrypt:conscrypt-android:2.5.1) and jetified-conscrypt-openjdk-uber-2.2.1 (org.conscrypt:conscrypt-openjdk-uber:2.2.1)
issues (alot of duplicated classes)
So for fixing this, I added
configurations {
all {
exclude group: "org.conscrypt", module: "conscrypt-openjdk-uber"
}
}
Now I get this error, because com.google.api.client is using Standard.UTF-8 and my device is on Android 17.
com.google.api.gax.rpc.UnauthenticatedException: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Failed computing credential metadata
at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:73)
at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)
at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)
at com.google.api.gax.grpc.ExceptionResponseObserver.onErrorImpl(ExceptionResponseObserver.java:82)
at com.google.api.gax.rpc.StateCheckingResponseObserver.onError(StateCheckingResponseObserver.java:86)
at com.google.api.gax.grpc.GrpcDirectStreamController$ResponseObserverAdapter.onClose(GrpcDirectStreamController.java:149)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426)
at io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:689)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$900(ClientCallImpl.java:577)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:751)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:740)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
Caused by: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Failed computing credential metadata
at io.grpc.Status.asRuntimeException(Status.java:533)
at com.google.api.gax.grpc.GrpcDirectStreamController$ResponseObserverAdapter.onClose(GrpcDirectStreamController.java:149) 
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426) 
at io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66) 
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:689) 
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$900(ClientCallImpl.java:577) 
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:751) 
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:740) 
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) 
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
at java.lang.Thread.run(Thread.java:856) 
Caused by: java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
at com.google.api.client.util.StringUtils.getBytesUtf8(StringUtils.java:51)
at com.google.api.client.json.webtoken.JsonWebSignature.signUsingRsaSha256(JsonWebSignature.java:571)
at com.google.auth.oauth2.JwtCredentials.refresh(JwtCredentials.java:125)
at com.google.auth.oauth2.JwtCredentials.getRequestMetadata(JwtCredentials.java:163)
at com.google.auth.oauth2.ServiceAccountJwtAccessCredentials.getRequestMetadata(ServiceAccountJwtAccessCredentials.java:365)
at com.google.auth.Credentials.blockingGetToCallback(Credentials.java:112)
at com.google.auth.oauth2.ServiceAccountJwtAccessCredentials.getRequestMetadata(ServiceAccountJwtAccessCredentials.java:341)
at io.grpc.auth.GoogleAuthLibraryCallCredentials.applyRequestMetadata(GoogleAuthLibraryCallCredentials.java:110)
at io.grpc.CallCredentials2.applyRequestMetadata(CallCredentials2.java:58)
at io.grpc.internal.CallCredentialsApplyingTransportFactory$CallCredentialsApplyingTransport.newStream(CallCredentialsApplyingTransportFactory.java:108)
at io.grpc.internal.ForwardingConnectionClientTransport.newStream(ForwardingConnectionClientTransport.java:49)
at io.grpc.internal.InternalSubchannel$CallTracingTransport.newStream(InternalSubchannel.java:671)
at io.grpc.internal.DelayedClientTransport$PendingStream.createRealStream(DelayedClientTransport.java:353)
at io.grpc.internal.DelayedClientTransport$PendingStream.access$300(DelayedClientTransport.java:341)
Question:
How to resolve this issue and run Speech with "ApiStreamObserver?
I tried reverting back "io.grpc:grpc-" libraries to version 1.0 or something, but then I have other problems...

I have resolved this issue and commited example project on Github
https://github.com/DjToMeK27/CloudGoogleSpeechToText/tree/main
What I did in this project
Downloaded https://github.com/GoogleCloudPlatform/android-docs-samples/blob/master/README.md
Changed classes in project SpeechRecognitionClient in android-docs-samples-master\speech
Changed AudioRecord in AudoEmitter.kt to support API 16
Imported org.conscrypt:conscrypt-android:2.5.1 library
Had to exclude group org.conscrypt from google-cloud-speech (in build.gradle)
Added init { Security.insertProviderAt(Conscrypt.newProvider(), 1) } For Android 4.1 to run proper TLS for GRC to work
I downloaded https://github.com/googleapis project
Changed all StandardCharsets found in google-http-client to Charset.forName())
And also changed some tests to work
https://imgur.com/a/iU7yjCZ (files changes)
I have build this project and added .jar files, which I included here
And now it works!

Related

How to resolve this error: Caused by: java.lang.IllegalArgumentException: com.example.MyClassName does not represent a declared type?

I am getting this error while building my Kotlin/Android application?
Caused by: java.lang.reflect.InvocationTargetException
at jdk.internal.reflect.GeneratedMethodAccessor812.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:90)
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:31)
at org.jetbrains.kotlin.kapt3.base.Kapt.kapt(Kapt.kt:45)
... 30 more
Caused by: com.sun.tools.javac.processing.AnnotationProcessingError: java.lang.IllegalArgumentException: com.example.MyClassName does not represent a declared type
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:992)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:896)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1222)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1335)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1258)
... 35 more
Caused by: java.lang.IllegalArgumentException: com.example.MyClassName does not represent a declared type
at dagger.shaded.auto.common.MoreTypes$CastingTypeVisitor.defaultAction(MoreTypes.java:948)
at dagger.shaded.auto.common.MoreTypes$CastingTypeVisitor.defaultAction(MoreTypes.java:939)
at jdk.compiler/com.sun.tools.javac.code.Type$ErrorType.accept(Type.java:2394)
at dagger.shaded.auto.common.MoreTypes.asDeclared(MoreTypes.java:579)
at dagger.internal.codegen.base.Keys$1.visitDeclared(Keys.java:89)
at dagger.internal.codegen.base.Keys$1.visitDeclared(Keys.java:66)
at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1151)
at dagger.internal.codegen.base.Keys.isValidImplicitProvisionKey(Keys.java:65)
at dagger.internal.codegen.base.Keys.isValidImplicitProvisionKey(Keys.java:50)
I am using dagger2 for dependency injection, in my application, the application uses a module that has a dependency on another module. What should be the correct way to resolve this dependency?
You'll need an implementation dependency on the module you're consuming, but the recent build flag enableAggregatingTask will do so automatically.
Per google/dagger#2123, bcorso responding to Kshitij09 in November 2020:
You mean I either app should have direct dependency (adding implementation) on :libraryB or :libraryA have api dependency on :libraryB right?
Hi #Kshitij09, yes that's the current solution and we're looking into ways to improve this (see #1991 (comment))
In that same thread, bcorso updates in September 2021:
If you're using Hilt (with Gradle) the solution is to use the Hilt Gradle plugin and then enable the aggregating task in your build.gradle modules:
hilt {
enableAggregatingTask = true
}
The enableAggregatingTask build configuration was introduced in Dagger 2.37 in June 2021 and enabled by default in Dagger 2.40 in October 2021.

Jacoco: IllegalStateException: Can't add different class with same name

I am trying to generate Jacoco XML reports for this Android project. I am using the gradle-android-junit-jacoco-plugin version 0.16.0 (latest as of today).
When I run the jacocoTestReportMerged task it fails with the following error:
Caused by: java.io.IOException: Error while analyzing XmlPullParsers.class.
at org.jacoco.core.analysis.Analyzer.analyzerError(Analyzer.java:170)
at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:142)
at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:165)
at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:201)
at org.jacoco.ant.ReportTask.createBundle(ReportTask.java:570)
at org.jacoco.ant.ReportTask.createReport(ReportTask.java:542)
at org.jacoco.ant.ReportTask.execute(ReportTask.java:495)
... 210 more
Caused by: java.lang.IllegalStateException: Can't add different class with same name:
info/metadude/android/eventfahrplan/network/serialization/XmlPullParsers
at org.jacoco.core.analysis.CoverageBuilder.visitCoverage(CoverageBuilder.java:107)
at org.jacoco.core.analysis.Analyzer$1.visitEnd(Analyzer.java:98)
at org.objectweb.asm.ClassVisitor.visitEnd(ClassVisitor.java:338)
at org.jacoco.core.internal.flow.ClassProbesAdapter.visitEnd(ClassProbesAdapter.java:98)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:683)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:391)
at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:124)
at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:140)
... 215 more
I started configuring exclude rules such as ...
junitJacoco {
excludes = [
"**/XmlPullParsers.*"
]
}
... but then the task fails at the next file - so this does not seem to be the correct way.
I also tried 0.17.0-SNAPSHOT and version prior to 0.16.0, without success though. Gradle 6.3 is used in this project.
How can I configure the Gradle plugin for my project?

Release apk android in flutter is crashing on start up

I think my issue is because of Cloudfirestore that I am using inside my application. Some devices crash and some not.( S7 samsung verizon android 8.0 crashed, A5 samsung android 6.0 did not crash...). I used logcat to get the logs that are causing the crash and this is the error:
java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
at com.google.firebase.firestore.obfuscated.zzgf.zzb(com.google.firebase:firebase-firestore##17.1.1:377)
at com.google.firebase.firestore.obfuscated.zzgk.run(com.google.firebase:firebase-firestore##17.1.1)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5302)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: io.grpc.ManagedChannelProvider$ProviderNotFoundException: No functional channel service provider found. Try adding a dependency on the grpc-okhttp or grpc-netty artifact
at com.google.firebase.firestore.obfuscated.zzgf.zza(com.google.firebase:firebase-firestore##17.1.1:288)
at com.google.firebase.firestore.obfuscated.zzgi.run(com.google.firebase:firebase-firestore##17.1.1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at com.google.firebase.firestore.obfuscated.zzgf$zza.run(com.google.firebase:firebase-firestore##17.1.1:203)
at java.lang.Thread.run(Thread.java:856)
Caused by: io.grpc.ManagedChannelProvider$ProviderNotFoundException: No functional channel service provider found. Try adding a dependency on the grpc-okhttp or grpc-netty artifact
at io.grpc.ManagedChannelProvider.provider(ManagedChannelProvider.java:60)
at io.grpc.ManagedChannelBuilder.forTarget(ManagedChannelBuilder.java:70)
at com.google.firebase.firestore.obfuscated.zzfk.<init>(com.google.firebase:firebase-firestore##17.1.1:101)
at com.google.firebase.firestore.obfuscated.zzm.zza(com.google.firebase:firebase-firestore##17.1.1:1216)
at com.google.firebase.firestore.obfuscated.zzt.run(com.google.firebase:firebase-firestore##17.1.1)
at com.google.firebase.firestore.obfuscated.zzgf.zzc(com.google.firebase:firebase-firestore##17.1.1:309)
at com.google.firebase.firestore.obfuscated.zzgj.call(com.google.firebase:firebase-firestore##17.1.1)
at com.google.firebase.firestore.obfuscated.zzgf.zza(com.google.firebase:firebase-firestore##17.1.1:285)
at com.google.firebase.firestore.obfuscated.zzgi.run(com.google.firebase:firebase-firestore##17.1.1) 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
at com.google.firebase.firestore.obfuscated.zzgf$zza.run(com.google.firebase:firebase-firestore##17.1.1:203) 
at java.lang.Thread.run(Thread.java:856) 
so how to resolve such an error in flutter ??
Had the same issue with some phones like Samsung S5. The app started crashing when I tried to open it. Here is a fix that worked for me:
defaultConfig {
...
multiDexEnabled true
ndk {
abiFilters 'x86', 'armeabi-v7a'
}
}
Had to add ndk in android/app/build.gradle file and it worked like a charm.
I hope this can help someone.
you should check first if you have installed the latest cloud_firestore package (0.8.2+3) in your pubspec.yaml
you can upgrade the google services under <yourapp>/android/build.gradle (current version 4.2.0). But be aware that you maybe need to upgrade the other plugins as well to the newest version there.

Runtime exception from room in a project that is not using room

I suddnly started getting this runtime exception at app launch without having room as my dependency at all.
07-20 19:48:37.703 18737-18771/mypackage.x E/AndroidRuntime: FATAL EXCEPTION: pool-4-thread-1
Process: mypackage, PID: 18737
java.lang.IllegalStateException: A migration from 3 to 2 was required but not found. Please provide the necessary Migration path via RoomDatabase.Builder.addMigration(Migration ...) or allow for destructive migrations via one of the RoomDatabase.Builder.fallbackToDestructiveMigration* methods.
at android.arch.persistence.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:97)
at android.arch.persistence.room.RoomOpenHelper.onDowngrade(RoomOpenHelper.java:109)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onDowngrade(FrameworkSQLiteOpenHelper.java:144)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:396)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:96)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:54)
at android.arch.persistence.room.RoomDatabase.compileStatement(RoomDatabase.java:244)
at android.arch.persistence.room.SharedSQLiteStatement.createNewStatement(SharedSQLiteStatement.java:65)
at android.arch.persistence.room.SharedSQLiteStatement.getStmt(SharedSQLiteStatement.java:72)
at android.arch.persistence.room.SharedSQLiteStatement.acquire(SharedSQLiteStatement.java:87)
at androidx.work.impl.model.WorkSpecDao_Impl.resetScheduledState(WorkSpecDao_Impl.java:337)
at androidx.work.impl.WorkManagerImpl.rescheduleEligibleWork(WorkManagerImpl.java:514)
at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:73)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
here are some of the dependencies that I do have from Android arch:
implementation "androidx.core:core-ktx:$ktx_version"
implementation "android.arch.paging:runtime:$paging_runtime"
implementation("android.arch.lifecycle:extensions:$android_arc_version") {
force = true
}
implementation "android.arch.navigation:navigation-fragment-ktx:$navigation_version"
// use -ktx for Kotlin
implementation "android.arch.navigation:navigation-ui-ktx:$navigation_version"
implementation "android.arch.work:work-runtime-ktx:$work_version"
Any idea what might have caused this?
It turns out that android.arch.work:work had a dependency to the room library and I was using the version 1.0.0-alpha03 of work library. I thought of excluding the dependency but I noticed that an update is available for the work component and after trying that, it fixed the issue. So upgrade your work library to fix the issue (at this time the updated version is 1.0.0-alpha04)

Facebook Account Kit Collision with Google play services gradle

After configuring account kit sdk as
compile 'com.facebook.android:account-kit-sdk:4.+'
and gradle sync it conflict with com.google.android.gms gradle as mixing versions can lead to runtime crashes and my app crash as
Firebase API initialization failure.
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at ...
the above error is due to mixing google play services gradle (I think Google play services gradle may be used by Facebook Account Kit SDK) because I have same version for all Google play services gradles.
And one more crash is coming from Facebook Account Kit SDK side as
java.lang.RuntimeException: Unable to get provider com.facebook.accountkit.internal.AccountKitInitProvider: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
at android.app.ActivityThread.installProvider(ActivityThread.java:5260)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4808)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4748)
at android.app.ActivityThread.access$1700(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1436)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
at com.facebook.accountkit.internal.Initializer.initialize(Initializer.java:99)
at com.facebook.accountkit.internal.AccountKitController.initialize(AccountKitController.java:592)
at com.facebook.accountkit.internal.AccountKitInitProvider.onCreate(AccountKitInitProvider.java:31)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1758)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1733)
at android.app.ActivityThread.installProvider(ActivityThread.java:5257)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4808) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4748) 
at android.app.ActivityThread.access$1700(ActivityThread.java:153) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1436) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:5529) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629) 
But after removing
compile 'com.facebook.android:account-kit-sdk:4.+'
my app working without any issue.
But to integrate Facebook Account Kit in my app I have to include above gradle which conflict with google play services.
Totally disappointed, please help.
After upgrading Firebase Gradle as
compile 'com.google.firebase:firebase-messaging:11.6.0'
its not colliding but still gives above RuntimeException from Account Kit SDK.
To fix this you can do something like the following
compile ('com.facebook.android:account-kit-sdk:4.27.0') {
exclude group: 'com.google.android.gms', module: 'play-services-auth-api-phone'
exclude group: 'com.google.android.gms', module: 'play-services-auth'
}
compile 'com.google.android.gms:play-services-auth:11.6.0'
compile 'com.google.firebase:firebase-messaging:11.6.0'
That would remove the stale support gms library from Facebook's SDK and then swap in the same version of the lib that Firebase is using.
Possibly the conflict of libraries can be the reason. See dependencies here;
https://mvnrepository.com/artifact/com.facebook.android/account-kit-sdk/4.27.0
See if you could submit an issue with the facebook to update it.
Or if you need facebook for authentication only, you can use Facebook Android Sdk
What feature/service from firebase r u using , can u pls share the snippet of ur gradle dependencies for the same to better understand the problem here?
For Unable to get provider RuntimeException exception it seems that, Application is not initialized first, Content Providers are initialized before it.
And in Facebook account kit SDK's code it was trying to get my application context.
Now the problem was, I did implement method getApplicationContext() in application class that is getting application shared variable but that variable was setting globally and Facebook Account Kit sdk code getting Null application context.
Solution : setting shared variable in onCreate method instead of setting globally it resolved the problem of Unable to get provider.
And For Mixing issue, Account Kit SDK use 11.0.1 version for play services gradle and in my project I am having 11.0.4 that is actually not the issue because on compile time gradle takes latest gradle but In my project I am not referring below gradle which Facebook Account Kit SDK is using.
compile 'com.google.android.gms:play-services-auth-api-phone:11.0.1'
Solution : I have added above gradle with version 11.0.4 and the mixing gradle issue has been resolved.
compile 'com.google.android.gms:play-services-auth-api-phone:11.0.4'
And as suggested by #astryk if I exclude play-services-auth-api-phone module then gradle mixing error is not showing but it is not including that module becasue in AccountKitActivity on next button click my application crashes as
Crash Report Thread:main Exception:java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/auth/api/phone/SmsRetriever;
at com.facebook.accountkit.internal.PhoneLoginController.createSmsToken(PhoneLoginController.java:250)
at com.facebook.accountkit.internal.PhoneLoginController.logIn(PhoneLoginController.java:188)
at com.facebook.accountkit.internal.LoginManager.logInWithPhoneNumber(LoginManager.java:372)
at com.facebook.accountkit.internal.AccountKitController.logInWithPhoneNumber(AccountKitController.java:631)
at com.facebook.accountkit.ui.PhoneLoginFlowManager.logInWithPhoneNumber(PhoneLoginFlowManager.java:57)
at com.facebook.accountkit.ui.ActivityPhoneHandler.onPhoneLoginComplete(ActivityPhoneHandler.java:189)
at com.facebook.accountkit.ui.AccountKitActivity$1.onReceive(AccountKitActivity.java:176)
at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.auth.api.phone.SmsRetriever" on path: DexPathList[[zip file "/data/app/com.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myappList item -1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 16 more
Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.auth.api.phone.SmsRetriever
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 17 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available`

Categories

Resources