Java Question {Solved/cancelled] NoSuchAlgorithmException: JKS KeyStore not available

DonManfred

Expert
Licensed User
Longtime User
Hello,

i´m trying to get a GoogleApiclient working to be able to use the Google Calendar Api.
But i´m running into Exceptions and do not know what i need to add (include, additionaljar)

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 346)
java.security.KeyStoreException: JKS not found
at java.security.KeyStore.getInstance(KeyStore.java:890)
at com.google.api.client.util.SecurityUtils.getJavaKeyStore(SecurityUtils.java:53)
at com.google.api.client.googleapis.GoogleUtils.getCertificateTrustStore(GoogleUtils.java:74)
at com.google.api.client.googleapis.javanet.GoogleNetHttpTransport.newTrustedTransport(GoogleNetHttpTransport.java:55)
at de.donmanfred.GoogleCalendarClientwrapper.Initialize(GoogleCalendarClientwrapper.java:50)
at de.donmanfred.gcalclient.main._activity_create(main.java:346)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at de.donmanfred.gcalclient.main.afterFirstLayout(main.java:104)
at de.donmanfred.gcalclient.main.access$000(main.java:17)
at de.donmanfred.gcalclient.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.security.NoSuchAlgorithmException: JKS KeyStore not available
at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)
at java.security.Security.getImpl(Security.java:590)
at java.security.KeyStore.getInstance(KeyStore.java:887)
... 17 more

The code which raises the Exception is:
B4X:
        ba.Log("Build Credentials");
        this.credentials = new GoogleCredential.Builder().setTransport(GoogleNetHttpTransport.newTrustedTransport())
              .setJsonFactory(new GsonFactory())
              .setServiceAccountId(ServiceAccountId)
              .setServiceAccountScopes(Arrays.asList("https://www.googleapis.com/auth/calendar"))
              .setServiceAccountPrivateKeyFromP12File(new File(p12file))
              .setServiceAccountUser(ServiceAccountUSer)
            .build();

Anyone have an Idea?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
It is a library for google calendar for java.

On the documentation i found infos about how to setup gradle for this. I gues gradle is adding a keystore to a project.
I tried to find dependencies and used additionaljar

B4X:
#AdditionalJar: google-oauth-client-1.25.0
#AdditionalJar: google-api-client-1.25.0
#AdditionalJar: google-api-client-android-1.25.0
#AdditionalJar: google-api-client-gson-1.25.0
#AdditionalJar: google-api-client-jackson2-1.25.0
#AdditionalJar: google-api-client-java6-1.25.0
#AdditionalJar: google-api-client-servlet-1.25.0
#AdditionalJar: google-api-services-calendar-v3-rev355-1.25.0
#AdditionalJar: google-http-client-1.25.0
#AdditionalJar: google-http-client-android-1.25.0
#AdditionalJar: google-http-client-gson-1.25.0
#AdditionalJar: google-oauth-client-java6-1.25.0
#AdditionalJar: httpclient-4.5.5
#AdditionalJar: guava-27.0.1-android

After further googling i found out that i should use ContentResolver to add a Event or get Eventlist from a calendar.
I even should use the CalendarProvider.

I also should use a syncadapter for the Caslendar if i want new events to get synced with google.

I´m planning to stop here and i´m reading more about the way how it works with content-resolver, CalendarProvider and try to setup also a Syncadapter.

Case closed for now.

PD: Deep in mind i have the feeling i already got this answer from you in the past but my bain is kidding me it seems ;-/
 

DonManfred

Expert
Licensed User
Longtime User
Follow up for anyone who is interested.

I played around with a ContentResolver used in my Wrapper. Together with java-code i found in Internet. I did got it working to query Calendars, Events.
While playing around with it i learned a lot about how it works (i did not used it very much in the past).

I now changed my wrapper to apply a lot of contants needed.
I then switched to B4As ContentResolver and tried to build them (query Calendars) with the CR to get it work without a library (except the contants. And these can be done without a lib easily too. For now i have a wrapperlib for them....

calcon is a Object which contains Constants. I also have one for Event-Constants.

B4A Code to get all Calendars.

B4X:
    '
    ' cr = ContentResolver
    '
    ' Getting Calendars i have access to. Or i can "see". At this time i do not know exactly ;-)
    Dim projection() As String = Array As String(calcon.ID,calcon.NAME,calcon.CALENDAR_DISPLAY_NAME,calcon.ACCOUNT_NAME,calcon.ACCOUNT_TYPE,calcon.OWNER_ACCOUNT)
    cr.Initialize("CR")
    cr.QueryAsync(calcon.CONTENT_URI,projection, calcon.VISIBLE&"=1",Null,calcon.ID&" ASC")
    wait for CR_QueryCompleted(Success As Boolean, Crsr As Cursor)
    Log($"QueryCompleted(${Success})"$)
    If Crsr.IsInitialized Then
        If Crsr.RowCount > 0 Then
            Dim Cursor As Cursor
            Cursor = Crsr
            For i = 0 To Cursor.RowCount - 1
                Cursor.Position = i
                'calcon.ACCOUNT_TYPE,calcon.OWNER_ACCOUNT)
                Log($"CR --------------------------------------"$)
                Log(Cursor.GetString(calcon.ID))
                Log(Cursor.GetString(calcon.NAME))
                Log(Cursor.GetString(calcon.CALENDAR_DISPLAY_NAME))
                Log(Cursor.GetString(calcon.ACCOUNT_NAME))
                Log(Cursor.GetString(calcon.ACCOUNT_TYPE))
                Log(Cursor.GetString(calcon.OWNER_ACCOUNT))
              
            Next
            Cursor.Close
        Else
            ' No rows
        End If
    Else
        '
    End If

It does list all Calendars i subscribed on my Device.... :)

Attached the Wrapper with the Contants and the CR inside the wrapper. content will change. I plan to concentrate on the B4A CR and maybe write a Class for all the Methods... Don´t know. I´m playing around at this time...
 

Attachments

  • GoogleCalendarClientV0.02.zip
    8.4 KB · Views: 415
Top