Ameer
Ameer

Reputation: 2769

applyNativeModulesAppBuildGradle(project) and applyNativeModulesSettingsGradle in gradle kts file

I am using the Gradle KTS file and trying to set up the React native. I am not able to add

applyNativeModulesAppBuildGradle(project)

What is the alternative for applyNativeModulesAppBuildGradle in KTS. Also on settings, we have to write applyNativeModulesSettingsGradle

Upvotes: 10

Views: 2879

Answers (1)

ggaier
ggaier

Reputation: 391

Things may have changed. For recent RN Android projects, use this:

import groovy.lang.Closure
import org.gradle.api.Project

apply(from = "../node_modules/@react-native-community/cli-platform-android/native_modules.gradle")
val applyNativeModules: Closure<Project> = extra.get("applyNativeModulesSettingsGradle") as Closure<Project>
applyNativeModules(settings)

include(":app")

includeBuild("../node_modules/@react-native/gradle-plugin")

Below is my solution,calling applyNativeModulesSettingsGradle method in native_modules.gradle:

import groovy.lang.Closure

apply(from = "../node_modules/@react-native-community/cli-platform-android/native_modules.gradle")
val applyNativeModules: Closure<Any> = extra.get("applyNativeModulesSettingsGradle") as Closure<Any>
applyNativeModules(settings)

Use the Kotlin way to get the method reference from extra, then invoke the function.

Upvotes: 7

Related Questions