Skip to content

Commit 0b0ae9b

Browse files
authored
docs: add Kotlin Gradle plugin in build.gradle (#3711)
1 parent aba3a88 commit 0b0ae9b

File tree

6 files changed

+289
-1
lines changed

6 files changed

+289
-1
lines changed

docs/the-new-architecture/pillars-fabric-components.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,51 @@ android
239239

240240
First, create a `build.gradle` file in the `android` folder, with the following contents:
241241

242+
<Tabs groupId="android-language" queryString defaultValue={constants.defaultAndroidLanguage} values={constants.androidLanguages}>
243+
<TabItem value="java">
244+
245+
```java title="build.gradle"
246+
buildscript {
247+
ext.safeExtGet = {prop, fallback ->
248+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
249+
}
250+
repositories {
251+
google()
252+
gradlePluginPortal()
253+
}
254+
dependencies {
255+
classpath("com.android.tools.build:gradle:7.3.1")
256+
}
257+
}
258+
259+
apply plugin: 'com.android.library'
260+
apply plugin: 'com.facebook.react'
261+
262+
android {
263+
compileSdkVersion safeExtGet('compileSdkVersion', 33)
264+
namespace "com.rtncenteredtext"
265+
266+
defaultConfig {
267+
minSdkVersion safeExtGet('minSdkVersion', 21)
268+
targetSdkVersion safeExtGet('targetSdkVersion', 33)
269+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true")
270+
}
271+
}
272+
273+
repositories {
274+
mavenCentral()
275+
google()
276+
}
277+
278+
dependencies {
279+
implementation 'com.facebook.react:react-native'
280+
}
281+
```
282+
283+
</TabItem>
284+
285+
<TabItem value="kotlin">
286+
242287
```kotlin title="build.gradle"
243288
buildscript {
244289
ext.safeExtGet = {prop, fallback ->
@@ -250,11 +295,13 @@ buildscript {
250295
}
251296
dependencies {
252297
classpath("com.android.tools.build:gradle:7.3.1")
298+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.22")
253299
}
254300
}
255301

256302
apply plugin: 'com.android.library'
257303
apply plugin: 'com.facebook.react'
304+
apply plugin: 'org.jetbrains.kotlin.android'
258305

259306
android {
260307
compileSdkVersion safeExtGet('compileSdkVersion', 33)
@@ -277,6 +324,9 @@ dependencies {
277324
}
278325
```
279326

327+
</TabItem>
328+
</Tabs>
329+
280330
#### The `ReactPackage` class
281331

282332
Then, you need a class that implements the `ReactPackage` interface. To run the **Codegen** process, you don't have to completely implement the Package class: an empty implementation is enough for the app to pick up the module as a proper React Native dependency and to try and generate the scaffolding code.

docs/the-new-architecture/pillars-turbomodule.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,45 @@ android
231231
232232
First, create a `build.gradle` file in the `android` folder, with the following contents:
233233
234+
<Tabs groupId="android-language" queryString defaultValue={constants.defaultAndroidLanguage} values={constants.androidLanguages}>
235+
<TabItem value="java">
236+
237+
```java title="build.gradle"
238+
buildscript {
239+
ext.safeExtGet = {prop, fallback ->
240+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
241+
}
242+
repositories {
243+
google()
244+
gradlePluginPortal()
245+
}
246+
dependencies {
247+
classpath("com.android.tools.build:gradle:7.3.1")
248+
}
249+
}
250+
251+
apply plugin: 'com.android.library'
252+
apply plugin: 'com.facebook.react'
253+
254+
android {
255+
compileSdkVersion safeExtGet('compileSdkVersion', 33)
256+
namespace "com.rtncalculator"
257+
}
258+
259+
repositories {
260+
mavenCentral()
261+
google()
262+
}
263+
264+
dependencies {
265+
implementation 'com.facebook.react:react-native'
266+
}
267+
```
268+
269+
</TabItem>
270+
271+
<TabItem value="kotlin">
272+
234273
```kotlin title="build.gradle"
235274
buildscript {
236275
ext.safeExtGet = {prop, fallback ->
@@ -242,11 +281,13 @@ buildscript {
242281
}
243282
dependencies {
244283
classpath("com.android.tools.build:gradle:7.3.1")
284+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.22")
245285
}
246286
}
247287

248288
apply plugin: 'com.android.library'
249289
apply plugin: 'com.facebook.react'
290+
apply plugin: 'org.jetbrains.kotlin.android'
250291

251292
android {
252293
compileSdkVersion safeExtGet('compileSdkVersion', 33)
@@ -263,6 +304,9 @@ dependencies {
263304
}
264305
```
265306
307+
</TabItem>
308+
</Tabs>
309+
266310
#### The `ReactPackage` class
267311
268312
Then, you need a class that extends the `TurboReactPackage` interface. To run the **Codegen** process, you don't have to completely implement the package class: an empty implementation is enough for the app to pick up the module as a proper React Native dependency and to try and generate the scaffolding code.

website/versioned_docs/version-0.70/the-new-architecture/pillars-fabric-components.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,54 @@ android
255255

256256
First, create a `build.gradle` file in the `android` folder, with the following contents:
257257

258+
<Tabs groupId="android-language" queryString defaultValue={constants.defaultAndroidLanguage} values={constants.androidLanguages}>
259+
<TabItem value="java">
260+
261+
```java title="build.gradle"
262+
buildscript {
263+
ext.safeExtGet = {prop, fallback ->
264+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
265+
}
266+
repositories {
267+
google()
268+
gradlePluginPortal()
269+
}
270+
dependencies {
271+
classpath("com.android.tools.build:gradle:7.3.1")
272+
}
273+
}
274+
275+
apply plugin: 'com.android.library'
276+
apply plugin: 'com.facebook.react'
277+
278+
android {
279+
compileSdkVersion safeExtGet('compileSdkVersion', 31)
280+
281+
defaultConfig {
282+
minSdkVersion safeExtGet('minSdkVersion', 21)
283+
targetSdkVersion safeExtGet('targetSdkVersion', 31)
284+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true")
285+
}
286+
}
287+
288+
repositories {
289+
maven {
290+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
291+
url "$projectDir/../node_modules/react-native/android"
292+
}
293+
mavenCentral()
294+
google()
295+
}
296+
297+
dependencies {
298+
implementation 'com.facebook.react:react-native:+'
299+
}
300+
```
301+
302+
</TabItem>
303+
304+
<TabItem value="kotlin">
305+
258306
```kotlin title="build.gradle"
259307
buildscript {
260308
ext.safeExtGet = {prop, fallback ->
@@ -265,12 +313,14 @@ buildscript {
265313
gradlePluginPortal()
266314
}
267315
dependencies {
268-
classpath("com.android.tools.build:gradle:7.1.1")
316+
classpath("com.android.tools.build:gradle:7.3.1")
317+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.22")
269318
}
270319
}
271320

272321
apply plugin: 'com.android.library'
273322
apply plugin: 'com.facebook.react'
323+
apply plugin: 'org.jetbrains.kotlin.android'
274324

275325
android {
276326
compileSdkVersion safeExtGet('compileSdkVersion', 31)
@@ -296,6 +346,9 @@ dependencies {
296346
}
297347
```
298348

349+
</TabItem>
350+
</Tabs>
351+
299352
#### The `AndroidManifest.xml`
300353

301354
Second, create an `android/src/main` folder. Inside that folder, create a `AndroidManifest.xml` file, with the following code:

website/versioned_docs/version-0.70/the-new-architecture/pillars-turbomodule.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,48 @@ android
244244
245245
First, create a `build.gradle` file in the `android` folder, with the following contents:
246246
247+
<Tabs groupId="android-language" queryString defaultValue={constants.defaultAndroidLanguage} values={constants.androidLanguages}>
248+
<TabItem value="java">
249+
250+
```java title="build.gradle"
251+
buildscript {
252+
ext.safeExtGet = {prop, fallback ->
253+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
254+
}
255+
repositories {
256+
google()
257+
gradlePluginPortal()
258+
}
259+
dependencies {
260+
classpath("com.android.tools.build:gradle:7.1.1")
261+
}
262+
}
263+
264+
apply plugin: 'com.android.library'
265+
apply plugin: 'com.facebook.react'
266+
267+
android {
268+
compileSdkVersion safeExtGet('compileSdkVersion', 31)
269+
}
270+
271+
repositories {
272+
maven {
273+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
274+
url "$projectDir/../node_modules/react-native/android"
275+
}
276+
mavenCentral()
277+
google()
278+
}
279+
280+
dependencies {
281+
implementation 'com.facebook.react:react-native:+'
282+
}
283+
```
284+
285+
</TabItem>
286+
287+
<TabItem value="kotlin">
288+
247289
```kotlin title="build.gradle"
248290
buildscript {
249291
ext.safeExtGet = {prop, fallback ->
@@ -255,11 +297,13 @@ buildscript {
255297
}
256298
dependencies {
257299
classpath("com.android.tools.build:gradle:7.1.1")
300+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.22")
258301
}
259302
}
260303

261304
apply plugin: 'com.android.library'
262305
apply plugin: 'com.facebook.react'
306+
apply plugin: 'org.jetbrains.kotlin.android'
263307

264308
android {
265309
compileSdkVersion safeExtGet('compileSdkVersion', 31)
@@ -279,6 +323,9 @@ dependencies {
279323
}
280324
```
281325
326+
</TabItem>
327+
</Tabs>
328+
282329
#### The `AndroidManifest.xml`
283330
284331
Second, create an `android/src/main` folder. Inside that folder, create a `AndroidManifest.xml` file, with the following code:

website/versioned_docs/version-0.71/the-new-architecture/pillars-fabric-components.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,51 @@ android
239239

240240
First, create a `build.gradle` file in the `android` folder, with the following contents:
241241

242+
<Tabs groupId="android-language" queryString defaultValue={constants.defaultAndroidLanguage} values={constants.androidLanguages}>
243+
<TabItem value="java">
244+
245+
```java title="build.gradle"
246+
buildscript {
247+
ext.safeExtGet = {prop, fallback ->
248+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
249+
}
250+
repositories {
251+
google()
252+
gradlePluginPortal()
253+
}
254+
dependencies {
255+
classpath("com.android.tools.build:gradle:7.3.1")
256+
}
257+
}
258+
259+
apply plugin: 'com.android.library'
260+
apply plugin: 'com.facebook.react'
261+
262+
android {
263+
compileSdkVersion safeExtGet('compileSdkVersion', 33)
264+
namespace "com.rtncenteredtext"
265+
266+
defaultConfig {
267+
minSdkVersion safeExtGet('minSdkVersion', 21)
268+
targetSdkVersion safeExtGet('targetSdkVersion', 33)
269+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true")
270+
}
271+
}
272+
273+
repositories {
274+
mavenCentral()
275+
google()
276+
}
277+
278+
dependencies {
279+
implementation 'com.facebook.react:react-native'
280+
}
281+
```
282+
283+
</TabItem>
284+
285+
<TabItem value="kotlin">
286+
242287
```kotlin title="build.gradle"
243288
buildscript {
244289
ext.safeExtGet = {prop, fallback ->
@@ -250,11 +295,13 @@ buildscript {
250295
}
251296
dependencies {
252297
classpath("com.android.tools.build:gradle:7.3.1")
298+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.22")
253299
}
254300
}
255301

256302
apply plugin: 'com.android.library'
257303
apply plugin: 'com.facebook.react'
304+
apply plugin: 'org.jetbrains.kotlin.android'
258305

259306
android {
260307
compileSdkVersion safeExtGet('compileSdkVersion', 33)
@@ -277,6 +324,9 @@ dependencies {
277324
}
278325
```
279326

327+
</TabItem>
328+
</Tabs>
329+
280330
#### The `ReactPackage` class
281331

282332
Then, you need a class that implements the `ReactPackage` interface. To run the **Codegen** process, you don't have to completely implement the Package class: an empty implementation is enough for the app to pick up the module as a proper React Native dependency and to try and generate the scaffolding code.

0 commit comments

Comments
 (0)