Adding PubSub as a dependency causes errors with Firestore - java

I am fairly new to Android and the Google cloud. I have written a test app which successfully writes to a firestore database.
I wanted to extend my application by adding a feature to publish to a pubsub topic.
I added the following dependency line to build.gradle:
implementation 'com.google.cloud:google-cloud-pubsub:0.33.0-beta'
Before I even added any new pubsub code, my app builds, runs, and immediately crashes with the following stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tliv.mytestapp, PID: 27506
java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
at com.google.android.gms.internal.zzeux.run(Unknown Source:23)
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.util.ServiceConfigurationError: Provider io.grpc.netty.NettyChannelProvider could not be instantiated: java.lang.ClassCastException: class io.grpc.netty.NettyChannelProvider cannot be cast to com.google.android.gms.internal.zzfmw
at com.google.android.gms.internal.zzfmw.zzq(Unknown Source:84)
at com.google.android.gms.internal.zzfmw.zzdcr(Unknown Source:26)
at com.google.android.gms.internal.zzfmw.<clinit>(Unknown Source:12)
at com.google.android.gms.internal.zzfmw.zzdcs(Unknown Source:0)
at com.google.android.gms.internal.zzfmv.zzud(Unknown Source:0)
at com.google.android.gms.internal.zzeti.<init>(Unknown Source:22)
at com.google.android.gms.internal.zzenf.zza(Unknown Source:74)
at com.google.android.gms.internal.zzenh.run(Unknown Source:8)
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.android.gms.internal.zzeuu$zza.run(Unknown Source:7)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.ClassCastException: class io.grpc.netty.NettyChannelProvider cannot be cast to com.google.android.gms.internal.zzfmw
at java.lang.Class.asSubclass(Class.java:2469)
at com.google.android.gms.internal.zzfmw.zzq(Unknown Source:2)
at com.google.android.gms.internal.zzfmw.zzdcr(Unknown Source:26) 
at com.google.android.gms.internal.zzfmw.<clinit>(Unknown Source:12) 
at com.google.android.gms.internal.zzfmw.zzdcs(Unknown Source:0) 
at com.google.android.gms.internal.zzfmv.zzud(Unknown Source:0) 
at com.google.android.gms.internal.zzeti.<init>(Unknown Source:22) 
at com.google.android.gms.internal.zzenf.zza(Unknown Source:74) 
at com.google.android.gms.internal.zzenh.run(Unknown Source:8) 
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.android.gms.internal.zzeuu$zza.run(Unknown Source:7) 
at java.lang.Thread.run(Thread.java:764) 
I'm not sure where to begin troubleshooting this. As soon as I remove the pubsub dependency, my code builds and runs fine again.

As per the doc, "Google Cloud Java client libraries do not currently support Android".
You may want to use the Google Cloud Pub/Sub API Client Library instead for your project.

Related

java.lang.NoClassDefFoundError: org.jumpmind.symmetric.io.stage.StagingManager$1, even though the class exists in the jar file

I am trying to integrate Symmetric-Android 3.10.2 in my Android application. It is showing
java.lang.NoClassDefFoundError:
org.jumpmind.symmetric.io.stage.StagingManager$1
Even the class exists in jarfile
I have upgraded my API level from 22 to 26 after reading article from
https://sourceforge.net/p/symmetricds/discussion/1354726/thread/f965364c00/
but the issue remains
java.lang.NoClassDefFoundError:
org.jumpmind.symmetric.io.stage.StagingManager$1
at org.jumpmind.symmetric.io.stage.StagingManager.(StagingManager.java:288)
at org.jumpmind.symmetric.android.AndroidSymmetricEngine.createStagingManager(AndroidSymmetricEngine.java:108)
at org.jumpmind.symmetric.AbstractSymmetricEngine.init(AbstractSymmetricEngine.java:348)
at org.jumpmind.symmetric.android.AndroidSymmetricEngine.(AndroidSymmetricEngine.java:84)
at org.jumpmind.symmetric.android.SymmetricService.onStartCommand(SymmetricService.java:88)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3944)
at android.app.ActivityThread.access$2300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1833)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
It sounds like your issue may not be related to SymmetricDS, but instead how your classpath is configured in this Android project. There are several solutions in this thread that might help

java.lang.UnsatisfiedLinkError: dlopen failed: library "libpthread.so.0" not found

Im trying to make an app for serial comminucation with android
im using rxtx library
Unfortunately i got a problem in my project
Thats my Logcat error :
java.lang.UnsatisfiedLinkError: dlopen failed: library "libpthread.so.0" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
at java.lang.System.loadLibrary(System.java:1669)
at gnu.io.LibraryLoader.loadRxtxNative(LibraryLoader.java:32)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:118)
at gnu.io.CommPortIdentifier.getPortIdentifier(Unknown Source:0)
at com.example.pooya.myapplication.Connection.open(Connection.java:145)
at com.example.pooya.myapplication.MainActivity$1.onClick(MainActivity.java:37)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
i added the libpthread.so.0 file to my jnilibs (all subfolders) but the result is same.
please give me a hint to solve this problem
There is no libpthread.so on Android, all threading functions are handled by libc itself. It seems the RxTx library does not support the Android platform.
You can try porting it yourself or use another solution:
Android Things API
Android USB Host API
RxTx Android port (warning: last update 2011)
android-serialport-api (warning: last update 2011)
usb-serial-for-android (last update 2016)

Android app with AWS analytic integration failed to read awsconfiguration.json

I am following the tutorial here
I am just trying to get a feel for Android development and AWS integration. I setup the basic helloworld Android app following this guide. Then went on to add the AWS components in the first link.
When I get to the "Monitor Analytics" section, my project will build but throw an exception at runtime.
The exception is as follows:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.xxxx.wearables_data_receiver.app/com.xx.xxxx.wearables_data_receiver.feature.MainActivity}: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.
at com.amazonaws.mobile.config.AWSConfiguration.readInputJson(AWSConfiguration.java:99)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:83)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:68)
at com.amazonaws.mobile.config.AWSConfiguration.<init>(AWSConfiguration.java:45)
at com.amazonaws.mobile.client.AWSMobileClient.initialize(AWSMobileClient.java:155)
at com.xx.xxxx.wearables_data_receiver.feature.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1351)
at android.content.res.Resources.openRawResource(Resources.java:1265)
at android.content.res.Resources.openRawResource(Resources.java:1241)
at com.amazonaws.mobile.config.AWSConfiguration.readInputJson(AWSConfiguration.java:88)
The line:
at com.xx.xxxx.wearables_data_receiver.feature.MainActivity.onCreate(MainActivity.java:51)
Points to the "AWSMobileClient.getInstance().initialize" call from the tutorial in the first link:
AWSMobileClient.getInstance().initialize(this, new AWSStartupHandler() {
#Override
public void onComplete(AWSStartupResult awsStartupResult) {
System.out.println("AWSMobileClient is instantiated and you are connected to AWS!");
}
}).execute();
I'm not sure what's going on here, I have tried opening up the file permissions, and placing it in a few different directories but to no avail. Any help would be greatly appreciated.
The error is due to missing awsconfiguration.json file.
Caused by: java.lang.RuntimeException: Failed to read awsconfiguration.json please check that it is correctly formed.
Could you make sure that you have the awsconfiguration.json file placed in the res/raw directory and has valid json? If you did the set up using Amplify CLI it should always automatically update the awsconfiguration.json file with required information.

java.security.GeneralSecurityException CryptoCipher when using Apache Crypto Commons

I'm attempting to use the code here for encryption https://commons.apache.org/proper/commons-crypto/xref-test/org/apache/commons/crypto/examples/CipherByteArrayExample.html. I copied the code word-for-word and I am not sure why I'm getting this exception as I can't find much on the issue. The only part that I changed was "StandardCharsets.UTF_8" to the String "UTF-8." I am also not interested in using Bouncy Castle or the java JCE as alternatives but am open to other libraries that use AES/DES in CBC/ECB modes (I am aware of the dangers of DES/ECB so no need for the lecture). Thank you.
EDIT:
Stack trace (Note that line 62 of Crypto.java is "CryptoCipher encipher=Utils.getCipherInstance(transform, properties) ):
W/System.err: java.io.IOException: java.security.GeneralSecurityException: CryptoCipher {org.apache.commons.crypto.cipher.OpenSslCipher} is not available or transformation AES/CBC/PKCS5Padding is not supported.
at org.apache.commons.crypto.utils.Utils.getCipherInstance(Utils.java:130)
at com.example.me.cryptotest.Crypto.test(Crypto.java:62)
at com.example.me.cryptotest.MainActivity.onCreate(MainActivity.java:43)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
W/System.err:
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
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.security.GeneralSecurityException: CryptoCipher {org.apache.commons.crypto.cipher.OpenSslCipher} is not available or transformation AES/CBC/PKCS5Padding is not supported.
at org.apache.commons.crypto.cipher.CryptoCipherFactory.getCryptoCipher(CryptoCipherFactory.java:176)
at org.apache.commons.crypto.utils.Utils.getCipherInstance(Utils.java:128)
... 15 more
W/System.err: Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.apache.commons.crypto.utils.ReflectionUtils.newInstance(ReflectionUtils.java:90)
at org.apache.commons.crypto.cipher.CryptoCipherFactory.getCryptoCipher(CryptoCipherFactory.java:160)
... 16 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
W/System.err:
at org.apache.commons.crypto.utils.ReflectionUtils.newInstance(ReflectionUtils.java:88)
... 17 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: no native library is found for os.name=Linux and os.arch=x86
at org.apache.commons.crypto.cipher.OpenSslCipher.<init>(OpenSslCipher.java:59)
... 20 more
Caused by: java.lang.RuntimeException: no native library is found for os.name=Linux and os.arch=x86
at org.apache.commons.crypto.NativeCodeLoader.findNativeLibrary(NativeCodeLoader.java:120)
at org.apache.commons.crypto.NativeCodeLoader.loadLibrary(NativeCodeLoader.java:62)
at org.apache.commons.crypto.NativeCodeLoader.<clinit>(NativeCodeLoader.java:50)
at org.apache.commons.crypto.NativeCodeLoader.isNativeCodeLoaded(NativeCodeLoader.java:261)
at org.apache.commons.crypto.Crypto.isNativeCodeLoaded(Crypto.java:84)
W/System.err: at org.apache.commons.crypto.cipher.OpenSsl.<clinit>(OpenSsl.java:94)
at org.apache.commons.crypto.cipher.OpenSsl.getLoadingFailureReason(OpenSsl.java:114)
at org.apache.commons.crypto.cipher.OpenSslCipher.<init>(OpenSslCipher.java:57)
... 20 more
I see your problem here:
java.lang.RuntimeException: no native library is found for os.name=Linux and os.arch=x86
Looks like you are not using Oracle JVM. Possible your JVM is reporting different os.arch string then standard Oracle JVM, so you need to copy the native library from possibly linux/i386 to linux/x86 (wild guess). Fire a google search on this error no native library is found for os.name=Linux and os.arch=x86, and playaround with your OS & JVM to help your runtime find the required native library(s).
Update:
If you look at the `README.md' of the project on github. You will notice this:
Portable across various operating systems (currently only Linux/MacOSX/Windows); Apache Commons Crypto loads the library according to your machine environment (it checks system properties, os.name and os.arch).
And this is the dll structure they have in the code,
so you can override your System property 'os.arch' to load the native library as per your OS:
System.setProperty("os.arch", "#folder")
Just for reference, I am running the code in Windows 10 with Oracle JDK8, so my derived path is coming to /org/apache/commons/crypto/native/Windows/x86_64/commons-crypto.dll
Hope this will provide you more help in resolving the issue.

NoClassDefFoundError caught in Android project [duplicate]

Suddenly started receiving this error since a support library update, which crashes the application on launch, even if everything builds fine. I tried to use lower version packages, which gave me the same error. I tried complete reinstall of Xamarin and Android SDK and finally creating a new Project which uses AppCompat but no success.
Android Support Library v22.2
Packages:
Xamarin.Android.Support.v7.AppCompat v22.2
Xamarin.Android.Support.v7.MediaRouter v22.2
Xamarin.Android.Support.v4 v22.2
Xamarin.Android.Support.v13 v22.2
Xamarin.GooglePlayServices v22.2.0.2
Call Stack:
System.Diagnostics.Debugger.Mono_UnhandledException_internal () in
System.Diagnostics.Debugger.Mono_UnhandledException (ex={Java.Lang.NoClassDefFoundError: Exception of type 'Java.Lang.NoClassDefFoundError' was thrown.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00078>
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue*) [0x00084] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029
at Android.App.Activity.OnCreate (Android.OS.Bundle) [0x00070] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:2725
at MyApp.MainActivity.OnCreate (Android.OS.Bundle) [0x0001f] in c:\Users\Admin\Documents\Projects\MyApp\MyApp\Activities\MainActivity.cs:43
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:2707
at (wrapper dynamic-method) object.e364abe5-1498-42eb-85b3-b3d7986e8b04 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
--- End of managed exception stack trace ---
java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:93)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:77)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:429)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:57)
at md5528fae1ec675c410de183ce65ec994d2.MainActivity.n_onCreate(Native Method)
at md5528fae1ec675c410de183ce65ec994d2.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5333)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
}) in
Android.Runtime.UncaughtExceptionHandler.UncaughtException (thread=, ex=) in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/src/Runtime/UncaughtExceptionHandler.cs:35
Java.Lang.Thread.IUncaughtExceptionHandlerInvoker.n_UncaughtException_Ljava_lang_Thread_Ljava_lang_Throwable_ (Parameters=) in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.Thread.cs:221
object.ce1e54b9-203c-4387-b0fe-be79adb149c0 (Parameters=) in
Today I reinstalled all the support libraries, cleaned and recompiled the app again and the error was gone.

Categories

Resources