group = "io.agora.agorartm.agora_rtm"
version = "1.0"

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

buildscript {
    repositories {
        google()
        mavenCentral()
    }

}

rootProject.allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

apply plugin: "com.android.library"

android {
    // Conditional for compatibility with AGP <4.2.
    if (project.android.hasProperty("namespace")) {
        namespace = "io.agora.agorartm.agora_rtm"
    }
    compileSdkVersion safeExtGet('compileSdkVersion', 34)

    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 21)

        consumerProguardFiles 'consumer-rules.pro'
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    sourceSets {
        if (isDev(project)) {
           println("Include libs/ to jniLibs.srcDirs for debugging.")
           main.jniLibs.srcDirs += 'libs'
        }
    }

    dependencies {
        testImplementation("junit:junit:4.13.2")
        testImplementation("org.mockito:mockito-core:5.0.0")
    }

    testOptions {
        unitTests.all {
            testLogging {
               events "passed", "skipped", "failed", "standardOut", "standardError"
               outputs.upToDateWhen {false}
               showStandardStreams = true
            }
        }
    }
}

dependencies {
  if (isDev(project)) {
    println("Include libs/*jar for debugging.")
    api fileTree(dir: "libs", include: ["*.jar"])
  } else {
    api 'io.agora.rtm:iris-rtm:2.2.5-build.2'
    api 'io.agora:agora-rtm:2.2.5'
  }
}

static boolean isDev(Project project) {
    def devFile = new File(project.projectDir, '../.plugin_dev')
    return devFile.exists()
}
