From 0375ff3e1a224ef1e087c0c23a1576fece64d493 Mon Sep 17 00:00:00 2001 From: Vladimir Abramichev Date: Wed, 10 Jul 2024 18:17:33 +0200 Subject: [PATCH] chore: update build.gradle --- android/build.gradle | 146 +++++++++++++++--------- android/dependencies.gradle | 11 -- android/gradle.properties | 4 + android/src/main/AndroidManifest.xml | 1 + android/src/main/AndroidManifestNew.xml | 8 ++ package.json | 1 - scripts/set-version.sh | 2 +- 7 files changed, 107 insertions(+), 66 deletions(-) create mode 100644 android/gradle.properties create mode 100644 android/src/main/AndroidManifestNew.xml diff --git a/android/build.gradle b/android/build.gradle index 3851a264b..90cdf2bff 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,74 +1,114 @@ -def safeExtGet(prop, fallback) { - rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback +buildscript { + // Buildscript is evaluated before everything else so we can't use getExtOrDefault + def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["ComAdyenreactnativesdkModule_kotlinVersion"] + + repositories { + google() + mavenCentral() + } + + dependencies { + classpath "com.android.tools.build:gradle:7.2.1" + // noinspection DifferentKotlinGradleVersion + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } } -buildscript { - apply from: 'dependencies.gradle' +def reactNativeArchitectures() { + def value = rootProject.getProperties().get("reactNativeArchitectures") + return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] +} - repositories { - google() - jcenter() - } +def isNewArchitectureEnabled() { + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" +} - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } +apply plugin: "com.android.library" +apply plugin: "kotlin-android" +apply from: "jacoco.gradle" +apply from: 'dependencies.gradle' + +if (isNewArchitectureEnabled()) { + apply plugin: "com.facebook.react" +} + +def getExtOrDefault(name) { + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ComAdyenreactnativesdkModule_" + name] +} + +def getExtOrIntegerDefault(name) { + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ComAdyenreactnativesdkModule_" + name]).toInteger() } -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply from: 'jacoco.gradle' +def supportsNamespace() { + def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') + def major = parsed[0].toInteger() + def minor = parsed[1].toInteger() + + // Namespace support was added in 7.3.0 + return (major == 7 && minor >= 3) || major >= 8 +} android { + if (supportsNamespace()) { namespace "com.adyenreactnativesdk" - compileSdk safeExtGet('compileSdkVersion', 34) - defaultConfig { - minSdkVersion safeExtGet('minSdkVersion', 21) - targetSdkVersion safeExtGet('targetSdkVersion', 34) - versionCode 1 - versionName "1.0" - buildConfigField "String", "CHECKOUT_VERSION", "\"{SDK_VERSION}\"" - } - buildTypes { - release { - minifyEnabled false - } - } - lintOptions { - disable 'GradleCompatible' - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceSets { + main { + manifest.srcFile "src/main/AndroidManifestNew.xml" + } } - kotlinOptions { - jvmTarget = "1.8" + } + + compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") + + defaultConfig { + minSdkVersion getExtOrIntegerDefault("minSdkVersion") + targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") + buildConfigField "String", "CHECKOUT_VERSION", "\"{SDK_VERSION}\"" + } + + buildFeatures { + buildConfig true + } + + buildTypes { + release { + minifyEnabled false } + } + + lintOptions { + disable "GradleCompatible" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } repositories { - mavenLocal() - maven { - // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm - url("$rootDir/../node_modules/react-native/android") - } - google() - mavenCentral() - jcenter() + mavenCentral() + google() } +def kotlin_version = getExtOrDefault("kotlinVersion") + dependencies { - //noinspection GradleDynamicVersion - api "com.facebook.react:react-native:+" // From node_modules - implementation("com.adyen.checkout:drop-in:$adyen_version") { + // 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:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation("com.adyen.checkout:drop-in:$adyen_version") { exclude group:'androidx.lifecycle' } - implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" - implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version" + implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" + implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version" - //Tests - testImplementation testLibraries.json - testImplementation testLibraries.junit5 - testImplementation testLibraries.mockito -} + //Tests + testImplementation testLibraries.json + testImplementation testLibraries.junit5 + testImplementation testLibraries.mockito +} \ No newline at end of file diff --git a/android/dependencies.gradle b/android/dependencies.gradle index 64847a298..dd61f94cf 100644 --- a/android/dependencies.gradle +++ b/android/dependencies.gradle @@ -1,15 +1,4 @@ ext { - // SDK - compile_sdk_version = 34 - target_sdk_version = 34 - min_sdk_version = 21 - - // The version_name format is "major.minor.patch(-(alpha|beta|rc)[0-9]{2}){0,1}" (e.g. 3.0.0, 3.1.1-alpha04 or 3.1.4-rc01 etc). - version_name = "{SDK_VERSION}" - - // Build Script - kotlin_version = '1.9.24' - // Code quality jacoco_version = '0.8.12' diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 000000000..e1b0ef373 --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,4 @@ +ComAdyenreactnativesdkModule_kotlinVersion=1.9.24 +ComAdyenreactnativesdkModule_minSdkVersion=21 +ComAdyenreactnativesdkModule_targetSdkVersion=34 +ComAdyenreactnativesdkModule_compileSdkVersion=34 diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 686932b33..9bcc3b85b 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,4 +1,5 @@ diff --git a/android/src/main/AndroidManifestNew.xml b/android/src/main/AndroidManifestNew.xml new file mode 100644 index 000000000..686932b33 --- /dev/null +++ b/android/src/main/AndroidManifestNew.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/package.json b/package.json index f9f3310d4..effd6a1ff 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "typescript": "^5.0.2" }, "peerDependencies": { - "@types/react": "*", "expo": ">=47", "react": "*", "react-native": "*" diff --git a/scripts/set-version.sh b/scripts/set-version.sh index 959147c4e..1b679c97b 100755 --- a/scripts/set-version.sh +++ b/scripts/set-version.sh @@ -5,7 +5,7 @@ echo "Set Version" echo $VERSION IOS_PATH="ios/Version.swift" -ANDROID_PATH="android/dependencies.gradle" +ANDROID_PATH="android/build.gradle" if [[ "$OSTYPE" == "darwin"* ]]; then sed -i '' "s/{SDK_VERSION}/$VERSION/g" $IOS_PATH