|
| 1 | +buildscript { |
| 2 | + // Buildscript is evaluated before everything else so we can't use getExtOrDefault |
| 3 | + def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['SolanaMobileSeedVaultLibModule_kotlinVersion'] |
| 4 | + |
| 5 | + repositories { |
| 6 | + google() |
| 7 | + mavenCentral() |
| 8 | + } |
| 9 | + |
| 10 | + dependencies { |
| 11 | + classpath 'com.android.tools.build:gradle:7.4.2' |
| 12 | + // noinspection DifferentKotlinGradleVersion |
| 13 | + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |
| 14 | + classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +def isNewArchitectureEnabled() { |
| 19 | + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" |
| 20 | +} |
| 21 | + |
| 22 | +apply plugin: 'com.android.library' |
| 23 | +apply plugin: 'kotlin-android' |
| 24 | +apply plugin: 'kotlinx-serialization' |
| 25 | + |
| 26 | +if (isNewArchitectureEnabled()) { |
| 27 | + apply plugin: 'com.facebook.react' |
| 28 | +} |
| 29 | + |
| 30 | +def getExtOrDefault(name) { |
| 31 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['SolanaMobileSeedVaultLibModule_' + name] |
| 32 | +} |
| 33 | + |
| 34 | +def getExtOrIntegerDefault(name) { |
| 35 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['SolanaMobileSeedVaultLibModule_' + name]).toInteger() |
| 36 | +} |
| 37 | + |
| 38 | +android { |
| 39 | + namespace "com.solanamobile.seedvault.reactnative" |
| 40 | + compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') |
| 41 | + |
| 42 | + defaultConfig { |
| 43 | + minSdkVersion getExtOrIntegerDefault('minSdkVersion') |
| 44 | + targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') |
| 45 | + buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() |
| 46 | + } |
| 47 | + buildTypes { |
| 48 | + release { |
| 49 | + minifyEnabled false |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + lintOptions { |
| 54 | + disable 'GradleCompatible' |
| 55 | + } |
| 56 | + |
| 57 | + compileOptions { |
| 58 | + sourceCompatibility JavaVersion.VERSION_1_8 |
| 59 | + targetCompatibility JavaVersion.VERSION_1_8 |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +repositories { |
| 64 | + mavenCentral() |
| 65 | + google() |
| 66 | + |
| 67 | + def found = false |
| 68 | + def defaultDir = null |
| 69 | + def androidSourcesName = 'React Native sources' |
| 70 | + |
| 71 | + if (rootProject.ext.has('reactNativeAndroidRoot')) { |
| 72 | + defaultDir = rootProject.ext.get('reactNativeAndroidRoot') |
| 73 | + } else { |
| 74 | + defaultDir = new File( |
| 75 | + projectDir, |
| 76 | + '/../../../node_modules/react-native/android' |
| 77 | + ) |
| 78 | + } |
| 79 | + |
| 80 | + if (defaultDir.exists()) { |
| 81 | + maven { |
| 82 | + url defaultDir.toString() |
| 83 | + name androidSourcesName |
| 84 | + } |
| 85 | + |
| 86 | + logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") |
| 87 | + found = true |
| 88 | + } else { |
| 89 | + def parentDir = rootProject.projectDir |
| 90 | + |
| 91 | + 1.upto(5, { |
| 92 | + if (found) return true |
| 93 | + parentDir = parentDir.parentFile |
| 94 | + |
| 95 | + def androidSourcesDir = new File( |
| 96 | + parentDir, |
| 97 | + 'node_modules/react-native' |
| 98 | + ) |
| 99 | + |
| 100 | + def androidPrebuiltBinaryDir = new File( |
| 101 | + parentDir, |
| 102 | + 'node_modules/react-native/android' |
| 103 | + ) |
| 104 | + |
| 105 | + if (androidPrebuiltBinaryDir.exists()) { |
| 106 | + maven { |
| 107 | + url androidPrebuiltBinaryDir.toString() |
| 108 | + name androidSourcesName |
| 109 | + } |
| 110 | + |
| 111 | + logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") |
| 112 | + found = true |
| 113 | + } else if (androidSourcesDir.exists()) { |
| 114 | + maven { |
| 115 | + url androidSourcesDir.toString() |
| 116 | + name androidSourcesName |
| 117 | + } |
| 118 | + |
| 119 | + logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") |
| 120 | + found = true |
| 121 | + } |
| 122 | + }) |
| 123 | + } |
| 124 | + |
| 125 | + if (!found) { |
| 126 | + throw new GradleException( |
| 127 | + "${project.name}: unable to locate React Native android sources. " + |
| 128 | + "Ensure you have you installed React Native as a dependency in your project and try again." |
| 129 | + ) |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +def kotlin_version = getExtOrDefault('kotlinVersion') |
| 134 | + |
| 135 | +dependencies { |
| 136 | + //noinspection GradleDynamicVersion |
| 137 | + implementation "com.facebook.react:react-native:+" // From node_modules |
| 138 | + implementation 'com.solanamobile:seedvault-wallet-sdk:0.2.8' |
| 139 | + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" |
| 140 | + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4" |
| 141 | + implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1" |
| 142 | +} |
| 143 | + |
| 144 | +if (isNewArchitectureEnabled()) { |
| 145 | + react { |
| 146 | + jsRootDir = file("../src/") |
| 147 | + libraryName = "SolanaMobileWSeedVaultLibModule" |
| 148 | + codegenJavaPackageName = "com.solanamobile.SeedVault.reactnative" |
| 149 | + } |
| 150 | +} |
0 commit comments