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

Feature request: Native metadata filtering for iOS and Android #5220

Closed
mbektchiev opened this issue Jan 21, 2020 · 0 comments
Closed

Feature request: Native metadata filtering for iOS and Android #5220

mbektchiev opened this issue Jan 21, 2020 · 0 comments
Assignees
Labels
Milestone

Comments

@mbektchiev
Copy link
Contributor

mbektchiev commented Jan 21, 2020

Is your feature request related to a problem? Please describe.
Currently, the whole platform SDKs and all native libraries used in a {N} app are included in the metadata binary files. To reduce app size and improve startup performance, we should allow app and plugin developers to specify which entities (e.g. Clang modules or Java packages) need to be accessible from JavaScript and omit the ones that aren't used.

Describe the solution you'd like

  1. Plugins should be able to declare their native API usage from JavaScript using a file called native-api-usage.json, located in each of its platforms directories (platforms/android or platforms/ios). Its format should be like:
{
    "uses": [
      "java.util:List"
    ]
}
  1. Apps should be able to opt-in and out of filtering for either platform, using similar specification lists in files named native-api-usage.json, located in App_Resources/Android or App_Resources/iOS:
{
   "whitelist-plugins-usages": true,
    "whitelist": [
        "java.util:Base64*"
    ],
    "blacklist": [
        "java.util:Locale*"
    ]
}

Each entry declares a pattern which is whitelisting or blacklisting a specific set of native entities. The following rules apply:

  • Entries are of the form <pattern1>[:pattern2]
  • On Android, the first pattern is matched against Java package names, while the optional second one -- against classes, interfaces, enums, etc.
  • On iOS, the first pattern is matched against Clang module/submodule names, while the optional second one -- against structs, global functions, enums, Objective-C interfaces, protocols, categories, etc.
  • Patterns support wildcards (* (any number of characters) and ? (a single character)).
  • An unspecified or empty pattern is functionally equivalent to being set to * (matching everything)
  • If the whitelist is empty, all supported metadata entities are included, except those matching at least one entry of the blacklist
  • If both lists are empty, the behavior is the same as before the implementation of this feature
  • If whitelist-plugins-usages is true, all plugins' usage specifications are automatically appended to the application's whitelist, otherwise they are ignored. If this option is not specified explicitly, it should default to false, but if there's at least one entry in the whitelist CLI should check whether all plugins specs are present in the whitelist and emit a warning stating which plugins' entries are missing.

Additional context
After following the logic of the rules, CLI should prepare a pair of lists for each of the platforms. These lists should be saved as whitelist.mdg and blacklist.mdg in both platforms/ios and platforms/android

Each line of these files should contain one entry from the JSON specs or should start with # or // and be treated as a comment.

Notice
Most of the system iOS frameworks define implicit submodules (e.g. CoreFoundation.CFData), that's why to completely include a whole module a rule such as CoreFoundation* will be needed (strictly speaking 2 rules will be needed such as CoreFoundation and CoreFoundation.* if you don't want to risk to include other modules that start with the same prefix, like an imaginary CoreFoundation2 for example)

This issue is related to: NativeScript/ios-jsc#1209 and NativeScript/android#1485

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants