{"action":"closed","issue":{"url":"https://api.github.com/repos/NativeScript/android-runtime/issues/465","repository_url":"https://api.github.com/repos/NativeScript/android-runtime","labels_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/465/labels{/name}","comments_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/465/comments","events_url":"https://api.github.com/repos/NativeScript/android-runtime/issues/465/events","html_url":"https://github.com/NativeScript/android-runtime/issues/465","id":156929652,"number":465,"title":"[Proposal] Improve workflow of extending Android classes required at runtime (e.g. Activity, Application, etc.)","user":{"login":"slavchev","id":3962815,"avatar_url":"https://avatars.githubusercontent.com/u/3962815?v=3","gravatar_id":"","url":"https://api.github.com/users/slavchev","html_url":"https://github.com/slavchev","followers_url":"https://api.github.com/users/slavchev/followers","following_url":"https://api.github.com/users/slavchev/following{/other_user}","gists_url":"https://api.github.com/users/slavchev/gists{/gist_id}","starred_url":"https://api.github.com/users/slavchev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slavchev/subscriptions","organizations_url":"https://api.github.com/users/slavchev/orgs","repos_url":"https://api.github.com/users/slavchev/repos","events_url":"https://api.github.com/users/slavchev/events{/privacy}","received_events_url":"https://api.github.com/users/slavchev/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NativeScript/android-runtime/labels/3%20-%20In%20Progress","name":"3 - In Progress","color":"c7def8"},{"url":"https://api.github.com/repos/NativeScript/android-runtime/labels/T:Feature","name":"T:Feature","color":"bfe5bf"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/NativeScript/android-runtime/milestones/20","html_url":"https://github.com/NativeScript/android-runtime/milestones/2.4.0","labels_url":"https://api.github.com/repos/NativeScript/android-runtime/milestones/20/labels","id":2013432,"number":20,"title":"2.4.0","description":"","creator":{"login":"slavchev","id":3962815,"avatar_url":"https://avatars.githubusercontent.com/u/3962815?v=3","gravatar_id":"","url":"https://api.github.com/users/slavchev","html_url":"https://github.com/slavchev","followers_url":"https://api.github.com/users/slavchev/followers","following_url":"https://api.github.com/users/slavchev/following{/other_user}","gists_url":"https://api.github.com/users/slavchev/gists{/gist_id}","starred_url":"https://api.github.com/users/slavchev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slavchev/subscriptions","organizations_url":"https://api.github.com/users/slavchev/orgs","repos_url":"https://api.github.com/users/slavchev/repos","events_url":"https://api.github.com/users/slavchev/events{/privacy}","received_events_url":"https://api.github.com/users/slavchev/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":1,"state":"open","created_at":"2016-09-19T11:42:13Z","updated_at":"2016-09-20T07:45:10Z","due_on":"2016-11-02T00:00:00Z","closed_at":null},"comments":3,"created_at":"2016-05-26T08:21:52Z","updated_at":"2016-09-20T07:45:10Z","closed_at":"2016-09-20T07:45:10Z","body":"## Overview\r\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.\r\n## Proposal\r\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\r\n```\r\n<proj dir>\r\n|-app\r\n|  |-App_Resources\r\n|     |-Android\r\n|       |-AndroidManifest.xml\r\n|       |-app.gradle\r\n|       |-...\r\n|-node_modules\r\n|-platforms\r\n    |-android\r\n       |-src\r\n       | |-main\r\n       |   |-assets\r\n       |   |-java\r\n       |   |-res\r\n       |-...\r\n```\r\nInstead of storing the extended classes in `platforms/android/src/main/java` directory we can adjust the directory structure as follows\r\n```\r\n<projdir>\r\n|-app\r\n|  |-App_Resources\r\n|     |-Android\r\n|     | |-AndroidManifest.xml\r\n|     | |-app.gradle\r\n|     | |-main\r\n|     |   |-assets\r\n|     |   |-java\r\n|     |   |-res\r\n|     |-...\r\n|-node_modules\r\n|-platforms\r\n    |-android\r\n       |-src\r\n       | |-main\r\n       |   |-assets\r\n       |   |-java\r\n       |   |-res\r\n       |-...\r\n```\r\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\r\n```\r\n// MyActivity.ts\r\n@JavaProxy(\"com.example.MyActivity\")\r\nclass MyActivity extends com.google.android.youtube.player.YouTubeBaseActivity {\r\n...\r\n}\r\n```\r\nAnd the generated file will be stored in `<projdir>/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.\r\n\r\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.\r\n\r\n## Technical Details\r\nI outlined some of the details but here is more detailed info.\r\nThe default platform specific directory (`<platdir>`) is  `<projdir>/app/App_Resources/Android/main`. This can be configured through the existing `settings.gradle` file.\r\n### When No Static Binding Generator Is Used\r\n* All drawables are moved to `<platdir>/res` directory\r\n* During build `<platdir>` is copied to `<projdir>/platforms/android/src` overwriting all existing files\r\n\r\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 `<projdir>/platforms/android` directory.\r\n\r\n### When Static Binding Generator Is Used\r\n* All drawables are moved to `<platdir>/res` directory\r\n* During build `babeljs` will parse all JavaScript/TypeScript files looking for extending native classes\r\n* The static binding generator will use this information and writes the `*.java` files `<platdir>/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\r\n* During build `<platdir>` is copied to `<projdir>/platforms/android/src` overwriting all existing files\r\n\r\n## Impact\r\nThe current proposal does not have any breaking changes.\r\n\r\n## Summary\r\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."}}
{"actor":{"display_login":"atanasovg"}}