-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Proposal] Improve workflow of extending Android classes required at runtime (e.g. Activity, Application, etc.) #465
Comments
After some thorough internal discussions, we've decided to follow the JavaScript-first approach. That is to enable such scenarios from JavaScript where/when possible. For 2.1 we made some refactoring in the core modules and their behavior is now easily controllable through custom Application/Activity extends. For more information please refer to this article: |
It might be a good idea to follow the gradle project structure, as mentioned in the proposal, to avoid complicated logic on CLI side when copying resources. This will also help with declaring and controlling xml files, that are currently not the subject of change. Currently, because of the style.xml file we can't build with lower api level than 21. Example of these files: everything in: |
Closing the issue, @Plamen5kov's comment moved as a separate issue. |
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 contains files eligible for version control. Hence the need for this issue.Proposal
There 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 inAndroidManifest.xml
. These types may contain application specific code and so they should be part of the app source code tree shown belowInstead of storing the extended classes in
platforms/android/src/main/java
directory we can adjust the directory structure as followsThe 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 throughextend
syntax for JavaScript programmers or through a decorator for TypeScript ones. For exampleAnd 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.As a first step we can add keep the existing
NativeScriptApplication
andNativeScriptActivity
classes and add support for "secondary" activities (we keepNativeScriptActivity
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.Technical Details
I outlined some of the details but here is more detailed info.
The default platform specific directory (
<platdir>
) is<projdir>/app/App_Resources/Android/main
. This can be configured through the existingsettings.gradle
file.When No Static Binding Generator Is Used
<platdir>/res
directory<platdir>
is copied to<projdir>/platforms/android/src
overwriting all existing filesIn 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 providetns clean
command so it will be possible to clean<projdir>/platforms/android
directory.When Static Binding Generator Is Used
<platdir>/res
directorybabeljs
will parse all JavaScript/TypeScript files looking for extending native classes*.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. Thetns
CLI will provide an option (e.g.--binding-overwrite
) in order to overwrite an existing file<platdir>
is copied to<projdir>/platforms/android/src
overwriting all existing filesImpact
The current proposal does not have any breaking changes.
Summary
This 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.
The text was updated successfully, but these errors were encountered: