We have created an Azure Event Hub and are getting an exception when the following line of code is executed. we are getting the below exception where in Android studio suggests that java/time/Duration is available only for API level 26 and above.
Is there a EventHub library available that supports Android 7.0 ?
EventHubClient client = EventHubClient.createSync(conn.toString(), Executors.newSingleThreadExecutor());
We get the following exception.
demo.eventhubsample E/AndroidRuntime: FATAL EXCEPTION: main
Process: demo.eventhubsample, PID: 24833
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/Duration;
at com.microsoft.azure.eventhubs.impl.MessagingFactory.<clinit>(MessagingFactory.java:46)
at com.microsoft.azure.eventhubs.impl.EventHubClientImpl.create(EventHubClientImpl.java:53)
at com.microsoft.azure.eventhubs.EventHubClient$-CC.create(EventHubClient.java:84)
at com.microsoft.azure.eventhubs.EventHubClient$-CC.lambda$createSync$0(EventHubClient.java:50)
at com.microsoft.azure.eventhubs.-$$Lambda$EventHubClient$c5UbZzYQx71Hbh8oGZBMd2lKXRw.execute(lambda)
at com.microsoft.azure.eventhubs.impl.ExceptionUtil.syncWithIOException(ExceptionUtil.java:200)
at com.microsoft.azure.eventhubs.EventHubClient$-CC.createSync(EventHubClient.java:50)
at com.microsoft.azure.eventhubs.EventHubClient$-CC.createSync(EventHubClient.java:35)
at demo.eventhubsample.MainActivity.sendEvent(MainActivity.java:65)
at demo.eventhubsample.MainActivity$1.onClick(MainActivity.java:44)
at android.view.View.performClick(View.java:5714)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22589)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.Duration" on path: DexPathList[[zip file "/data/app/demo.eventhubsample-1/base.apk"],nativeLibraryDirectories=[/data/app/demo.eventhubsample-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.microsoft.azure.eventhubs.impl.MessagingFactory.<clinit>(MessagingFactory.java:46)
at com.microsoft.azure.eventhubs.impl.EventHubClientImpl.create(EventHubClientImpl.java:53)
at com.microsoft.azure.eventhubs.EventHubClient$-CC.create(EventHubClient.java:84)
at com.microsoft.azure.eventhubs.EventHubClient$-CC.lambda$createSync$0(EventHubClient.java:50)
at com.microsoft.azure.eventhubs.-$$Lambda$EventHubClient$c5UbZzYQx71Hbh8oGZBMd2lKXRw.execute(lambda)
at com.microsoft.azure.eventhubs.impl.ExceptionUtil.syncWithIOException(ExceptionUtil.java:200)
at com.microsoft.azure.eventhubs.EventHubClient$-CC.createSync(EventHubClient.java:50)
at com.microsoft.azure.eventhubs.EventHubClient$-CC.createSync(EventHubClient.java:35)
at demo.eventhubsample.MainActivity.sendEvent(MainActivity.java:65)
at demo.eventhubsample.MainActivity$1.onClick(MainActivity.java:44)
at android.view.View.performClick(View.java:5714)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22589)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Suppressed: java.lang.ClassNotFoundException: java.time.Duration
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)
... 21 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Dependencies used
implementation 'com.microsoft.azure:azure-eventhubs:1.3.0'
API Level defined in gradle
minSdkVersion 21 targetSdkVersion 26
Java Version
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }