buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.3'
    }
}

apply plugin: 'com.android.library'

def getExtOrDefault(name, fallback) {
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : fallback
}

android {
    // Check AGP version for backward compatibility w/react-native versions still on gradle plugin 6
    // it looks like this causes issues between 7 and 8, so for the time being 
    def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION    
    if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
        namespace = "kjd.reactnative.bluetooth"
    }
    
    compileSdkVersion getExtOrDefault('compileSdkVersion', 34)
    buildToolsVersion getExtOrDefault('buildToolsVersion', "34.0.0")

    defaultConfig {
        minSdkVersion getExtOrDefault('minSdkVersion', 16)
        targetSdkVersion getExtOrDefault('targetSdkVersion', 34)
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
    sourceSets { main { java.srcDirs = ['src/main/java', 'src/main/tests'] } }

    testOptions {
        unitTests.returnDefaultValues = true
    }
}

repositories {
    mavenCentral()
    google()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
}

dependencies {
    implementation 'com.facebook.react:react-native:0.71.0-rc.0'

    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.mockito:mockito-core:4.0.0'
    testImplementation group: 'org.powermock', name: 'powermock-core', version: '1.6.6'
    testImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: '1.6.6'
    testImplementation group: 'org.powermock', name: 'powermock-api-mockito', version: '1.6.6'

}
