Skip to content

Commit

Permalink
Merge pull request #490 from Adyen/gradle-refactor
Browse files Browse the repository at this point in the history
Update build.gradle
  • Loading branch information
descorp authored Jul 11, 2024
2 parents 1758a9d + 0375ff3 commit 7c089f7
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 66 deletions.
146 changes: 93 additions & 53 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 0 additions & 11 deletions android/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
4 changes: 4 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ComAdyenreactnativesdkModule_kotlinVersion=1.9.24
ComAdyenreactnativesdkModule_minSdkVersion=21
ComAdyenreactnativesdkModule_targetSdkVersion=34
ComAdyenreactnativesdkModule_compileSdkVersion=34
1 change: 1 addition & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest
package="com.adyenreactnativesdk"
xmlns:android="http://schemas.android.com/apk/res/android">

<application>
Expand Down
8 changes: 8 additions & 0 deletions android/src/main/AndroidManifestNew.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<service android:name="com.adyenreactnativesdk.component.dropin.AdvancedCheckoutService" android:exported="false" />
<service android:name="com.adyenreactnativesdk.component.dropin.SessionCheckoutService" android:exported="false" />
</application>
</manifest>
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"typescript": "^5.0.2"
},
"peerDependencies": {
"@types/react": "*",
"expo": ">=47",
"react": "*",
"react-native": "*"
Expand Down
2 changes: 1 addition & 1 deletion scripts/set-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c089f7

Please sign in to comment.