buildscript {
    def kotlinGradleVersion = rootProject.ext.has("kotlinGradleVersion") ? rootProject.ext.get("kotlinGradleVersion") : "1.5.0"

    if(rootProject == project) {
        repositories {
            google()
            mavenCentral()
            gradlePluginPortal()
            /*maven {
                url "https://s3.amazonaws.com/android-listener/mvn-repo"
            }*/
        }
        dependencies {
            classpath "com.android.tools.build:gradle:4.2.2"
            classpath "com.google.gms:google-services:4.3.4"
            //use the version suggested by react-native-firebase
            //classpath "com.google.firebase:firebase-crashlytics-gradle:2.3.0"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinGradleVersion"
        }
    } else {
        repositories {
            mavenCentral()
        }

        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinGradleVersion"
        }
    }
}

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

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

publishing {
    publications {
        tareactnativeandroidopensettings(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-android-open-settings'
            version '1.3.0'
            artifact("$libsDirName/react-native-android-open-settings-release.aar")
        }

        tareactnativeappsettings(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-app-settings'
            version '2.0.1'
            artifact("$libsDirName/react-native-app-settings-release.aar")
        }

        tareactnativeasyncstorageasyncstorage(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-async-storage_async-storage'
            version '1.23.1'
            artifact("$libsDirName/react-native-async-storage_async-storage-release.aar")
        }

        tareactnativecolormatriximagefilters(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-color-matrix-image-filters'
            version '5.2.10'
            artifact("$libsDirName/react-native-color-matrix-image-filters-release.aar")
        }

        tareactnativecommunityart(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-community_art'
            version '1.2.0'
            artifact("$libsDirName/react-native-community_art-release.aar")
        }

        tareactnativecommunitydatetimepicker(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-community_datetimepicker'
            version '6.7.5'
            artifact("$libsDirName/react-native-community_datetimepicker-release.aar")
        }

        tareactnativecommunityimageeditor(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-community_image-editor'
            version '2.3.0'
            artifact("$libsDirName/react-native-community_image-editor-release.aar")
        }

        tareactnativecommunitynetinfo(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-community_netinfo'
            version '5.9.10'
            artifact("$libsDirName/react-native-community_netinfo-release.aar")
        }

        tareactnativecommunityslider(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-community_slider'
            version '2.0.9'
            artifact("$libsDirName/react-native-community_slider-release.aar")
        }

        tareactnativeconfig(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-config'
            version '1.4.11'
            artifact("$libsDirName/react-native-config-release.aar")
        }

        tareactnativecookiescookies(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-cookies_cookies'
            version '6.2.0'
            artifact("$libsDirName/react-native-cookies_cookies-release.aar")
        }

        tareactnativedarkmode(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-dark-mode'
            version '0.2.2'
            artifact("$libsDirName/react-native-dark-mode-release.aar")
        }

        tareactnativedeviceinfo(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-device-info'
            version '8.7.1'
            artifact("$libsDirName/react-native-device-info-release.aar")
        }

        tareactnativedynamicfonts(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-dynamic-fonts'
            version '0.3.2'
            artifact("$libsDirName/react-native-dynamic-fonts-release.aar")
        }

        tareactnativefastimage(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-fast-image'
            version '8.5.11'
            artifact("$libsDirName/react-native-fast-image-release.aar")
        }

        tareactnativefs(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-fs'
            version '2.20.0'
            artifact("$libsDirName/react-native-fs-release.aar")
        }

        tareactnativegesturehandler(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-gesture-handler'
            version '1.10.3'
            artifact("$libsDirName/react-native-gesture-handler-release.aar")
        }

        tareactnativehtmltopdf(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-html-to-pdf'
            version '0.12.0'
            artifact("$libsDirName/react-native-html-to-pdf-release.aar")
        }

        tareactnativeidletimer(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-idle-timer'
            version '2.1.6'
            artifact("$libsDirName/react-native-idle-timer-release.aar")
        }

        tareactnativeimagemarker(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-image-marker'
            version '0.9.2'
            artifact("$libsDirName/react-native-image-marker-release.aar")
        }

        tareactnativelineargradient(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-linear-gradient'
            version '2.8.3'
            artifact("$libsDirName/react-native-linear-gradient-release.aar")
        }

        tareactnativemail(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-mail'
            version '6.1.1'
            artifact("$libsDirName/react-native-mail-release.aar")
        }

        tareactnativepagerview(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-pager-view'
            version '6.1.4'
            artifact("$libsDirName/react-native-pager-view-release.aar")
        }

        tareactnativephotoviewex(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-photo-view-ex'
            version '1.1.0'
            artifact("$libsDirName/react-native-photo-view-ex-release.aar")
        }

        tareactnativereanimated(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-reanimated'
            version '1.13.3'
            artifact("$libsDirName/react-native-reanimated-release.aar")
        }

        tareactnativesafeareacontext(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-safe-area-context'
            version '3.3.2'
            artifact("$libsDirName/react-native-safe-area-context-release.aar")
        }

        tareactnativescreens(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-screens'
            version '3.13.1'
            artifact("$libsDirName/react-native-screens-release.aar")
        }

        tareactnativeshare(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-share'
            version '7.9.1'
            artifact("$libsDirName/react-native-share-release.aar")
        }

        tareactnativesplashscreen(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-splash-screen'
            version '3.2.0'
            artifact("$libsDirName/react-native-splash-screen-release.aar")
        }

        tareactnativesqlitestorage(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-sqlite-storage'
            version '3.3.10'
            artifact("$libsDirName/react-native-sqlite-storage-release.aar")
        }

        tareactnativesvg(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-svg'
            version '12.1.0'
            artifact("$libsDirName/react-native-svg-release.aar")
        }

        tareactnativetecnaviautils(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-tecnavia-utils'
            version '1.1.1'
            artifact("$libsDirName/react-native-tecnavia-utils-release.aar")
        }

        tareactnativetextsize(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-text-size'
            version '3.0.0'
            artifact("$libsDirName/react-native-text-size-release.aar")
        }

        tareactnativetts(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-tts'
            version '4.1.0'
            artifact("$libsDirName/react-native-tts-release.aar")
        }

        tareactnativeuuidgenerator(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-uuid-generator'
            version '6.1.1'
            artifact("$libsDirName/react-native-uuid-generator-release.aar")
        }

        tareactnativevectoricons(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-vector-icons'
            version '8.1.0'
            artifact("$libsDirName/react-native-vector-icons-release.aar")
        }

        tareactnativevideo(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-video'
            version '5.1.1'
            artifact("$libsDirName/react-native-video-release.aar")
        }

        tareactnativevolumecontrol(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-volume-control'
            version '1.0.1'
            artifact("$libsDirName/react-native-volume-control-release.aar")
        }

        tareactnativewebview(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native-webview'
            version '11.17.2'
            artifact("$libsDirName/react-native-webview-release.aar")
        }

        tarnfetchblob(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'rn-fetch-blob'
            version '0.11.2'
            artifact("$libsDirName/rn-fetch-blob-release.aar")
        }

        tatecnaviareactnativebridge(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'tecnavia_react-native-bridge'
            version '1.3.1'
            artifact("$libsDirName/tecnavia_react-native-bridge-release.aar")
        }

        tatecnaviareactnativedefaultpreference(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'tecnavia_react-native-default-preference'
            version '1.5.0'
            artifact("$libsDirName/tecnavia_react-native-default-preference-release.aar")
        }

        tatecnaviareactnativedfp(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'tecnavia_react-native-dfp'
            version '1.5.0'
            artifact("$libsDirName/tecnavia_react-native-dfp-release.aar")
        }

        tatecnaviareactnativegeolocation(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'tecnavia_react-native-geolocation'
            version '3.0.1'
            artifact("$libsDirName/tecnavia_react-native-geolocation-release.aar")
        }

        tatecnaviareactnativenavigationbarcolor(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'tecnavia_react-native-navigation-bar-color'
            version '2.0.2'
            artifact("$libsDirName/tecnavia_react-native-navigation-bar-color-release.aar")
        }

        tatecnaviareactnativepdf(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'tecnavia_react-native-pdf'
            version '5.1.6'
            artifact("$libsDirName/tecnavia_react-native-pdf-release.aar")
        }

        tatecnaviareactnativeprint(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'tecnavia_react-native-print'
            version '0.6.1'
            artifact("$libsDirName/tecnavia_react-native-print-release.aar")
        }

        tatecnaviareactnativewebanalytics(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'tecnavia_react-native-web-analytics'
            version '1.0.0'
            artifact("$libsDirName/tecnavia_react-native-web-analytics-release.aar")
        }

        tatecnaviareactnativeworkaround(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'tecnavia_react-native-workaround'
            version '0.0.2'
            artifact("$libsDirName/tecnavia_react-native-workaround-release.aar")
        }

        tatecnaviareactnativeziparchive(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'tecnavia_react-native-zip-archive'
            version '5.2.0'
            artifact("$libsDirName/tecnavia_react-native-zip-archive-release.aar")
        }

        tareactnative(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'react-native'
            version '0.67.5'
            artifact("$libsDirName/react-native-release.aar")
        }

        tahermes(MavenPublication) {
            groupId 'tecnavia'
            artifactId 'hermes'
            version '1.0.0'
            artifact("$libsDirName/hermes-release.aar")
        }

    }
}

afterEvaluate {
    tasks.clean.dependsOn("publishToMavenLocal")
    tasks.preBuild.dependsOn("publishToMavenLocal")
}

android {
    compileSdkVersion safeExtGet("compileSdkVersion", "33").toInteger()

    defaultConfig {
        targetSdkVersion safeExtGet("targetSdkVersion", "33").toInteger()
        minSdkVersion safeExtGet("minSdkVersion", "24").toInteger()
        versionName APP_VERSION_NAME
    }

    flavorDimensions "store"

    productFlavors {
        amazon {
            dimension "store"
        }

        play {
            dimension "store"
        }

        huawei {
            dimension "store"
        }
    }

    lintOptions {
        abortOnError false
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

        buildTypes.each {
            it.resValue 'string', 'APP_NAME', APP_NAME
            it.resValue 'string', 'APP_VERSION_NAME', APP_VERSION_NAME
            it.resValue 'string', 'APP_VERSION_CODE', APP_VERSION_CODE
            it.resValue 'string', 'ANDROID_APP_ID', ANDROID_APP_ID
            it.resValue 'string', 'IS_ADDON', IS_ADDON
        }
    }

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

repositories {
    mavenCentral()
    mavenLocal()
}

def frescoVersion = safeExtGet("frescoVersion", "2.5.0")
def soLoaderVersion = safeExtGet("soLoaderVersion","0.10.1")
def okHttpVersion = safeExtGet("okHttpVersion", "4.9.2")
def glideVersion = safeExtGet("glideVersion", "4.12.0")
def kotlinVersion = safeExtGet("kotlinVersion", "1.4.0")
def webkitVersion = safeExtGet("webkitVersion", "1.4.0")
def androidxVersion = safeExtGet("androidxVersion", "1.5.0")
def androidxWorkRuntimeVersion = safeExtGet("androidxWorkRuntimeVersion", "2.7.0")
def androidxAnnotationVersion = safeExtGet("androidxAnnotationVersion", "1.4.0")
def androidxViewpager2Version = safeExtGet("androidxViewpager2Version", "1.0.0")
def androidxFragmentVersion = safeExtGet("androidxFragmentVersion", "1.4.1")
def androidxBrowserVersion = safeExtGet("androidxBrowserVersion", "1.4.0")
def androidxTransitionVersion = safeExtGet("androidxTransitionVersion", "1.1.0")
def androidxCoordinatorlayoutVersion = safeExtGet("androidxCoordinatorlayoutVersion", "1.1.0")
def androidxSwiperefreshlayoutVersion = safeExtGet("androidxSwiperefreshlayoutVersion", "1.0.0")
def androidxAppcompatVersion = safeExtGet("androidxAppcompatVersion", "1.0.2")
def androidxLegacySupportVersion = safeExtGet("androidxLegacySupportVersion", "1.0.0")
def playServiceiidVersion = safeExtGet("playServiceiidVersion", "17.0.0")
def playServiceBaseVersion = safeExtGet("playServiceBaseVersion", "18.0.1")
def playServiceAnalyticsVersion = safeExtGet("playServiceAnalyticsVersion", "18.0.1")
def playServiceAdsVersion = safeExtGet("playServiceAdsVersion", "20.2.0")
def playServiceMapsVersion = safeExtGet("playServiceMapsVersion", "17.0.0")
def playBillingVersion = safeExtGet("playBillingVersion", "5.0.0")
def amazonSdkVersion = safeExtGet("amazonSdkVersion", "3.0.3")

dependencies {
    implementation "tecnavia:react-native-android-open-settings:1.3.0"
    implementation "tecnavia:react-native-app-settings:2.0.1"
    implementation "tecnavia:react-native-async-storage_async-storage:1.23.1"
    implementation "tecnavia:react-native-color-matrix-image-filters:5.2.10"
    implementation "tecnavia:react-native-community_art:1.2.0"
    implementation "tecnavia:react-native-community_datetimepicker:6.7.5"
    implementation "tecnavia:react-native-community_image-editor:2.3.0"
    implementation "tecnavia:react-native-community_netinfo:5.9.10"
    implementation "tecnavia:react-native-community_slider:2.0.9"
    implementation "tecnavia:react-native-config:1.4.11"
    implementation "tecnavia:react-native-cookies_cookies:6.2.0"
    implementation "tecnavia:react-native-dark-mode:0.2.2"
    implementation "tecnavia:react-native-device-info:8.7.1"
    implementation "tecnavia:react-native-dynamic-fonts:0.3.2"
    implementation "tecnavia:react-native-fast-image:8.5.11"
    implementation "tecnavia:react-native-fs:2.20.0"
    implementation "tecnavia:react-native-gesture-handler:1.10.3"
    implementation "tecnavia:react-native-html-to-pdf:0.12.0"
    implementation "tecnavia:react-native-idle-timer:2.1.6"
    implementation "tecnavia:react-native-image-marker:0.9.2"
    implementation "tecnavia:react-native-linear-gradient:2.8.3"
    implementation "tecnavia:react-native-mail:6.1.1"
    implementation "tecnavia:react-native-pager-view:6.1.4"
    implementation "tecnavia:react-native-photo-view-ex:1.1.0"
    implementation "tecnavia:react-native-reanimated:1.13.3"
    implementation "tecnavia:react-native-safe-area-context:3.3.2"
    implementation "tecnavia:react-native-screens:3.13.1"
    implementation "tecnavia:react-native-share:7.9.1"
    implementation "tecnavia:react-native-splash-screen:3.2.0"
    implementation "tecnavia:react-native-sqlite-storage:3.3.10"
    implementation "tecnavia:react-native-svg:12.1.0"
    implementation "tecnavia:react-native-tecnavia-utils:1.1.1"
    implementation "tecnavia:react-native-text-size:3.0.0"
    implementation "tecnavia:react-native-tts:4.1.0"
    implementation "tecnavia:react-native-uuid-generator:6.1.1"
    implementation "tecnavia:react-native-vector-icons:8.1.0"
    implementation "tecnavia:react-native-video:5.1.1"
    implementation "tecnavia:react-native-volume-control:1.0.1"
    implementation "tecnavia:react-native-webview:11.17.2"
    implementation "tecnavia:rn-fetch-blob:0.11.2"
    api "tecnavia:tecnavia_react-native-bridge:1.3.1"
    implementation "tecnavia:tecnavia_react-native-default-preference:1.5.0"
    implementation "tecnavia:tecnavia_react-native-dfp:1.5.0"
    implementation "tecnavia:tecnavia_react-native-geolocation:3.0.1"
    implementation "tecnavia:tecnavia_react-native-navigation-bar-color:2.0.2"
    implementation "tecnavia:tecnavia_react-native-pdf:5.1.6"
    implementation "tecnavia:tecnavia_react-native-print:0.6.1"
    implementation "tecnavia:tecnavia_react-native-web-analytics:1.0.0"
    implementation "tecnavia:tecnavia_react-native-workaround:0.0.2"
    implementation "tecnavia:tecnavia_react-native-zip-archive:5.2.0"
    api "tecnavia:react-native:0.67.5"
    implementation "tecnavia:hermes:1.0.0"

    
    //the below dependencies works, if you change the versions something could not work well
    implementation "org.webkit:android-jsc:+"
    //androidx dependencies
    implementation "javax.inject:javax.inject:1"
    implementation "androidx.autofill:autofill:1.1.0"
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation "androidx.viewpager2:viewpager2:$androidxViewpager2Version"
    implementation "androidx.work:work-runtime-ktx:$androidxWorkRuntimeVersion"
    implementation "androidx.appcompat:appcompat:$androidxAppcompatVersion"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:$androidxSwiperefreshlayoutVersion"
    implementation "androidx.webkit:webkit:$webkitVersion"
    implementation "androidx.fragment:fragment:$androidxFragmentVersion"
    implementation "androidx.core:core-ktx:$androidxVersion"
    implementation "androidx.transition:transition:$androidxTransitionVersion"
    implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorlayoutVersion"
    implementation "androidx.core:core:$androidxVersion"
    implementation "androidx.annotation:annotation:$androidxAnnotationVersion" //used by iap
    implementation "androidx.browser:browser:$androidxBrowserVersion" //used by iap
    annotationProcessor "com.android.support:support-annotations:28.0.0"
    //build dependencies
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    //facebook react-native dependencies
    implementation "com.facebook.infer.annotation:infer-annotation:0.18.0"
    implementation "com.facebook.yoga:proguard-annotations:1.19.0"
    implementation "com.facebook.fresco:fresco:$frescoVersion"
    implementation "com.facebook.fresco:imagepipeline-okhttp3:$frescoVersion"
    implementation "com.facebook.fresco:ui-common:$frescoVersion"
    implementation "com.facebook.soloader:soloader:$soLoaderVersion"
    implementation "com.facebook.fbjni:fbjni-java-only:0.2.2"
    //google dependencies
    implementation "com.google.code.findbugs:jsr305:3.0.2"
    implementation "com.google.code.gson:gson:2.8.5"
    //used by react-native-device-info package
    //update core with the same values in react-native-firebase
    implementation "com.google.android.gms:play-services-iid:$playServiceiidVersion" 
    //used by react-native-maps and react-native-iap packages
    //update core with the same values in react-native-firebase
    implementation "com.google.android.gms:play-services-base:$playServiceBaseVersion" 
    //used by react-native-google-analytics-bridge ga3
    //try to use the same version of firebase-core
    
    //use the same version of play-services-analytics
    
    //used by react-native-prebid, react-native-admob and react-native-dfp packages
    implementation "com.google.android.gms:play-services-ads:$playServiceAdsVersion"
    //used by react-native-maps package
    
    
    //used by @firebase/app
    
    
    
    //firebase
    
    
    
    
    
    
    //okhttp
    implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
    implementation "com.squareup.okhttp3:okhttp-urlconnection:$okHttpVersion"
    implementation "com.squareup.okio:okio:2.9.0"
    //glide dependencies
    implementation "com.github.bumptech.glide:annotations:$glideVersion"
    implementation "com.github.bumptech.glide:glide:$glideVersion"
    implementation "com.github.bumptech.glide:okhttp3-integration:$glideVersion"
    annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
    //others
    implementation "net.lingala:zip4j:1.3.3"
    implementation "com.jakewharton.timber:timber:4.7.1"
    implementation "me.relex:photodraweeview:1.1.3"
    implementation "com.yqritc:android-scalablevideoview:1.0.4"
}
