Skip to content

fix(kotlin,android): make the SDKs and their Java examples usable from Java - #2095

Merged
ChiragAgg5k merged 3 commits into
mainfrom
fix/jvm-java-interop
Oct 17, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
fix/jvm-java-interop

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

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 Map overload of a generic method (e.g. listRows()) carried @Throws(AppwriteException::class); the generic listRows<T>(…, nestedType) and every non-generic method did not. A Java try { … } catch (AppwriteException e) around them failed with exception 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.of were used without imports, Client was left unterminated (; missing) when a method has no auth headers, numeric list examples used int literals for List<Double>/List<Long> params, Android array-enum params got a single enum value, and Android OAuth examples omitted the activity argument.

Static helpers. ID, Permission, Role, Query, Operator, InputFile (both SDKs) and Channel (Android) now have @JvmStatic, plus @JvmOverloads where a parameter has a default, so Java can write ID.unique() instead of ID.Companion.unique(7). Topic.path is left alone: a static path(List) would clash with the instance path(List) on the JVM.

Upload overloads. Upload methods whose parameters are all required had no @JvmOverloads, so Java had to pass onProgress explicitly. They now get the overload without it.

Default endpoint (no change). Android's Client default of https://cloud.appwrite.io/v1 comes from the spec's servers[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 throws clause), as they already do with the Kotlin SDK.

Test Plan

  • KotlinJava17Test, Android16Java17Test and Android5Java17Test now:
    • convert every generated docs/examples/java/**.md into 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 as Map.of(…), and one calls a method named enum, a Java keyword.
    • run JavaInterop.java against the mock server: ID.unique(), Permission.read(Role.any()), a caught AppwriteException from a path check, and uploadGeneric(file, Map.class, callback) inside try/catch (AppwriteException).
  • Red: against origin/main output, the Java examples fail with ';' expected and the Java class fails with cannot find symbol for ID.unique()/Permission.read/Role.any and for the uploadGeneric overload. A try/catch around Android getPresetProfile(Map.class, …) fails with exception AppwriteException is never thrown.
  • Green: vendor/bin/phpunit tests/e2e/KotlinJava17Test.php passes locally (216 assertions). The Android test sources (Tests.kt, JavaInterop.java, the 52 fixture examples) compile locally; the Docker run is left to CI.
  • Live spec: all 781 Kotlin and 191 Android Java examples compile.
  • ktlint clean on regenerated examples/kotlin and examples/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

…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.
@hansi-codes

hansi-codes Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

This 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.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 10
File Change
src/SDK/Language/Kotlin.php Corrects numeric array values in generated Kotlin/Java examples.
templates/kotlin/docs/java/example.md.twig; templates/android/docs/java/example.md.twig Makes generated Java snippets compile with imports, exception handling, valid statements, and corrected arguments.
templates/kotlin/src/main/kotlin/io/appwrite/{ID,Operator,Permission,Query,Role}.kt.twig; templates/android/library/src/main/java/io/package/{ID,Operator,Permission,Query,Role}.kt.twig Exposes helper APIs as Java static methods and adds overloads for default parameters.
templates/kotlin/src/main/kotlin/io/appwrite/models/InputFile.kt.twig; templates/android/library/src/main/java/io/package/models/InputFile.kt.twig; templates/android/library/src/main/java/io/package/Channel.kt.twig Adds Java-facing static factory methods and appropriate default-argument overloads.
templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig; templates/android/library/src/main/java/io/package/services/Service.kt.twig Adds checked-exception declarations and Java-callable upload overloads.
tests/e2e/Android16Java17Test.php; tests/e2e/Android5Java17Test.php; tests/e2e/KotlinJava17Test.php; tests/e2e/Base.php Integrates Java interop and generated-example compilation into Kotlin and Android test suites and expected output.
tests/e2e/languages/android/ChannelInterop.java; tests/e2e/languages/android/Tests.kt; tests/e2e/languages/kotlin/JavaInterop.java; tests/e2e/languages/kotlin/Tests.kt Exercises Java helper calls and Android Channel methods during the SDK end-to-end tests.
tests/e2e/languages/kotlin/java-examples.php Converts generated Java documentation examples into compilable test classes.
templates/android/library/src/main/java/io/package/Channel.kt.twig Exposes Channel factory helpers as Java static methods.
tests/e2e/languages/kotlin/JavaInterop.java Exercises selected Java helper calls, checked exceptions, and the generic upload overload.
✅ Fixed since the last review · 1
  • Add Java coverage for the new static helper surfaces · templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig:14

Reviewed the commits since d8e4d47 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

Comment thread templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig
…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.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit 2ad5f62 into main Oct 17, 2026
61 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/jvm-java-interop branch October 17, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the Kotlin and Android SDKs and their Java examples usable from Java

1 participant