Android Question Health Connect Wrapper

Katja

Member
Licensed User
Longtime User
Hi everyone,

I am currently working on a B4A wrapper for the Android Health Connect SDK. I am developing the wrapper in Android Studio (Kotlin) and my goal is to produce two JAR files:
1.StepCounterHC.jar (the wrapper classes)
2.stepcounterhc_dependencies.jar (all merged dependencies like Health Connect, Protobuf, and Guava).

When I compile in B4A, I get the following Dex error:

Error in C:\Android\tools\..\extras\b4a_local\unpacked-com.google.guava-guava-63914864012000\dex_v1\com.google.guava-guava.zip:classes.dex:
Type com.google.common.base.Function is defined multiple times: C:\Android\tools\..\extras\b4a_local\unpacked-com.google.guava-guava-63914864012000\dex_v1\com.google.guava-guava.zip:classes.dex, C:\Android\tools\..\extras\b4a_local\unpacked-stepcounterhc_dependencies-63922555505069\dex_v1\stepcounterhc_dependencies.zip:classes.dex

If I exclude guava from stepcounterhc_dependecies.jar I get a runtime error ClassNotFound: Settablefuture (which is from guava). When I search for com.google.guava-guava at runtime, its not found at all but its in the list of dexed files.

I am at a loss here, any help is highly appreciated. Thanks.
 
Solution
Seems B4A is missing this in guava and its needed by Health Connect: failureaccess-1.0.2.jar. I added it via #AdditionalJar and also kotlinx-coroutines-guava-1.8.1.jar. Now the errors are gone.

Katja

Member
Licensed User
Longtime User
Hi,

I attached the xml and jar with the methods. The stepcounterhc_dependecies.jar (without guava) is too large, here´s a link for the download:
In my B4A Code I use:
B4X:
        hc.Initialize("hc")
        Log("hc: " &hc)
        Dim available As Boolean = hc.IsAvailable(GetContext)
        
        Log("Health Connect Available: " & available)
        
        If available Then
                   
            Log("get daily steps")
            Try
                hc.GetDailySteps(GetContext, "2023-10-27")
            Catch
                
                Log(LastException)
            End Try
            
        Else
            Log("Health Connect is not installed or supported on this device.")
        End If

This is from The B4A Log:

** Activity (stepcounter) Resume **
hc: com.example.stepcounterhc.StepCounterWrapper@cf4f719
Health Connect Available: true
get daily steps
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/util/concurrent/SettableFuture;
at androidx.health.platform.client.impl.ipc.Client.executeWithVersionCheck(Client.java:132)
at androidx.health.platform.client.impl.ServiceBackedHealthDataClient.readDataRange(ServiceBackedHealthDataClient.kt:165)
at androidx.health.connect.client.impl.HealthConnectClientImpl.readRecords(HealthConnectClientImpl.kt:227)
at com.example.stepcounterhc.StepCounterWrapper$GetDailySteps$1.invokeSuspend(StepCounterWrapper.kt:48)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@dfe7de4, Dispatchers.IO]
Caused by: java.lang.ClassNotFoundException: com.google.common.util.concurrent.SettableFuture
... 12 more
 

Attachments

  • StepCounterHC.jar
    12.3 KB · Views: 38
  • StepCounterHC.xml
    3.6 KB · Views: 34
Upvote 0

Katja

Member
Licensed User
Longtime User
Seems B4A is missing this in guava and its needed by Health Connect: failureaccess-1.0.2.jar. I added it via #AdditionalJar and also kotlinx-coroutines-guava-1.8.1.jar. Now the errors are gone.
 
Upvote 0
Solution
Top