๐Ÿ“ฆ manideepk90 / react-native-hyperswitch-sdk

๐Ÿ“„ build.gradle ยท 617 lines
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617apply plugin: "com.android.library"
apply plugin: "org.jetbrains.kotlin.android"
ext.generatePackageList = true
apply plugin: "com.facebook.react"


/**
 * This is the configuration block to customize your React Native Android app.
 * By default you don't need to apply any configuration, just uncomment the lines you need.
 */
react {
    /* Autolinking */
    autolinkLibrariesWithApp()

    /* Folders */
    //   The root of your project, i.e. where "package.json" lives. Default is '../..'
    // root = file("../../")
    //   The folder where the react-native NPM package is. Default is ../../node_modules/react-native
    // reactNativeDir = file("../../node_modules/react-native")
    //   The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
    // codegenDir = file("../../node_modules/@react-native/codegen")
    //   The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js
    // cliFile = file("../../node_modules/react-native/cli.js")

    /* Variants */
    //   The list of variants to that are debuggable. For those we're going to
    //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
    //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
    // debuggableVariants = ["liteDebug", "prodDebug"]

    /* Bundling */
    //   A list containing the node command and its flags. Default is just 'node'.
    // nodeExecutableAndArgs = ["node"]
    //
    //   The command to run when bundling. By default is 'bundle'
    // bundleCommand = "ram-bundle"
    //
    //   The path to the CLI configuration file. Default is empty.
    // bundleConfig = file(../rn-cli.config.js)
    //
    //   The name of the generated asset file containing your JS bundle
     bundleAssetName = "hyperswitch.bundle"
    //
    //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
    // entryFile = file("../js/MyApplication.android.js")
    //
    //   A list of extra flags to pass to the 'bundle' commands.
    //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
    // extraPackagerArgs = []

    /* Hermes Commands */
    //   The hermes compiler command to run. By default it is 'hermesc'
    // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
    //
    //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
    // hermesFlags = ["-O", "-output-source-map"]
}


/**
 * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore (JSC)
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = io.github.react-native-community:jsc-android-intl:2026004.+`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US. Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'

android {
    ndkVersion rootProject.ext.ndkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace "io.hyperswitch"
    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"

    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            ndk {
                debugSymbolLevel 'NONE'  // Remove debug symbols to reduce .so file size
            }
            shrinkResources false

            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

    packagingOptions {
        // Use pickFirst instead of exclude to handle duplicates
        pickFirst "**/libc++_shared.so"
        pickFirst "**/libfbjni.so"
        pickFirst "**/libjsi.so"
        pickFirst "**/libhermes.so"
        pickFirst "**/libreactnative.so"
        pickFirst "**/libimagepipeline.so"
        pickFirst "**/libnative-filters.so"
        pickFirst "**/libnative-imagetranscoder.so"

        // Also add these common React Native duplicates
        pickFirst "**/libreactnativejni.so"
        pickFirst "**/libturbomodulejsijni.so"
        pickFirst "**/libappmodules.so"
    }

    publishing {
        singleVariant("release") {
            withSourcesJar()
        }
    }

}

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    api("com.facebook.react:react-android")
    api project(':hyperswitch-sdk-android-api')
    implementation project(':hyperswitch-sdk-android-common')
    implementation project(':hyperswitch-sdk-android-logger')
//    implementation project(':hyperswitch-sdk-android-hyperota')
    if (hermesEnabled.toBoolean()) {
        api("com.facebook.react:hermes-android")
    } else {
        api jscFlavor
    }
}


rootProject.allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url("$rootDir/maven/")
        }
        maven {
            url "https://jitpack.io"
        }
        maven {
            url("$rootDir/../node_modules/detox/Detox-android")
        }
        maven {
            url "https://maven.juspay.in/hyper-sdk/"
        }
    }
}

apply plugin: "maven-publish"

// Read versions from package.json
def packageJsonVersions = [:]
try {
    def packageJsonFile = rootProject.file('../package.json')
    def json = new groovy.json.JsonSlurper().parse(packageJsonFile)

    packageJsonVersions = [
        'react-native': json.dependencies.'react-native'?.toString()?.replaceAll('[\\^~]', ''),
        'react-native-clipboard_clipboard': json.dependencies.'@react-native-clipboard/clipboard'?.toString()?.replaceAll('[\\^~]', ''),
        'sentry_react-native': json.dependencies.'@sentry/react-native'?.toString()?.replaceAll('[\\^~]', ''),
        'react-native-inappbrowser-reborn': json.dependencies.'react-native-inappbrowser-reborn'?.toString()?.replaceAll('[\\^~]', ''),
        'react-native-safe-area-context': json.dependencies.'react-native-safe-area-context'?.toString()?.replaceAll('[\\^~]', ''),
        'react-native-svg': json.dependencies.'react-native-svg'?.toString()?.replaceAll('[\\^~]', ''),
        'callstack_repack': json.devDependencies.'@callstack/repack'?.toString()?.replaceAll('[\\^~]', ''),
    ]
    println "Loaded versions from package.json: ${packageJsonVersions}"
} catch (Exception e) {
    logger.warn("Failed to read package.json: ${e.message}")
}

// Function to resolve version - capture packageJsonVersions in closure
def resolveVersion = { String groupId, String artifactId, String currentVersion ->
    if (currentVersion != 'unspecified') {
        return currentVersion
    }
    if (groupId == 'hyperSwitch') {
        return packageJsonVersions[artifactId] ?: 'unspecified'
    }
    return currentVersion
}

publishing {
    publications {
        release(MavenPublication) {
            groupId = 'hyperSwitch'
            artifactId = 'hyperswitch-sdk-android'
            version = hyperswitchSdkVersion

            afterEvaluate {
                from components.release
            }

            pom {
                name = 'Hyperswitch SDK for Android'
                description = 'This is the Hyperswitch SDK for Android, providing seamless integration with the Hyperswitch platform.'
                url = 'http://www.hyperswitch.io'

                licenses {
                    license {
                        name = 'The Apache License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution = 'repo'
                    }
                }

                scm {
                    url = 'https://github.com/hyperswitch/hyperswitch-sdk-android'
                    connection = 'scm:git:git://github.com/juspay/hyperswitch-sdk-android.git'
                    developerConnection = 'scm:git:ssh://git@github.com:juspay/hyperswitch-sdk-android.git'
                    tag = 'HEAD'
                }

                developers {
                    developer {
                        id = 'manideepk90'
                        name = 'manideep'
                        email = 'kuntimaddi.manideep@juspay.in'
                    }
                }

                withXml {
                    def root = asNode()

                    // Remove existing dependencies node and recreate with filtered dependencies
                    def dependenciesNode = root.dependencies[0]
                    if (dependenciesNode) {
                        root.remove(dependenciesNode)
                    }

                    def dependencies = root.appendNode('dependencies')

                    // Manually define the dependencies we want in the POM
                    // Core React Native dependencies - use version from package.json
                    def rnVersion = packageJsonVersions['react-native']
                    if (rnVersion && rnVersion != 'unspecified') {
                        addDependency(dependencies, 'com.facebook.react', 'react-native', rnVersion)
                    }

                    // Hermes - React Native 0.82.1 uses a specific Hermes version
                    // We'll use the same version as react-native for simplicity
                    if (rnVersion && rnVersion != 'unspecified') {
                        addDependency(dependencies, 'com.facebook', 'hermes', rnVersion)
                    }

                    // Internal hyperswitch modules - use fixed versions
                    addDependency(dependencies, 'io.hyperswitch', 'hyperswitch-sdk-android-api', '1.0.2')
                    addDependency(dependencies, 'io.hyperswitch', 'hyperswitch-sdk-android-common', '1.0.0')
                    addDependency(dependencies, 'io.hyperswitch', 'hyperswitch-sdk-android-logger', '1.0.1')

                    // Kotlin stdlib
                    addDependency(dependencies, 'org.jetbrains.kotlin', 'kotlin-stdlib', '2.1.20')

                    // React Native third-party libraries
                    addDependency(dependencies, 'com.facebook.react', 'react-native-clipboard', packageJsonVersions['react-native-clipboard_clipboard'])
                    addDependency(dependencies, 'com.github.proyecto26', 'react-native-inappbrowser-reborn', packageJsonVersions['react-native-inappbrowser-reborn'])
                    addDependency(dependencies, 'com.github.th3rdwave', 'react-native-safe-area-context', packageJsonVersions['react-native-safe-area-context'])
                    addDependency(dependencies, 'com.github.react-native-community', 'react-native-svg', packageJsonVersions['react-native-svg'])
                    addDependency(dependencies, 'io.sentry', 'sentry-android', packageJsonVersions['sentry_react-native'])
                    addDependency(dependencies, 'com.github.callstack', 'repack', packageJsonVersions['callstack_repack'])
                }
            }
        }
    }
}

// Helper function to add a dependency to the POM
def addDependency(def dependenciesNode, String groupId, String artifactId, String version) {
    if (version && version != 'unspecified') {
        def dependency = dependenciesNode.appendNode('dependency')
        dependency.appendNode('groupId', groupId)
        dependency.appendNode('artifactId', artifactId)
        dependency.appendNode('version', version)
    }
}

// Fix Gradle module metadata to replace 'unspecified' versions with versions from package.json
tasks.register('fixModuleMetadata') {
    doLast {
        def outputFile = file("${buildDir}/publications/release/module.json")
        if (outputFile.exists()) {
            def json = new groovy.json.JsonSlurper().parse(outputFile)
            json.component.variants.each { variant ->
                variant.dependencies?.each { dep ->
                    if (dep.version?.requires == 'unspecified') {
                        def resolvedVersion = resolveVersion(dep.group, dep.module, 'unspecified')
                        if (resolvedVersion != 'unspecified') {
                            dep.version.requires = resolvedVersion
                        }
                    }
                }
            }
            outputFile.text = groovy.json.JsonOutput.toJson(json)
            println "Fixed module metadata with versions from package.json"
        }
    }
}

// Fix module metadata in local Maven repository after publishing
tasks.register('fixPublishedModuleMetadata') {
    doLast {
        def mavenModuleFile = file("${System.getProperty('user.home')}/.m2/repository/hyperSwitch/hyperswitch-sdk-android/${hyperswitchSdkVersion}/hyperswitch-sdk-android-${hyperswitchSdkVersion}.module")
        if (mavenModuleFile.exists()) {
            def json = new groovy.json.JsonSlurper().parse(mavenModuleFile)

            // Mapping for third-party dependencies to their correct Maven coordinates
            def thirdPartyMapping = [
                'react-native-clipboard_clipboard': [groupId: 'com.facebook.react', artifactId: 'react-native-clipboard'],
                'react-native-inappbrowser-reborn': [groupId: 'com.github.proyecto26', artifactId: 'react-native-inappbrowser-reborn'],
                'react-native-safe-area-context': [groupId: 'com.github.th3rdwave', artifactId: 'react-native-safe-area-context'],
                'react-native-svg': [groupId: 'com.github.react-native-community', artifactId: 'react-native-svg'],
                'sentry_react-native': [groupId: 'io.sentry', artifactId: 'sentry-android'],
                'callstack_repack': [groupId: 'com.github.callstack', artifactId: 'repack']
            ]

            json.variants.each { variant ->
                // Filter out demo dependencies and fix unspecified versions and groupIds
                def filteredDeps = []
                variant.dependencies?.each { dep ->
                    // Skip demo dependencies
                    if (dep.module == 'react-native-lib-demo') {
                        return
                    }

                    // Fix groupId and artifactId for third-party dependencies
                    if (dep.group == 'hyperSwitch' && thirdPartyMapping.containsKey(dep.module)) {
                        def mapping = thirdPartyMapping[dep.module]
                        dep.group = mapping.groupId
                        dep.module = mapping.artifactId
                    }

                    // Fix missing or unspecified versions using package.json versions
                    def needsVersion = !dep.version || dep.version.requires == 'unspecified'
                    if (needsVersion) {
                        def resolvedVersion = null

                        // Map for core React Native dependencies (these come from react-android and hermes-android)
                        if (dep.group == 'com.facebook.react' && dep.module == 'react-android') {
                            resolvedVersion = packageJsonVersions['react-native']
                        } else if (dep.group == 'com.facebook.react' && dep.module == 'hermes-android') {
                            resolvedVersion = packageJsonVersions['react-native']
                        } else if (dep.group == 'io.hyperswitch') {
                            // Internal hyperswitch modules
                            if (dep.module == 'hyperswitch-sdk-android-api') {
                                resolvedVersion = '1.0.2'
                            } else if (dep.module == 'hyperswitch-sdk-android-common') {
                                resolvedVersion = '1.0.0'
                            } else if (dep.module == 'hyperswitch-sdk-android-logger') {
                                resolvedVersion = '1.0.1'
                            }
                        } else if (dep.group == 'org.jetbrains.kotlin' && dep.module == 'kotlin-stdlib') {
                            resolvedVersion = '2.1.20'
                        } else if (dep.group == 'com.facebook.react' && dep.module == 'react-native-clipboard') {
                            resolvedVersion = packageJsonVersions['react-native-clipboard_clipboard']
                        } else if (dep.group == 'com.github.proyecto26' && dep.module == 'react-native-inappbrowser-reborn') {
                            resolvedVersion = packageJsonVersions['react-native-inappbrowser-reborn']
                        } else if (dep.group == 'com.github.th3rdwave' && dep.module == 'react-native-safe-area-context') {
                            resolvedVersion = packageJsonVersions['react-native-safe-area-context']
                        } else if (dep.group == 'com.github.react-native-community' && dep.module == 'react-native-svg') {
                            resolvedVersion = packageJsonVersions['react-native-svg']
                        } else if (dep.group == 'io.sentry' && dep.module == 'sentry-android') {
                            resolvedVersion = packageJsonVersions['sentry_react-native']
                        } else if (dep.group == 'com.github.callstack' && dep.module == 'repack') {
                            resolvedVersion = packageJsonVersions['callstack_repack']
                        } else {
                            // Try resolveVersion for other dependencies
                            resolvedVersion = resolveVersion(dep.group, dep.module, 'unspecified')
                        }

                        if (resolvedVersion && resolvedVersion != 'unspecified') {
                            if (!dep.version) {
                                dep.version = [:]
                            }
                            dep.version.requires = resolvedVersion
                        }
                    }
                    filteredDeps << dep
                }
                variant.dependencies = filteredDeps
            }
            mavenModuleFile.text = groovy.json.JsonOutput.toJson(json)
            println "Fixed published module metadata with versions and correct groupIds from package.json"
        }
    }
}

// Ensure fixModuleMetadata runs after GenerateModuleMetadata
tasks.withType(GenerateModuleMetadata).configureEach {
    tasks.named('fixModuleMetadata').get().mustRunAfter(it)
}

// Ensure fixPublishedModuleMetadata runs after publish
tasks.named('publishReleasePublicationToMavenLocal').configure {
    finalizedBy 'fixPublishedModuleMetadata'
}

def runtimeDeps = [
        'react-native-inappbrowser-reborn',
        'react-native-svg',
        'sentry_react-native',
]

def runtimeDepsExcluded = [
        'demo-app',
        'demo-app-lite'
]

def runtimeDepsOptional = [
        'react-native-hyperswitch-kount',
        'react-native-hyperswitch-paypal',
        'juspay-tech_react-native-hyperswitch-netcetera-3ds',
        'juspay-tech_react-native-hyperswitch-samsung-pay',
        'juspay-tech_react-native-hyperswitch-scancard',
        'react-native-klarna-inapp-sdk',
]

def configurePomMetadata = { root ->
    root.appendNode('name', 'Hyperswitch SDK for Android')
    root.appendNode('description', 'This is the Hyperswitch SDK for Android, providing seamless integration with the Hyperswitch platform.')
    root.appendNode('url', 'http://www.hyperswitch.io')

    def licenseNode = root.appendNode('licenses').appendNode('license')
    licenseNode.appendNode('name', 'The Apache License, Version 2.0')
    licenseNode.appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0.txt')
    licenseNode.appendNode('distribution', 'repo')

    def scmNode = root.appendNode('scm')
    scmNode.appendNode('url', 'https://github.com/hyperswitch/hyperswitch-sdk-android')
    scmNode.appendNode('connection', 'scm:git:git://github.com/juspay/hyperswitch-sdk-android.git')
    scmNode.appendNode('developerConnection', 'scm:git:ssh://git@github.com:juspay/hyperswitch-sdk-android.git')
    scmNode.appendNode('tag', 'HEAD')

    def developerNode = root.appendNode('developers').appendNode('developer')
    developerNode.appendNode('id', 'manideepk90')
    developerNode.appendNode('name', 'Manideep')
    developerNode.appendNode('email', 'kuntimaddi.manideep@juspay.in')
}

gradle.projectsEvaluated {
    subprojects {
        def configurePom = { pom ->
            def root = pom.asNode()
            configurePomMetadata(root)

            def dependencies = root.appendNode('dependencies')
            configurations.getByName('releaseCompileClasspath').getResolvedConfiguration().getFirstLevelModuleDependencies().each {
                if (!runtimeDepsOptional.contains(it.moduleName)) {
                    def dependency = dependencies.appendNode('dependency')
                    dependency.appendNode('groupId', it.moduleGroup)
                    dependency.appendNode('artifactId', it.moduleName)
                    dependency.appendNode('version', runtimeDeps.contains(it.moduleName) ? rnlibVersion : it.moduleVersion)
                }
            }
        }

        def androidSourcesJar = tasks.register('androidSourcesJar', Jar) {
            archiveClassifier.set('sources')
            from android.sourceSets.main.java.srcDirs
            from android.sourceSets.main.kotlin.srcDirs
        }

        publishing {
            publications {
                if (!runtimeDepsExcluded.contains(project.name)) {
                    "$project.name"(MavenPublication) {
                        groupId = project.group
                        artifactId = project.name == 'app' ? 'hyperswitch-sdk-android' : project.name
                        version = runtimeDeps.contains(project.name) || runtimeDepsOptional.contains(project.name) ? rnlibVersion : project.version
                        artifact "$buildDir/outputs/aar/$project.name-release.aar"
                        artifact androidSourcesJar
                        pom.withXml(configurePom)
                    }
                }
            }
            repositories {
                maven {
                    url("${project.rootDir}/maven")
                }
            }
        }
    }
}

android.libraryVariants.all { variant ->
    if (variant.name == "release") {
        variant.packageLibraryProvider.get().doLast {
            // Find NDK strip tool
            def ndkDir = null
            def localProps = new Properties()
            def localPropsFile = rootProject.file("local.properties")
            if (localPropsFile.exists()) {
                localPropsFile.withInputStream { localProps.load(it) }
                def sdkDir = localProps.getProperty("sdk.dir")
                if (sdkDir) {
                    def ndkPath = new File(sdkDir, "ndk/${rootProject.ext.ndkVersion}")
                    if (ndkPath.exists()) {
                        ndkDir = ndkPath.absolutePath
                    }
                }
            }

            if (!ndkDir) {
                println "Could not find NDK directory. Skipping stripping."
                return
            }

            def os = System.getProperty("os.name").toLowerCase()
            def arch = System.getProperty("os.arch").toLowerCase()

            // Detect correct strip tool path
            def stripTool
            if (os.contains("mac")) {
                if (arch.contains("aarch64") || arch.contains("arm64")) {
                    stripTool = "${ndkDir}/toolchains/llvm/prebuilt/darwin-arm64/bin/llvm-strip"
                } else {
                    stripTool = "${ndkDir}/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip"
                }
            } else {
                stripTool = "${ndkDir}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip"
            }

            // Fallback to find strip tool
            if (!file(stripTool).exists()) {
                def possiblePaths = [
                    "${ndkDir}/toolchains/llvm/prebuilt/darwin-arm64/bin/llvm-strip",
                    "${ndkDir}/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip",
                    "${ndkDir}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip"
                ]
                for (path in possiblePaths) {
                    if (file(path).exists()) {
                        stripTool = path
                        break
                    }
                }
            }

            if (!file(stripTool).exists()) {
                println "Strip tool not found at: ${stripTool}. Skipping stripping."
                return
            }

            println "Using strip tool: ${stripTool}"

            // Strip all .so files in intermediates
            fileTree("${buildDir}/intermediates/stripped_native_libs/release/out/lib").visit { FileVisitDetails details ->
                if (details.file.name.endsWith('.so')) {
                    def originalSize = details.file.length()
                    def process = new ProcessBuilder(stripTool, '--strip-all', details.file.absolutePath)
                        .redirectErrorStream(true)
                        .start()
                    process.waitFor()
                    def newSize = details.file.length()
                    if (newSize < originalSize) {
                        def saved = (originalSize - newSize) / 1024 / 1024
                        println "Stripped ${details.file.name}: ${String.format("%.2f", originalSize / 1024 / 1024)}MB -> ${String.format("%.2f", newSize / 1024 / 1024)}MB (saved ${String.format("%.2f", saved)}MB)"
                    }
                }
            }

            // Also strip in the final AAR output
            def aarFile = file("${buildDir}/outputs/aar/${project.name}-release.aar")
            if (aarFile.exists()) {
                def tempDir = file("${buildDir}/tmp/aar-extract")
                tempDir.mkdirs()

                copy {
                    from zipTree(aarFile)
                    into tempDir
                }

                fileTree(tempDir).visit { FileVisitDetails details ->
                    if (details.file.name.endsWith('.so')) {
                        def originalSize = details.file.length()
                        def process = new ProcessBuilder(stripTool, '--strip-all', details.file.absolutePath)
                            .redirectErrorStream(true)
                            .start()
                        process.waitFor()
                        def newSize = details.file.length()
                        if (newSize < originalSize) {
                            def saved = (originalSize - newSize) / 1024 / 1024
                            println "Stripped AAR ${details.file.name}: ${String.format("%.2f", originalSize / 1024 / 1024)}MB -> ${String.format("%.2f", newSize / 1024 / 1024)}MB (saved ${String.format("%.2f", saved)}MB)"
                        }
                    }
                }

                ant.zip(destfile: aarFile, basedir: tempDir)
                delete tempDir
            }
        }
    }
}