You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generating the typings corresponding to the android and android-support jar files is a bit tricky operation, so here's a detailed explanation how to do it.
53
+
There are different andoid support versions and they depend on main android classes it is a little bit complicated to generate those typings. One option is to generate a big **d.ts** file with all the libraries inside. The downside of this approach is that you have to generate a big file for every API level and if the android support version is changed all those **d.ts** files need to be regenerated.
54
+
To avoid this there's some functionality in the tool for passing dependencies when generating typings.
55
+
There are two type of dependencies that can be passed:
56
+
57
+
1. Super class jars - this is needed when the current jar has classes which are extending classes from another jar file, but we don't want to have all that jar files' typings in a single output file. To achieve this we can provide the super class jar with the **super** argument(which works the same way as **input** for multiple files).
58
+
For instance if we want to generate typings for **android.support.v4.view.ViewPager** and we don't pass the super classes jar the generated typings won't extend any class as there's no information in the jar that contains the ViewPager. However this class extends **android.view.ViewGroup** class which is a part of the android jar file(any of the API levels). So if we pass one of the android.jar files as a super class jar file the generated typing will contain `extends android.view.ViewGroup`.
59
+
2. Input generics - When trying to get the type of a parameter which is a generic class we cannot really get the generic types of that class, so we cannot generate working typings. To fix this we are adding information about the generics of each package at the end of the file with comments starting with `//Generics information:`.
60
+
So to fix this we need to provide a file with all the generic information for the packages the current jar relies on. You need to create a file and copy all the generic informations of the related packages and provide it in the **input-generics** argument. This will make all the generic classes referenced without passing types to pass **any** so that the ouput will be valid.
61
+
62
+
## Adding all implements for generic types
63
+
There is an option **all-generic-implements** which is disabled by default which controls whether to add implements for all interfaces (if they are more than one) to generic type declarations. The problem is that in most of the cases one of those interfaces is actually an extend, so it should be manual reviewed and fixed after generation.
64
+
65
+
## Finding package dependencies
66
+
If you want to generate typings of a package but you are not sure how you can get all the needed dependencies you can follow the steps bellow:
67
+
68
+
1. Open [dts-generator/build.gradle](dts-generator/build.gradle) file and locate `dependencies` part.
69
+
2. Add as a `testCompileOnly` dependency the one that you want to generate typings for:
3. Open the [dts-generator](dts-generator) folder in your terminal
83
+
4. Run the following command:
84
+
85
+
```
86
+
./gradlew extractAllJars
87
+
```
88
+
89
+
5. The command above will get the needed jar files for your dependency and will output them in the [dts-generator/jar-files](dts-generator/jar-files) folder (or you can optionaly pass another output folder `-PjarsOutput=another-folder`)
90
+
6. You can run the following command to check what are the dependencies between the packages:
7. Run the dts-generator tool passing as **input** arguments the path to the output jars folder
97
+
98
+
## Android support specifics
99
+
To get all the jar files for android support follow the steps above. You can find the **jar** files for android support 27.0.1 in [the current repository](libs/android-support/27.0.1)
100
+
As the android support needs the base android jar file to create its typings you need to pass the android.jar file as a **super** parameter to the generator. To avoid having typings for every different API level you can reuse typings built with API level 17 for all API levels until 23. It's quite easy to test this:
101
+
102
+
1. Run the typings generator for android support passing **android-17/android.jar** as a supper jar
103
+
2. Add `/// <reference path="android-17.d.ts"/>` at the top of the generated typings file where android-17.d.ts is the typings file of the android API level 17
104
+
3. Run `tsc` passing the generated typings file and there shouldn't be errors
105
+
4. Now start replacing the reference file with the files from other API level while the `tsc` execution completes with no error
106
+
5. If there's an error this means that you need to generate the android support typings with the same android API level super jar
107
+
108
+
By repeating the steps above we've found that:
109
+
110
+
- Android support 17 typings(built with supper jar from android API 17) can be reused until android API 22
111
+
- Android support 23 typings(built with supper jar from android API 23) can be reused until android API 25
112
+
- Android support 26 typings(built with supper jar from android API 26) can be reused for API 26 and 27
113
+
114
+
The corresponding typings files can be found in the [tns-platform-declarations](https://github.com/NativeScript/NativeScript/tree/master/tns-platform-declarations) package. The repo's [Makefile](Makefile) can be used as a reference for creating these typings files
0 commit comments