Skip to content

Commit f226171

Browse files
isapirrigor789
andauthored
feat: document adding Java/Kotlin to App_Resources (#77)
Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
1 parent 53c831f commit f226171

File tree

2 files changed

+81
-8
lines changed

2 files changed

+81
-8
lines changed

app-resources.md

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ title: App_Resources
44

55
# Understanding App_Resources
66

7-
This page serves as a quick reference to understand how most settings in App_Resources affect the look of a NativeScript app.
7+
The App_Resources folder contains platform-specific resources of the application (icons, configuration files, native code, etc.). An application that supports both Android and iOS would therefore contain a subfolder for each platform.
8+
9+
This page serves as a quick reference to understand how most settings in App_Resources affect behavior and the the look of a NativeScript app.
810

911
**Quick Links:**
1012
[[toc]]
@@ -21,15 +23,86 @@ Here we are showing the default look of a few elements (no custom styling applie
2123

2224
```bash
2325
App_Resources/
24-
|- Android
25-
|- src/main/res
26-
|- values # Default Values
27-
|- values-v21 # Values for API 21+
28-
|- values-v29 # Values for API 29+
26+
├─ Android/
27+
│ └─ src/main/res/
28+
│ ├─ values/ # Default Values
29+
│ ├─ values-v21/ # Values for API 21+
30+
│ └─ values-v29/ # Values for API 29+
31+
└─ ... more
2932
```
3033

3134
Values can be overriden on specific API levels by making the changes in the corresponding directories.
3235

36+
### Adding native code to an application
37+
38+
There are different ways to add native code to an Android application. You can add Java JAR files or Java and/or Kotlin source files in `App_Resources/Android/libs` and `App_Resources/Android/src` respectively, e.g.:
39+
40+
```bash
41+
App_Resources/
42+
├─ Android/
43+
│ ├─ app.gradle
44+
│ ├─ libs/
45+
│ │ ├─ HelloAndroidLib.aar # Android ARchive
46+
│ │ └─ HelloJavaLib.jar # Java ARchive
47+
│ └─ src/
48+
│ └─ main/
49+
│ ├─ java/
50+
│ │ ├─ com/example/HelloKotlin.kt # Kotlin source code
51+
│ │ └─ com/example/HelloJava.java # Java source code
52+
│ └─ res/
53+
└─ ... more
54+
```
55+
56+
<!-- -->
57+
58+
<!-- tab: Kotlin -->
59+
60+
```kt
61+
// HelloKotlin.kt
62+
package com.example
63+
64+
class HelloKotlin {
65+
val hello = "Hello from Kotlin!"
66+
}
67+
```
68+
69+
<!-- tab: Java -->
70+
71+
```java
72+
// HelloJava.java
73+
package com.example
74+
75+
class HelloJava {
76+
public String getString() {
77+
return "Hello from Java!";
78+
}
79+
}
80+
```
81+
82+
Given the example above, your JavaScript or TypeScript code can reference the Kotlin or Java code by using the full class names, e.g.
83+
84+
```typescript
85+
const helloKotlin = new com.example.HelloKotlin()
86+
console.log('Kotlin says: ' + helloKotlin.hello)
87+
// prints: Kotlin says: Hello from Kotlin!
88+
89+
const helloJava = new com.example.HelloJava()
90+
console.log('Java says: ' + helloJava.getString())
91+
// prints: Java says: Hello from Java!
92+
```
93+
94+
:::tip Note
95+
96+
If using TypeScript, you may need to generate typings, or alternatively declare the top level package name as `any`, e.g.
97+
98+
```typescript
99+
declare const com: any
100+
```
101+
102+
:::
103+
104+
If using Kotlin source files, `useKotlin` should be enabled in `before-plugins.gradle` or `app.gradle`
105+
33106
### Setting the default color of the ActionBar
34107
35108
To change the default color fo the ActionBar, edit the `ns_primary` color inside `App_Resources/Android/src/main/res/values/colors.xml`:

development-workflow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,12 @@ Follow the official documentation on [Creating and Managing Virtual Devices](htt
232232
233233
#### Creating Android Virtual Device via command line tool
234234
235-
The `avdmanager` is a tool that allows you to create and manage Android Virtual Devices (AVDs) from the command line. The `avdmanager` is provided in the Android SDK Tools package (25.3.0 and higher) and is located in `<ANDROID_HOME_PATH_HERE>/tools/bin/`. For more information about the avdmanager and how to use it to create AVDs, see the [official avdmanager documentation](https://developer.android.com/studio/command-line/avdmanager.html).
235+
The `avdmanager` is a tool that allows you to create and manage Android Virtual Devices (AVDs) from the command line. The `avdmanager` is provided in the Android SDK Tools package (25.3.0 and higher) and is located in `<ANDROID_HOME_PATH_HERE>/cmdline-tools/latest/bin/`. For more information about the avdmanager and how to use it to create AVDs, see the [official avdmanager documentation](https://developer.android.com/studio/command-line/avdmanager).
236236
237237
Command syntax to create new AVD
238238
239239
```cli
240-
cd $ANDROID_HOME/tools/bin
240+
cd $ANDROID_HOME/cmdline-tools/latest/bin
241241
avdmanager create avd -n name -k "sdk_id" [-c {path|size}] [-f] [-p path]
242242
```
243243

0 commit comments

Comments
 (0)