Skip to content

Commit c7fb232

Browse files
add android version fetching
1 parent 8b25d4f commit c7fb232

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/routes/(console)/project-[region]-[project]/overview/platforms/createAndroid.svelte

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@
3636
let isPlatformCreated = $state(isConnectPlatform);
3737
3838
const projectId = page.params.project;
39+
const ANDROID_RELEASES_ENDPOINT =
40+
'https://api.github.com/repos/appwrite/sdk-for-android/releases';
41+
let androidSdkVersion = $state('11.3.0');
3942
40-
const alreadyExistsInstructions = `
43+
function buildAndroidInstructions(version: string) {
44+
return `
4145
Confirm you're working inside the correct Android project before editing anything:
4246
- Navigate into the directory that contains the real Android app module (look for gradlew, settings.gradle, and the app-level build.gradle(.kts)).
4347
- If Cursor opens in a parent folder (like your home directory) or you see multiple Android projects, ask which one to modify before making changes.
@@ -47,7 +51,7 @@ Prefer Version Catalogs when adding the Appwrite SDK:
4751
1. If ./gradle/libs.versions.toml exists, add or reuse an Appwrite entry:
4852
\`\`\`toml
4953
[libraries]
50-
appwrite = { module = "io.appwrite:sdk-for-android", version = "11.3.0" }
54+
appwrite = { module = "io.appwrite:sdk-for-android", version = "${version}" }
5155
\`\`\`
5256
2. Reference it inside the module's dependencies block:
5357
\`\`\`kotlin
@@ -57,11 +61,11 @@ dependencies {
5761
\`\`\`
5862
Only when the project lacks ./gradle/libs.versions.toml should you hardcode the dependency:
5963
\`\`\`kotlin
60-
implementation("io.appwrite:sdk-for-android:11.3.0")
64+
implementation("io.appwrite:sdk-for-android:${version}")
6165
\`\`\`
6266
Legacy Groovy scripts should use:
6367
\`\`\`groovy
64-
implementation "io.appwrite:sdk-for-android:11.3.0"
68+
implementation "io.appwrite:sdk-for-android:${version}"
6569
\`\`\`
6670
6771
Before introducing any new files, search the project (app/src, libs/, shared modules, etc.) for existing Appwrite client helpers (look for \`Client(\`, \`AppwriteClient\`, or \`.setEndpoint\`). If a client already exists, update its configuration instead of creating a duplicate.
@@ -80,6 +84,9 @@ From the app's entry point (e.g., Application class or the first launched Activi
8084
client.ping()
8185
\`\`\`
8286
`;
87+
}
88+
89+
const alreadyExistsInstructions = $derived(buildAndroidInstructions(androidSdkVersion));
8390
8491
const gitCloneCode =
8592
'\ngit clone https://github.com/appwrite/starter-for-android\ncd starter-for-android\n';
@@ -88,6 +95,22 @@ client.ping()
8895
const val APPWRITE_PROJECT_NAME = "${$project.name}"
8996
const val APPWRITE_PUBLIC_ENDPOINT = "${sdk.forProject(page.params.region, page.params.project).client.config.endpoint}"`;
9097
98+
async function fetchAndroidSdkVersion() {
99+
try {
100+
const response = await fetch(ANDROID_RELEASES_ENDPOINT);
101+
if (!response.ok) {
102+
throw new Error(`Failed to fetch Android SDK releases: ${response.status}`);
103+
}
104+
const data = await response.json();
105+
const latestTag = data?.[0]?.tag_name;
106+
if (latestTag) {
107+
androidSdkVersion = latestTag;
108+
}
109+
} catch (error) {
110+
console.error('Unable to fetch latest Android SDK version', error);
111+
}
112+
}
113+
91114
async function createAndroidPlatform() {
92115
try {
93116
isCreatingPlatform = true;
@@ -128,6 +151,7 @@ const val APPWRITE_PUBLIC_ENDPOINT = "${sdk.forProject(page.params.region, page.
128151
}
129152
130153
onMount(() => {
154+
fetchAndroidSdkVersion();
131155
const unsubscribe = realtime.forConsole(page.params.region, 'console', (response) => {
132156
if (response.events.includes(`projects.${projectId}.ping`)) {
133157
connectionSuccessful = true;

0 commit comments

Comments
 (0)