Skip to content

Classes using fields from compileSdk > Platform Sdk on device cause crash when extended in TS #626

@petekanev

Description

@petekanev

Instantiating, or causing the instantiation of a class that extends another native (Android) class in TypeScript can cause a crash if the class being extended exposes public members not present on the device that runs the application.

Suppose we extend a class that introduces a new static member with Platform SDK 24, then compile the application with compileSdk 24/25, and finally install the application on a device running on API Level 23. If we attempt to create an instance of our custom class the application will crash.

Android:

class AccessibilityService {
   ...
   static int GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN = 7; // available with SDK 24+
   ...
}

TypeScript:

declare class MyAccessibilityService extends AccessibilityService { ... }

The ts_helpers script will iterate through all public properties of the class being extended, some of which may not be available on the device that runs the app, (when extending a native class) thus causing the crash.

As a workaround we may add an explicit check to make sure that the traversed fields are not specific to the android Sdk

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions