Skip to content

fix(unity): register the Android OAuth callback at build time - #2089

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/unity-android-oauth-manifest
Oct 17, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/unity-android-oauth-manifest

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

The Unity package shipped Runtime/Core/Plugins/Android/AndroidManifest.xml with the literal scheme appwrite-callback-<YOUR_PROJECT_ID>. A package installed from a git URL is read-only, so the placeholder could never be filled in and OAuth on Android never returned to the app. The manifest also redeclared UnityPlayerActivity with the launcher intent filter, which competes with the project's own main manifest (and with the GameActivity entry point on Unity 2023+).

This PR removes that manifest and adds an Editor build processor (AppwriteAndroidManifestProcessor, an IPostGenerateGradleAndroidProject). When an Android Gradle project is generated, it reads the projectId of every AppwriteConfig asset and appends a VIEW/DEFAULT/BROWSABLE intent filter for appwrite-callback-<projectId> to the Unity activity in unityLibrary/src/main/AndroidManifest.xml (found by its unityplayer.UnityActivity meta-data or launcher category), skipping schemes that are already declared. I picked this over a package manifest with placeholders because it needs no edits to package files, it uses Unity's own merged manifest instead of competing with it, the API is available from Unity 2021.3 through Unity 6, and it does not need the Android module unless the build target is Android (the file is guarded by UNITY_ANDROID). The config is read through SerializedObject, so the Editor assembly takes no compile-time dependency on the runtime assembly, matching how the setup window already calls into it.

When no config with a project ID exists (clients created in code), the processor logs how to add the filter, and the README gains an "OAuth on Android" section describing the custom main manifest route.

The Unity setup window's Documentation button opened sdk.url (the generator's homepage URL, https://example.com in generated examples) and the Discord button a hardcoded invite. Documentation now opens the SDK README on GitHub (appwrite.io has no Unity quick start; /docs/quick-starts/unity falls back to the overview page), and Discord uses sdk.discordUrl, hidden when unset.

Client.From defaulting to {{ spec | endpoint }} is unchanged: every client SDK (Web, Node, React Native, Dart, Flutter, Swift, Apple, Kotlin, Android, .NET, Go, Python, Ruby, PHP, Rust) defaults its endpoint to the same spec server URL.

Test Plan

  • New GenerationTest cases: the Unity tree contains no AndroidManifest.xml, no non-docs file carries a <YOUR_PROJECT_ID> placeholder, the build processor registers the same appwrite-callback- prefix that WebAuthComponent waits for, and the setup window opens the README and no fixed Discord invite. Both fail on main and pass here.
  • vendor/bin/phpunit --testsuite Generation: 112 tests pass.
  • Compiled the generated processor with UNITY_ANDROID defined against Unity 6000.4's UnityEditor.CoreModule/UnityEngine.CoreModule, and ran its XML transform on a sample Unity library manifest: the intent filter lands on UnityPlayerActivity with the android: prefix.
  • php example.php unity client then dotnet format whitespace --folder --verify-no-changes in examples/unity, composer lint-twig, composer refactor:check, composer lint, and the 1200-character Twig line check all pass.

Related PRs and Issues

None.

Closes #2092

The package shipped Plugins/Android/AndroidManifest.xml with the literal scheme appwrite-callback-<YOUR_PROJECT_ID>. A package installed from a git URL is read-only, so the scheme could never be filled in and OAuth on Android never returned to the app; the manifest also redeclared the launcher activity, competing with the project's own main manifest.

An Editor IPostGenerateGradleAndroidProject processor now adds the intent filter to the Unity activity of the generated Gradle project, using the project ID of each AppwriteConfig asset, which works with Unity's manifest merging and needs no edits to package files. The README documents the custom main manifest route for clients created in code.

The setup window's Documentation button opened sdk.url (the generator's homepage URL) and its Discord button a fixed invite; they now open the SDK README and sdk.discordUrl.
@hansi-codes

hansi-codes Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

This change replaces the packaged Android manifest with a generated Unity Editor build processor that adds OAuth callback schemes from configuration assets, and documents the custom-manifest option for code-created clients. It also updates the setup window’s documentation and Discord links and adds Unity generation tests.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
src/SDK/Language/Unity.php Removes the packaged Android manifest and registers the new Editor processor template.
templates/unity/Assets/Editor/AppwriteAndroidManifestProcessor.cs.twig Adds build-time manifest editing for configured OAuth callback schemes.
templates/unity/Assets/Editor/AppwriteSetupWindow.cs.twig Updates the documentation link and uses the configured Discord URL.
templates/unity/README.md.twig Documents Android OAuth callback registration and the custom-manifest route.
templates/unity/Assets/Runtime/Core/Plugins/Android/AndroidManifest.xml.twig Deletes the manifest containing the unfillable project ID placeholder.
tests/generation/GenerationTest.php Checks Unity’s generated tree and setup-window links.
🔇 Filtered out · 1

Findings Hansi considered but did not post.

Finding Why
The Android processor is excluded from Editor compilation Verifier: The premise is incorrect: Unity defines target-platform symbols, including UNITY_ANDROID, during Editor compilation when Android is the active build target. UNITY_EDITOR and UNITY_ANDROID can both be defined. The Editor-only asmdef does not suppress target-platform symbols, and the processor is registered in Unity.getFiles(). Thus the guard permits this callback to compile for Android builds; it only excludes it when a different target is active. Unity's scripting-symbol reference confirms that platform symbols depend on the authoring and build-target platforms.

Reviewed 390e80f · 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 S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit 622e64c into main Oct 17, 2026
61 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/unity-android-oauth-manifest branch October 17, 2026 10:03
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.

Register the Unity Android OAuth callback at build time

1 participant