import com.android.Version

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def isNewArchitectureEnabled() {
    return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

buildscript {
    repositories {
		google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10"
	}
}

apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'

if (isNewArchitectureEnabled()) {
    apply plugin: 'com.facebook.react'
}

android {
    compileSdkVersion safeExtGet('compileSdkVersion', 31)
    buildToolsVersion safeExtGet('buildToolsVersion', '31.0.3')

    if (project.android.hasProperty("namespace")) {
        namespace "com.dynatrace.android.agent"
    }

    def agpVersion = Version.ANDROID_GRADLE_PLUGIN_VERSION
    if (agpVersion.tokenize('.')[0].toInteger() >= 8) {
        buildFeatures {
            buildConfig = true
        }
    }

    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 21)
        targetSdkVersion safeExtGet('targetSdkVersion', 31)
        versionCode 1
        versionName "1.0"

        buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {
        main {
            if (isNewArchitectureEnabled()) {
                java.srcDirs += ['src/new']
            } else {
                java.srcDirs += ['src/old']
            }
        }
    }
}

repositories {
    google()
    mavenCentral()
}

dependencies {
	implementation 'com.dynatrace.agent:agent-android:8.337.3.1013'
    implementation "com.facebook.react:react-native:${safeExtGet('reactNative', '+')}"
}
  