|
| 1 | +buildscript { |
| 2 | + repositories { |
| 3 | + google() |
| 4 | + mavenCentral() |
| 5 | + } |
| 6 | + |
| 7 | + dependencies { |
| 8 | + classpath "com.android.tools.build:gradle:7.2.1" |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +def isNewArchitectureEnabled() { |
| 13 | + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" |
| 14 | +} |
| 15 | + |
| 16 | +apply plugin: "com.android.library" |
| 17 | + |
| 18 | +if (isNewArchitectureEnabled()) { |
| 19 | + apply plugin: "com.facebook.react" |
| 20 | +} |
| 21 | + |
| 22 | +def getExtOrDefault(name) { |
| 23 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Mtcaptcha_" + name] |
| 24 | +} |
| 25 | + |
| 26 | +def getExtOrIntegerDefault(name) { |
| 27 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Mtcaptcha_" + name]).toInteger() |
| 28 | +} |
| 29 | + |
| 30 | +def supportsNamespace() { |
| 31 | + def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') |
| 32 | + def major = parsed[0].toInteger() |
| 33 | + def minor = parsed[1].toInteger() |
| 34 | + |
| 35 | + // Namespace support was added in 7.3.0 |
| 36 | + return (major == 7 && minor >= 3) || major >= 8 |
| 37 | +} |
| 38 | + |
| 39 | +android { |
| 40 | + if (supportsNamespace()) { |
| 41 | + namespace "com.mtcaptcha" |
| 42 | + |
| 43 | + sourceSets { |
| 44 | + main { |
| 45 | + manifest.srcFile "src/main/AndroidManifestNew.xml" |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + ndkVersion getExtOrDefault("ndkVersion") |
| 51 | + compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") |
| 52 | + |
| 53 | + defaultConfig { |
| 54 | + minSdkVersion getExtOrIntegerDefault("minSdkVersion") |
| 55 | + targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") |
| 56 | + buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() |
| 57 | + |
| 58 | + externalNativeBuild { |
| 59 | + cmake { |
| 60 | + cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all" |
| 61 | + abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a" |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + externalNativeBuild { |
| 67 | + cmake { |
| 68 | + path "CMakeLists.txt" |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + buildFeatures { |
| 73 | + buildConfig true |
| 74 | + } |
| 75 | + |
| 76 | + buildTypes { |
| 77 | + release { |
| 78 | + minifyEnabled false |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + lintOptions { |
| 83 | + disable "GradleCompatible" |
| 84 | + } |
| 85 | + |
| 86 | + compileOptions { |
| 87 | + sourceCompatibility JavaVersion.VERSION_1_8 |
| 88 | + targetCompatibility JavaVersion.VERSION_1_8 |
| 89 | + } |
| 90 | + |
| 91 | + sourceSets { |
| 92 | + main { |
| 93 | + if (isNewArchitectureEnabled()) { |
| 94 | + java.srcDirs += [ |
| 95 | + "src/newarch", |
| 96 | + // This is needed to build Kotlin project with NewArch enabled |
| 97 | + "${project.buildDir}/generated/source/codegen/java" |
| 98 | + ] |
| 99 | + } else { |
| 100 | + java.srcDirs += ["src/oldarch"] |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +repositories { |
| 107 | + mavenCentral() |
| 108 | + google() |
| 109 | +} |
| 110 | + |
| 111 | + |
| 112 | +dependencies { |
| 113 | + // For < 0.71, this will be from the local maven repo |
| 114 | + // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin |
| 115 | + //noinspection GradleDynamicVersion |
| 116 | + implementation "com.facebook.react:react-native:+" |
| 117 | +} |
| 118 | + |
| 119 | +if (isNewArchitectureEnabled()) { |
| 120 | + react { |
| 121 | + jsRootDir = file("../src/") |
| 122 | + libraryName = "Mtcaptcha" |
| 123 | + codegenJavaPackageName = "com.mtcaptcha" |
| 124 | + } |
| 125 | +} |
0 commit comments