-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbuild.gradle
More file actions
303 lines (257 loc) · 9.88 KB
/
Copy pathbuild.gradle
File metadata and controls
303 lines (257 loc) · 9.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import groovy.json.JsonSlurper
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
buildscript {
def googleRootBuildFile = [
new File(projectDir, '../../../packages/google/build.gradle.kts'),
new File(rootDir, '../../../packages/google/build.gradle.kts'),
new File(rootProject.projectDir, '../../../packages/google/build.gradle.kts')
].find { it.exists() }
def googlePluginVersion = { pluginId ->
if (googleRootBuildFile == null) {
return null
}
def marker = "id(\"${pluginId}\") version \""
def line = googleRootBuildFile.readLines().find { it.contains(marker) }
if (line == null) {
return null
}
def matcher = line =~ /version "([^"]+)"/
return matcher.find() ? matcher.group(1) : null
}
def configuredVersion = { extName, propertyName ->
if (rootProject.ext.has(extName)) {
return rootProject.ext.get(extName).toString()
}
def propertyValue = project.findProperty(propertyName)
if (propertyValue == null || propertyValue.toString().trim().isEmpty()) {
throw new GradleException("react-native-iap: missing ${propertyName} in android/gradle.properties")
}
return propertyValue.toString()
}
def androidGradlePluginVersion = googlePluginVersion('com.android.library')
?: configuredVersion('androidGradlePluginVersion', 'NitroIap_androidGradlePluginVersion')
def kotlinGradlePluginVersion = googlePluginVersion('org.jetbrains.kotlin.android')
?: configuredVersion('kotlinVersion', 'NitroIap_kotlinVersion')
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:$androidGradlePluginVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinGradlePluginVersion"
}
}
def reactNativeArchitectures() {
def value = rootProject.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}
def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}
def resolveOpenIapVersionsFile() {
def candidates = [
new File(projectDir.parentFile, 'openiap-versions.json'),
new File(rootDir.parentFile ?: rootDir, 'openiap-versions.json'),
new File(rootProject.projectDir.parentFile ?: rootProject.projectDir, 'openiap-versions.json')
]
return candidates.find { it.exists() }
}
def openiapVersionsFile = resolveOpenIapVersionsFile()
if (openiapVersionsFile == null) {
throw new GradleException("react-native-iap: Unable to locate openiap-versions.json")
}
def openiapVersions = new JsonSlurper().parse(openiapVersionsFile)
def googleVersion = (openiapVersions instanceof Map) ? openiapVersions.google : null
if (!(googleVersion instanceof String) || !googleVersion.trim()) {
throw new GradleException("react-native-iap: 'google' version missing or invalid in openiap-versions.json")
}
def googleVersionString = googleVersion.trim()
apply plugin: "com.android.library"
apply plugin: 'org.jetbrains.kotlin.android'
// Only apply Nitro autolinking if the file exists
def nitroAutolinkingFile = file('../nitrogen/generated/android/NitroIap+autolinking.gradle')
if (nitroAutolinkingFile.exists()) {
apply from: nitroAutolinkingFile
}
apply from: "./fix-prefab.gradle"
// DO NOT apply Facebook React plugin for library modules
// This should only be applied to application modules
// if (isNewArchitectureEnabled()) {
// apply plugin: "com.facebook.react"
// }
def getExtOrDefault(name) {
def value = rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["NitroIap_" + name]
if (value == null || value.toString().trim().isEmpty()) {
throw new GradleException("react-native-iap: missing NitroIap_${name} in android/gradle.properties")
}
return value
}
def getExtOrIntegerDefault(name) {
return getExtOrDefault(name).toString().toInteger()
}
// Read store flags from gradle.properties, default to play
def horizonEnabled = project.findProperty('horizonEnabled')?.toBoolean() ?: false
def fireOsEnabled = project.findProperty('fireOsEnabled')?.toBoolean() ?: false
if (horizonEnabled && fireOsEnabled) {
throw new GradleException("react-native-iap: horizonEnabled and fireOsEnabled cannot both be true")
}
def openiapFlavor = fireOsEnabled ? 'amazon' : (horizonEnabled ? 'horizon' : 'play')
def resolveOpenIapGoogleBuildFile() {
def candidates = [
new File(projectDir, '../../../packages/google/openiap/build.gradle.kts'),
new File(rootDir, '../../../packages/google/openiap/build.gradle.kts'),
new File(rootProject.projectDir, '../../../packages/google/openiap/build.gradle.kts')
]
return candidates.find { it.exists() }
}
def readOpenIapGoogleVariable(File buildFile, String variableName) {
if (buildFile == null) {
return null
}
def matcher = buildFile.text =~ /val\s+${variableName}\s*=\s*"([^"]+)"/
return matcher.find() ? matcher.group(1) : null
}
def readOpenIapGoogleDependencyVersion(File buildFile, String coordinate) {
if (buildFile == null) {
return null
}
def matcher = buildFile.text =~ /${java.util.regex.Pattern.quote(coordinate)}:([^"$)]+)/
return matcher.find() ? matcher.group(1) : null
}
def googleOpenIapBuildFile = resolveOpenIapGoogleBuildFile()
def coroutinesVersion = readOpenIapGoogleVariable(googleOpenIapBuildFile, 'coroutinesVersion')
?: getExtOrDefault("coroutinesVersion")
def playServicesBaseVersion = getExtOrDefault("playServicesBaseVersion")
def junitVersion = readOpenIapGoogleDependencyVersion(googleOpenIapBuildFile, 'junit:junit')
?: getExtOrDefault("junitVersion")
android {
namespace = "com.margelo.nitro.iap"
ndkVersion = getExtOrDefault("ndkVersion")
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
defaultConfig {
minSdkVersion = getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion = getExtOrIntegerDefault("targetSdkVersion")
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
// Ship consumer keep rules so Nitro HybridObjects aren't stripped in app release builds
consumerProguardFiles 'consumer-rules.pro'
// Use explicit store flags to determine platform flavor
missingDimensionStrategy "platform", openiapFlavor
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
abiFilters (*reactNativeArchitectures())
buildTypes {
debug {
cppFlags "-O1 -g"
}
release {
cppFlags "-O2"
}
}
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
packagingOptions {
excludes = [
"META-INF",
"META-INF/**",
"**/libc++_shared.so",
"**/libfbjni.so",
"**/libjsi.so",
"**/libfolly_json.so",
"**/libfolly_runtime.so",
"**/libglog.so",
"**/libhermes.so",
"**/libhermes-executor-debug.so",
"**/libhermes_executor.so",
"**/libreactnative.so",
"**/libreactnativejni.so",
"**/libturbomodulejsijni.so",
"**/libreact_nativemodule_core.so",
"**/libjscexecutor.so"
]
}
buildFeatures {
buildConfig = true
prefab = true
}
buildTypes {
release {
minifyEnabled = false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
lintOptions {
disable "GradleCompatible"
}
// Removed sourceSets configuration for codegen as it's not needed for library modules
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
repositories {
mavenCentral()
google()
}
dependencies {
// For < 0.71, this will be from the local maven repo
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
// Add a dependency on NitroModules (only if available)
if (findProject(':react-native-nitro-modules') != null) {
implementation project(":react-native-nitro-modules")
}
// Google Play Services
if (!fireOsEnabled && !horizonEnabled) {
implementation "com.google.android.gms:play-services-base:$playServicesBaseVersion"
}
// Kotlin coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
// Determine which OpenIAP dependency to use
// In monorepo: use local packages/google source if available
def localGoogleProject = findProject(':openiap')
if (localGoogleProject != null) {
implementation project(':openiap')
} else if (fireOsEnabled) {
implementation "io.github.hyochan.openiap:openiap-google-amazon:${googleVersionString}"
} else if (horizonEnabled) {
implementation "io.github.hyochan.openiap:openiap-google-horizon:${googleVersionString}"
} else {
implementation "io.github.hyochan.openiap:openiap-google:${googleVersionString}"
}
// Test dependencies
testImplementation "junit:junit:$junitVersion"
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
}
configurations.all {
exclude group: 'com.facebook.react', module: 'react-native-safe-area-context'
}
// Ensure our CMake tasks run after react-native-nitro-modules' CMake tasks
// to prevent race condition where libNitroModules.so is not yet built.
// See: https://github.com/hyochan/react-native-iap/issues/3163
afterEvaluate {
def nitroProject = rootProject.findProject(':react-native-nitro-modules')
if (nitroProject) {
tasks.configureEach { task ->
if (task.name.startsWith('buildCMake')) {
def nitroTask = nitroProject.tasks.findByName(task.name)
if (nitroTask) {
task.dependsOn(nitroTask)
}
}
}
}
}