Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Android api level parser to support version codenames and not just numbers #18

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/vscode-extension/src/utilities/sdkmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@ import { Logger } from "../Logger";
import { AndroidSystemImageInfo } from "../common/DeviceManager";
import { readdirSync, statSync } from "fs";
export const SYSTEM_IMAGES_PATH = path.join(ANDROID_HOME, "system-images");

const ACCEPTED_SYSTEM_IMAGES_TYPES = ["default", "google_apis_playstore", "google_apis"];

const ANDROID_CODENAMES_TO_API_LEVELS = {
s: 31,
r: 30,
q: 29,
pie: 28,
oreo: 27,
nougat: 24,
marshmallow: 23,
lollipop: 21,
kitkat: 19,
};

// Temporary solution due to sdkmanager not having information about android version.
function mapApiLevelToAndroidVersion(apiLevel: number): number | undefined {
switch (apiLevel) {
Expand Down Expand Up @@ -69,7 +82,14 @@ export async function getAndroidSystemImages(): Promise<AndroidSystemImageInfo[]
// example input: 'android-34/default/arm64-v8a/data'
function mapToSystemImageInfo(systemImagePath: string) {
const [imageName, systemImageType, arch] = systemImagePath.split("/");
const apiLevel = parseInt(imageName.split("-")[1]);
const apiLevelCode = imageName.split("-")[1];
let apiLevel = parseInt(apiLevelCode);
if (isNaN(apiLevel)) {
apiLevel =
ANDROID_CODENAMES_TO_API_LEVELS[
apiLevelCode.toLowerCase() as keyof typeof ANDROID_CODENAMES_TO_API_LEVELS
];
}
const androidVersion = mapApiLevelToAndroidVersion(apiLevel);

let apisSuffix = "";
Expand Down
Loading