Skip to content
This repository was archived by the owner on Feb 19, 2023. It is now read-only.

Commit 8e947e5

Browse files
authored
Support non-integer API level (ReactiveCircus#317)
* Support non-integer API level * update lib * Add test * No need to install platforms. Mostly application will use different SDK platform. * Update lib
1 parent e1248ae commit 8e947e5

8 files changed

+19
-10
lines changed

__tests__/input-validator.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ describe('api-level validator tests', () => {
3232
validator.checkApiLevel('29');
3333
};
3434
expect(func2).not.toThrow();
35+
const func3 = () => {
36+
validator.checkApiLevel('UpsideDownCake-ext5');
37+
};
38+
expect(func3).not.toThrow();
39+
const func4 = () => {
40+
validator.checkApiLevel('TiramisuPrivacySandbox');
41+
};
42+
expect(func4).not.toThrow();
3543
});
3644
});
3745

lib/input-validator.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ exports.VALID_TARGETS = ['default', 'google_apis', 'aosp_atd', 'google_atd', 'go
66
exports.VALID_ARCHS = ['x86', 'x86_64', 'arm64-v8a'];
77
exports.VALID_CHANNELS = ['stable', 'beta', 'dev', 'canary'];
88
function checkApiLevel(apiLevel) {
9+
if (apiLevel.startsWith('UpsideDownCake') || apiLevel === 'TiramisuPrivacySandbox')
10+
return;
911
if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) {
1012
throw new Error(`Unexpected API level: '${apiLevel}'.`);
1113
}

lib/main.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ function run() {
6161
}
6262
}
6363
// API level of the platform and system image
64-
const apiLevelInput = core.getInput('api-level', { required: true });
65-
(0, input_validator_1.checkApiLevel)(apiLevelInput);
66-
const apiLevel = Number(apiLevelInput);
64+
const apiLevel = core.getInput('api-level', { required: true });
65+
(0, input_validator_1.checkApiLevel)(apiLevel);
6766
console.log(`API level: ${apiLevel}`);
6867
// target of the system image
6968
const targetInput = core.getInput('target');

lib/sdk-installer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndk
6868
// accept all Android SDK licenses
6969
yield exec.exec(`sh -c \\"yes | sdkmanager --licenses > /dev/null"`);
7070
console.log('Installing latest build tools, platform tools, and platform.');
71-
yield exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
71+
yield exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools > /dev/null"`);
7272
console.log('Installing latest emulator.');
7373
yield exec.exec(`sh -c \\"sdkmanager --install emulator --channel=${channelId} > /dev/null"`);
7474
if (emulatorBuild) {

src/emulator-manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
77
* Creates and launches a new AVD instance with the specified configurations.
88
*/
99
export async function launchEmulator(
10-
apiLevel: number,
10+
apiLevel: string,
1111
target: string,
1212
arch: string,
1313
profile: string,

src/input-validator.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const VALID_ARCHS: Array<string> = ['x86', 'x86_64', 'arm64-v8a'];
44
export const VALID_CHANNELS: Array<string> = ['stable', 'beta', 'dev', 'canary'];
55

66
export function checkApiLevel(apiLevel: string): void {
7+
if (apiLevel.startsWith('UpsideDownCake') || apiLevel === 'TiramisuPrivacySandbox') return;
78
if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) {
89
throw new Error(`Unexpected API level: '${apiLevel}'.`);
910
}

src/main.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ async function run() {
4040
}
4141

4242
// API level of the platform and system image
43-
const apiLevelInput = core.getInput('api-level', { required: true });
44-
checkApiLevel(apiLevelInput);
45-
const apiLevel = Number(apiLevelInput);
43+
const apiLevel = core.getInput('api-level', { required: true });
44+
checkApiLevel(apiLevel);
4645
console.log(`API level: ${apiLevel}`);
4746

4847
// target of the system image

src/sdk-installer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/comman
1212
* Installs & updates the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator,
1313
* and the system image for the chosen API level, CPU arch, and target.
1414
*/
15-
export async function installAndroidSdk(apiLevel: number, target: string, arch: string, channelId: number, emulatorBuild?: string, ndkVersion?: string, cmakeVersion?: string): Promise<void> {
15+
export async function installAndroidSdk(apiLevel: string, target: string, arch: string, channelId: number, emulatorBuild?: string, ndkVersion?: string, cmakeVersion?: string): Promise<void> {
1616
try {
1717
console.log(`::group::Install Android SDK`);
1818
const isOnMac = process.platform === 'darwin';
@@ -41,7 +41,7 @@ export async function installAndroidSdk(apiLevel: number, target: string, arch:
4141

4242
console.log('Installing latest build tools, platform tools, and platform.');
4343

44-
await exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
44+
await exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools > /dev/null"`);
4545

4646
console.log('Installing latest emulator.');
4747
await exec.exec(`sh -c \\"sdkmanager --install emulator --channel=${channelId} > /dev/null"`);

0 commit comments

Comments
 (0)