Repository navigation
fix(kotlin,android): make the SDKs and their Java examples usable from Java - #2095
Merged
Merged
Conversation
…m Java Java callers could not write the code the docs show. The Java examples called methods declared @throws(AppwriteException) without catching it, used List.of and Map.of without importing them, and left the client statement unterminated when a method has no auth headers. ID, Permission, Role, Query, Operator, Channel and InputFile helpers lived on companion objects without @JvmStatic, so Java had to go through Companion. Upload methods whose parameters are all required had no @jvmoverloads, so Java had to pass onProgress explicitly. On Android only the Map overload of a generic method carried @throws, so a Java try/catch around listRows<T> failed with "exception is never thrown". Every Android service method now declares it, matching the Kotlin SDK. The Kotlin and Android e2e suites now compile every generated Java example and run a Java class against the mock server.
🟢 Tier S · Ready to mergeThis pull request exposes Kotlin and Android SDK helpers and upload overloads for Java callers, declares Android checked exceptions, and updates generated Java documentation examples to compile. It also adds Java interop checks and compilation coverage for generated examples across the Kotlin and Android end-to-end suites. Latest changes: The latest commits add Java interop coverage for Query and Operator static helpers and Android Channel helpers, wiring the checks and expected output into both Android Java17 suites.
📂 Walkthrough · 10
✅ Fixed since the last review · 1
Reviewed the commits since |
2 tasks
…om Java The Java interop test only reached ID, Permission and Role, so losing @JvmStatic or @jvmoverloads on the other companion helpers would go unnoticed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes the Kotlin and Android SDKs callable from Java the way their docs show, and makes every generated Java example compile.
Checked exceptions on Android. Only the
Mapoverload of a generic method (e.g.listRows()) carried@Throws(AppwriteException::class); the genericlistRows<T>(…, nestedType)and every non-generic method did not. A Javatry { … } catch (AppwriteException e)around them failed withexception AppwriteException is never thrown in body of corresponding try statement. Every Android service method now declares it, matching the Kotlin SDK.Java examples (
docs/examples/java, both SDKs). Each one failed to compile: the call was not wrapped in a try/catch for the checked exception,List.of/Map.ofwere used without imports,Clientwas left unterminated (;missing) when a method has no auth headers, numeric list examples usedintliterals forList<Double>/List<Long>params, Android array-enum params got a single enum value, and Android OAuth examples omitted theactivityargument.Static helpers.
ID,Permission,Role,Query,Operator,InputFile(both SDKs) andChannel(Android) now have@JvmStatic, plus@JvmOverloadswhere a parameter has a default, so Java can writeID.unique()instead ofID.Companion.unique(7).Topic.pathis left alone: a staticpath(List)would clash with the instancepath(List)on the JVM.Upload overloads. Upload methods whose parameters are all required had no
@JvmOverloads, so Java had to passonProgressexplicitly. They now get the overload without it.Default endpoint (no change). Android's
Clientdefault ofhttps://cloud.appwrite.io/v1comes from the spec'sservers[0].url, the same source Web, React Native, Flutter/Dart and Apple/Swift use, so all client SDKs already agree.Behaviour note for Java users of the Android SDK: calls that previously compiled without a try/catch now need one (or a
throwsclause), as they already do with the Kotlin SDK.Test Plan
KotlinJava17Test,Android16Java17TestandAndroid5Java17Testnow:docs/examples/java/**.mdinto a Java class (tests/e2e/languages/kotlin/java-examples.php) and compile it with the SDK's tests. Four fixture-only examples are listed as unsupported: three pass request models, which the JVM examples still render asMap.of(…), and one calls a method namedenum, a Java keyword.JavaInterop.javaagainst the mock server:ID.unique(),Permission.read(Role.any()), a caughtAppwriteExceptionfrom a path check, anduploadGeneric(file, Map.class, callback)insidetry/catch (AppwriteException).origin/mainoutput, the Java examples fail with';' expectedand the Java class fails withcannot find symbolforID.unique()/Permission.read/Role.anyand for theuploadGenericoverload. A try/catch around AndroidgetPresetProfile(Map.class, …)fails withexception AppwriteException is never thrown.vendor/bin/phpunit tests/e2e/KotlinJava17Test.phppasses locally (216 assertions). The Android test sources (Tests.kt, JavaInterop.java, the 52 fixture examples) compile locally; the Docker run is left to CI.ktlintclean on regeneratedexamples/kotlinandexamples/android.composer lint,composer lint-twig,composer refactor:check, the max-line-length check and the Generation suite pass.Related PRs and Issues
None.
Closes #2096