|
| 1 | +import groovy.json.JsonOutput |
| 2 | +import org.jetbrains.kotlin.gradle.dsl.JvmTarget |
| 3 | + |
| 4 | +plugins { |
| 5 | + id 'com.android.library' |
| 6 | + id 'org.jetbrains.kotlin.android' |
| 7 | + id 'com.commencis.secretsvaultplugin' |
| 8 | +} |
| 9 | + |
| 10 | +ext { |
| 11 | + publishArtifactId = 'processout-android-netcetera-3ds-core' |
| 12 | + publishVersion = rootProject.ext.netcetera3dsSdkVersion |
| 13 | + publishDescription = 'ProcessOut Android SDK - Netcetera 3DS Core' |
| 14 | +} |
| 15 | + |
| 16 | +apply from: "${rootProject.projectDir}/scripts/publish-module.gradle" |
| 17 | + |
| 18 | +android { |
| 19 | + namespace 'com.processout.sdk.netcetera.threeds.core' |
| 20 | + compileSdk rootProject.ext.compileSdkVersion |
| 21 | + |
| 22 | + ndkVersion rootProject.ext.ndkVersion |
| 23 | + externalNativeBuild { |
| 24 | + cmake { |
| 25 | + path file('src/main/cpp/CMakeLists.txt') |
| 26 | + version rootProject.ext.cmakeVersion |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + defaultConfig { |
| 31 | + minSdk rootProject.ext.minSdkVersion |
| 32 | + targetSdk rootProject.ext.targetSdkVersion |
| 33 | + setBuildConfig(it) |
| 34 | + consumerProguardFiles 'consumer-rules.pro', 'netcetera-consumer-rules.pro' |
| 35 | + ndk { |
| 36 | + abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + buildTypes { |
| 41 | + release { |
| 42 | + minifyEnabled false |
| 43 | + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 44 | + } |
| 45 | + debug { |
| 46 | + getIsDefault().set(true) |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + flavorDimensions = ['environment'] |
| 51 | + productFlavors { |
| 52 | + production { |
| 53 | + dimension 'environment' |
| 54 | + } |
| 55 | + staging { |
| 56 | + getIsDefault().set(true) |
| 57 | + dimension 'environment' |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + buildFeatures { |
| 62 | + buildConfig true |
| 63 | + } |
| 64 | + |
| 65 | + compileOptions { |
| 66 | + sourceCompatibility JavaVersion.VERSION_17 |
| 67 | + targetCompatibility JavaVersion.VERSION_17 |
| 68 | + } |
| 69 | + |
| 70 | + publishing { |
| 71 | + singleVariant('productionRelease') |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +kotlin { |
| 76 | + compilerOptions { |
| 77 | + jvmTarget.set(JvmTarget.JVM_17) |
| 78 | + optIn.add("com.processout.sdk.netcetera.threeds.core.annotation.ProcessOutInternalApi") |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +@SuppressWarnings('GrMethodMayBeStatic') |
| 83 | +def setBuildConfig(buildType) { |
| 84 | + buildType.buildConfigField("String", "LIBRARY_NAME", "\"ProcessOut Android SDK - Netcetera 3DS Core\"") |
| 85 | + buildType.buildConfigField("String", "LIBRARY_VERSION", "\"$publishVersion\"") |
| 86 | +} |
| 87 | + |
| 88 | +tasks.register('beforeKeepSecrets') { |
| 89 | + doLast { |
| 90 | + File secrets = project.file("secrets.json") |
| 91 | + def content = [[key: "apiKey", value: getApiKey()]] |
| 92 | + secrets.text = JsonOutput.toJson(content) |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +def getApiKey() { |
| 97 | + File localProperties = rootProject.file("local.properties") |
| 98 | + if (localProperties.exists()) { |
| 99 | + def properties = new Properties() |
| 100 | + properties.load(new FileInputStream(localProperties)) |
| 101 | + String apiKey = properties.getProperty("netcetera.apiKey", "").trim() |
| 102 | + if (!apiKey) { |
| 103 | + throw new GradleException("Missing or blank 'netcetera.apiKey' in 'local.properties' file.") |
| 104 | + } |
| 105 | + return apiKey |
| 106 | + } |
| 107 | + throw new GradleException("File not found: 'local.properties'.") |
| 108 | +} |
| 109 | + |
| 110 | +tasks.register('afterKeepSecrets') { |
| 111 | + doLast { |
| 112 | + copyCMakeLists() |
| 113 | + copyMainSecretsClass() |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +def copyCMakeLists() { |
| 118 | + File source = project.file("src/main/cpp/CMakeLists.copy") |
| 119 | + File target = project.file("src/main/cpp/CMakeLists.txt") |
| 120 | + target.text = source.text |
| 121 | +} |
| 122 | + |
| 123 | +def copyMainSecretsClass() { |
| 124 | + String packagePath = "com/processout/sdk/netcetera/threeds/core" |
| 125 | + File source = project.file("src/main/kotlin/${packagePath}/MainSecrets.copy") |
| 126 | + File target = project.file("src/main/kotlin/${packagePath}/MainSecrets.kt") |
| 127 | + target.text = source.text |
| 128 | +} |
| 129 | + |
| 130 | +keepSecrets.dependsOn beforeKeepSecrets |
| 131 | +afterKeepSecrets.dependsOn keepSecrets |
| 132 | +preBuild.dependsOn afterKeepSecrets |
| 133 | + |
| 134 | +dependencies { |
| 135 | + api fileTree(dir: 'libs', include: ['*.jar']) |
| 136 | + api "org.bouncycastle:bcprov-jdk15to18:$bouncyCastleVersion" |
| 137 | + implementation "org.slf4j:slf4j-api:$slf4jVersion" |
| 138 | +} |
0 commit comments