apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
  compileSdkVersion Config.compileSdkVersion
  buildToolsVersion Config.buildToolsVersion

  defaultConfig {
    minSdkVersion Config.minSdkVersion
    targetSdkVersion Config.targetSdkVersion
    missingDimensionStrategy 'abi', 'abi_all', 'abi_arm', 'abi_arm64', 'abi_x86'
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  }

  packagingOptions {
    exclude 'META-INF/proguard/androidx-annotations.pro'
  }

  sourceSets {
    test.java.srcDirs += 'src/test/kotlin'
    androidTest.java.srcDirs += 'src/androidTest/kotlin'
  }

  useLibrary 'android.test.runner'
  useLibrary 'android.test.base'

  gradle.projectsEvaluated {
    preBuild.dependsOn(copyDefaultSubscriptions)
  }
}

bintray {
  pkg {
    desc="An Android library that provides a configuration interface for Adblock Plus."
  }
}

dependencies {
  api project(':adblock-android')
  api Deps.androidx_preference
  testImplementation Deps.junit4
  testImplementation Deps.kotlin_stdlib
  androidTestImplementation Deps.kotlin_stdlib
  androidTestImplementation Deps.androidx_test_core
  androidTestImplementation Deps.androidx_test_runner
  androidTestImplementation Deps.androidx_test_ext_junit
}

task copyDefaultSubscriptions (type: org.gradle.api.tasks.Copy) {
  from "$rootDir/libadblockplus/adblockpluscore/data/"
  into "./src/main/res/raw/"
  include "subscriptions.json"
}

gradle.taskGraph.afterTask { task ->
  if(task.state.noSource && task.name == 'copyDefaultSubscriptions'){
    throw new GradleException("${task.path} failed. Please check that libadblockplus\\adblockpluscore is checked out.")
  }
}
