Title: [Proposal] Improve workflow of extending Android classes required at runtime (e.g. Activity, Application, etc.) · Issue #465 · NativeScript/android · GitHub
Open Graph Title: [Proposal] Improve workflow of extending Android classes required at runtime (e.g. Activity, Application, etc.) · Issue #465 · NativeScript/android
X Title: [Proposal] Improve workflow of extending Android classes required at runtime (e.g. Activity, Application, etc.) · Issue #465 · NativeScript/android
Description: Overview This proposal aims to develop further the previous story of extending Android classes required at build time. At present we use a project template that is located in platforms/android directory which doesn't and shouldn't contai...
Open Graph Description: Overview This proposal aims to develop further the previous story of extending Android classes required at build time. At present we use a project template that is located in platforms/android dire...
X Description: Overview This proposal aims to develop further the previous story of extending Android classes required at build time. At present we use a project template that is located in platforms/android dire...
Opengraph URL: https://github.com/NativeScript/android/issues/465
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Proposal] Improve workflow of extending Android classes required at runtime (e.g. Activity, Application, etc.)","articleBody":"## Overview\n\nThis proposal aims to develop further the [previous story](https://github.com/NativeScript/android-runtime/issues/283) of extending Android classes required at build time. At present we use a project template that is located in `platforms/android` directory which doesn't and shouldn't contains files eligible for version control. Hence the need for this issue.\n## Proposal\n\nThere are lots of scenarios where it is required to extend Android classes used at build time. Often when using various SDKs, for example YouTube SDK, we have to extend third party types, like `Activity`, which are then used in `AndroidManifest.xml`. These types may contain application specific code and so they should be part of the app source code tree shown below\n\n```\n\u003cproj dir>\n|-app\n| |-App_Resources\n| |-Android\n| |-AndroidManifest.xml\n| |-app.gradle\n| |-...\n|-node_modules\n|-platforms\n |-android\n |-src\n | |-main\n | |-assets\n | |-java\n | |-res\n |-...\n```\n\nInstead of storing the extended classes in `platforms/android/src/main/java` directory we can adjust the directory structure as follows\n\n```\n\u003cprojdir>\n|-app\n| |-App_Resources\n| |-Android\n| | |-AndroidManifest.xml\n| | |-app.gradle\n| | |-main\n| | |-assets\n| | |-java\n| | |-res\n| |-...\n|-node_modules\n|-platforms\n |-android\n |-src\n | |-main\n | |-assets\n | |-java\n | |-res\n |-...\n```\n\nThe idea is to preserve as much of the current `gradle` folder structure so it is familiar to the Android developers and avoid NIH syndrome. The exact location can be additionally configured through `extend` syntax for JavaScript programmers or through a [decorator](https://github.com/NativeScript/NativeScript/blob/v2.0.0/ui/frame/frame.android.ts#L674) for TypeScript ones. For example\n\n```\n// MyActivity.ts\n@JavaProxy(\"com.example.MyActivity\")\nclass MyActivity extends com.google.android.youtube.player.YouTubeBaseActivity {\n...\n}\n```\n\nAnd the generated file will be stored in `\u003cprojdir>/app/App_Resources/Android/main/com/example` directory. In case when a static binding generator is used it should keep track whether the generated file is changed by the developer and prints a warning instead of overwriting the file. The usual way for doing this is to use the file last update time-stamp. It is up to the developer to resolve any potential conflicts.\n\nAs a first step we can add keep the existing `NativeScriptApplication` and `NativeScriptActivity` classes and add support for \"secondary\" activities (we keep `NativeScriptActivity` as a main one). The sole reason for this suggestion is that some changes in the tns modules are required. Please note that this step can be revisited if the aforementioned change is easy and won't require much time to implement.\n## Technical Details\n\nI outlined some of the details but here is more detailed info.\nThe default platform specific directory (`\u003cplatdir>`) is `\u003cprojdir>/app/App_Resources/Android/main`. This can be configured through the existing `settings.gradle` file.\n### When No Static Binding Generator Is Used\n- All drawables are moved to `\u003cplatdir>/res` directory\n- During build `\u003cplatdir>` is copied to `\u003cprojdir>/platforms/android/src` overwriting all existing files\n\nIn this scenario the developer has full control over both the JavaScript and Java files. There is no synchronization between the source and the destination folders, it is one-way file copy. The `tns` CLI should provide `tns clean` command so it will be possible to clean `\u003cprojdir>/platforms/android` directory.\n### When Static Binding Generator Is Used\n- All drawables are moved to `\u003cplatdir>/res` directory\n- During build `babeljs` will parse all JavaScript/TypeScript files looking for extending native classes\n- The static binding generator will use this information and writes the `*.java` files `\u003cplatdir>/java`. If a file with newer time-stamp exists then a warning will be shown and the file won't be overwritten. The `tns` CLI will provide an option (e.g. `--binding-overwrite`) in order to overwrite an existing file\n- During build `\u003cplatdir>` is copied to `\u003cprojdir>/platforms/android/src` overwriting all existing files\n## Impact\n\nThe current proposal does not have any breaking changes.\n## Summary\n\nThis proposal makes it possible to create custom non-main activities or other classes required during build time. In order to provide full ull support for main activities further change in tns modules is required.\n","author":{"url":"https://github.com/slavchev","@type":"Person","name":"slavchev"},"datePublished":"2016-05-26T08:21:52Z","url":"https://github.com/NativeScript/android/issues/465"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6660e8ba-daad-f13f-d544-598d119b05f9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CCC:2564D8:159F710:1C8EB7B:6B012C1C |
| html-safe-nonce | 6976d0136498a011058d37bc207d37d2bb788326815caf62a6c6daf0b3365055 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0NDOjI1NjREODoxNTlGNzEwOjFDOEVCN0I6NkIwMTJDMUMiLCJ2aXNpdG9yX2lkIjoiNzc3MTc0NzMwNTM0MTkyMjMzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 73714e87674548f3127c191994fc4628770ac2551741a21906264a4f74f83897 |
| hovercard-subject-tag | issue:156929652 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/android/465/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3bb21cbc1e3db700bf78c5a7b4691efd6eeb7b28e8bca774d377e567f3974826/NativeScript/android/issues/465 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3bb21cbc1e3db700bf78c5a7b4691efd6eeb7b28e8bca774d377e567f3974826/NativeScript/android/issues/465 |
| og:image:alt | Overview This proposal aims to develop further the previous story of extending Android classes required at build time. At present we use a project template that is located in platforms/android dire... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | slavchev |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/android git https://github.com/NativeScript/android.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 29137950 |
| octolytics-dimension-repository_nwo | NativeScript/android |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29137950 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/android |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width