buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:1.1.3'
    classpath files ('libs/gradle-witness.jar')
  }
}

apply plugin: 'com.android.application'
apply plugin: 'witness'

android {
  compileSdkVersion 23
  buildToolsVersion "23.0.3"

  defaultConfig {
    applicationId "com.duckduckgo.mobile.android"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 101
    versionName "3.1.1"
  }

  repositories {
    mavenCentral()
  }

  dependencies {
    compile 'ch.acra:acra:4.5.0'
    compile ('com.android.support:recyclerview-v7:23.1.1') {
      exclude module: 'support-v4'
      exclude module: 'support-annotations'
    }
    compile 'com.squareup:otto:1.3.8'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile project(':libs:OnionKit:libnetcipher')
    compile ('com.android.support:appcompat-v7:23.1.1') {
      exclude module: 'support-v4'
    }
    compile project(':libs:android-support-v4-preferencefragment')
  }

  dependencyVerification {
    verify = [
            'ch.acra:acra:b46be215fefd703fe91bd8c2a9f59ba87f28924316c556468c5e6141d1fc87a7',
            'com.android.support:recyclerview-v7:7606373da0931a1e62588335465a0e390cd676c98117edab29220317495faefd',
            'com.squareup:otto:13e2c8f5782de514cb161a1e03cdf394a6933431ce1aa2391f6289005b5a250c',
            'com.squareup.picasso:picasso:233e18f59d25b6aff475df1e01a0661677f88af73838a27eb23aa21b96a3ac6e',
            'com.android.support:appcompat-v7:0a8762214382b7e8d4b989b4ac10b5c846b957d767ccb7bccbc6be5afa885a82',
    ]
  }

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      java.srcDirs = ['src']
      resources.srcDirs = ['src']
      aidl.srcDirs = ['src']
      renderscript.srcDirs = ['src']
      res.srcDirs = ['res']
      assets.srcDirs = ['assets']
    }
  }

  signingConfigs {
    release
  }

  buildTypes {
    debug {
      debuggable true
      jniDebuggable true
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    release {
      signingConfig signingConfigs.release
    }
  }

  lintOptions {
    abortOnError false
  }

  applicationVariants.all { variant ->
    variant.outputs.each { output ->
      def alignedOutputFile = output.outputFile

      if (variant.buildType.zipAlignEnabled) {
        if(variant.buildType.name.contains("release")) {
          output.outputFile = new File(alignedOutputFile.parent, "DuckDuckGo-release.apk")
        } else if(variant.buildType.name.contains("debug")) {
          output.outputFile = new File(alignedOutputFile.parent, "DuckDuckGo-debug.apk")
        }
      }
    }
  }

  def Properties props = new Properties()
  def propFile = new File('/Users/jenkins/jenkins_static/duckduckgo_android/ddg_android_build.properties')
  if (propFile.exists()){
      props.load(new FileInputStream(propFile))

    if (props!=null && props.containsKey('key.store') && props.containsKey('key.store.password') &&
        props.containsKey('key.alias') && props.containsKey('key.alias.password')) {
      android.signingConfigs.release.storeFile = file(props['key.store'])
      android.signingConfigs.release.storePassword = props['key.store.password']
      android.signingConfigs.release.keyAlias = props['key.alias']
      android.signingConfigs.release.keyPassword = props['key.alias.password']
    } else {
      println 'signing.properties found but some entries are missing'
      android.buildTypes.release.signingConfig = null
    }
  } else {
    println 'signing.properties not found'
    android.buildTypes.release.signingConfig = null
  }
}
