ory / sdk

The place where ORY's SDKs are being auto-generated
Apache License 2.0
137 stars 85 forks source link

Unable to use Java client on Android #272

Closed wondering639 closed 1 year ago

wondering639 commented 1 year ago

Preflight checklist

Describe the bug

Calling createNativeLoginFlow on Android leads to java.lang.NoClassDefFoundError, see "Relevant log output" for details. Before that I already had to do some fiddling with gradle (excludes for duplicate classes were necessary). Seems like the Java SDK is not intended for Android? How to use Ory on native Android then? (I normally use Kotlin for Android, a Kotlin client would be also fine for me)

Reproducing the bug

  1. Create Android project
  2. Add this in build.gradle:
    implementation("sh.ory:ory-client:1.1.33") {
        exclude group : 'org.apache.oltu.oauth2', module: 'org.apache.oltu.oauth2.common'
    }
  3. Call this method:

    private void makeOryClientCall() {
    StrictMode.ThreadPolicy gfgPolicy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(gfgPolicy);
    
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://<slug>.projects.oryapis.com");
    
    FrontendApi apiInstance = new FrontendApi(defaultClient);
    Boolean refresh = true; // Boolean | Refresh a login session  If set to true, this will refresh an existing login session by asking the user to sign in again. This will reset the authenticated_at time of the session.
    String aal = "aal1"; // String | Request a Specific AuthenticationMethod Assurance Level  Use this parameter to upgrade an existing session's authenticator assurance level (AAL). This allows you to ask for multi-factor authentication. When an identity sign in using e.g. username+password, the AAL is 1. If you wish to \"upgrade\" the session's security by asking the user to perform TOTP / WebAuth/ ... you would set this to \"aal2\".
    String xSessionToken = "xSessionToken_example"; // String | The Session Token of the Identity performing the settings flow.
    Boolean returnSessionTokenExchangeCode = true; // Boolean | EnableSessionTokenExchangeCode requests the login flow to include a code that can be used to retrieve the session token after the login flow has been completed.
    String returnTo = "<valid redirect url>"; // String | The URL to return the browser to after the flow was completed.
    try {
        LoginFlow result = apiInstance.createNativeLoginFlow(refresh, aal, xSessionToken, returnSessionTokenExchangeCode, returnTo);
        System.out.println(result);
    } catch (ApiException e) {
        Log.e("makeOryClientCall", "Exception when calling FrontendApi#createNativeLoginFlow");
        Log.e("makeOryClientCall","Status code: " + e.getCode());
        Log.e("makeOryClientCall","Reason: " + e.getResponseBody());
        Log.e("makeOryClientCall","Response headers: " + e.getResponseHeaders());
        e.printStackTrace();
    }
    }

Relevant log output

java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/ws/rs/core/GenericType;
    at sh.ory.model.UiNodeAttributes.validateJsonObject(UiNodeAttributes.java:380)
[..]   
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.ws.rs.core.GenericType" on path: DexPathList[[<paths removed for better readability>]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
[..]

Relevant configuration

No response

Version

1.1.33

On which operating system are you observing this issue?

Other

In which environment are you deploying?

Other

Additional Context

Same issue no matter if used on a pure Java or Kotlin Android project

wondering639 commented 1 year ago

Obviously the Java SDK depends on Java classes not available on Android -> extra Android client needed. Closing this issue as it is about the Java SDK.