summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/build.gradle
blob: 510dc79d4317f71c058ce250444848efad2da89f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
apply plugin: 'com.android.library'
apply plugin: "com.jaredsburrows.license"
apply plugin: 'kotlin-android'

dependencies {
    lintChecks project(":MapboxGLAndroidSDKLint")
    api dependenciesList.mapboxAndroidTelemetry
    api dependenciesList.mapboxJavaGeoJSON
    api dependenciesList.mapboxAndroidGestures
    api dependenciesList.mapboxAndroidAccounts
    implementation dependenciesList.mapboxJavaTurf
    implementation dependenciesList.supportAnnotations
    implementation dependenciesList.supportFragmentV4
    implementation dependenciesList.okhttp3
    implementation dependenciesList.reLinker
    testImplementation dependenciesList.junit
    testImplementation dependenciesList.mockito
    testImplementation dependenciesList.mockk
    testImplementation dependenciesList.robolectric
    testImplementation dependenciesList.kotlinLib
    testImplementation dependenciesList.commonsIO
}

android {
    compileSdkVersion androidVersions.compileSdkVersion

    defaultConfig {
        minSdkVersion androidVersions.minSdkVersion
        targetSdkVersion androidVersions.targetSdkVersion
        buildConfigField "String", "GIT_REVISION_SHORT", String.format("\"%s\"", getGitRevision())
        buildConfigField "String", "MAPBOX_SDK_IDENTIFIER", String.format("\"%s\"", "mapbox-maps-android")
        buildConfigField "String", "MAPBOX_SDK_VERSION", String.format("\"%s\"", project.VERSION_NAME)
        buildConfigField "String", "MAPBOX_VERSION_STRING", String.format("\"Mapbox/%s\"", project.VERSION_NAME)
        buildConfigField "String", "MAPBOX_EVENTS_USER_AGENT", String.format("\"mapbox-maps-android/%s\"", project.VERSION_NAME)
    }

    defaultPublishConfig project.hasProperty("mapbox.buildtype") ? project.getProperty("mapbox.buildtype") : "debug"

    // We sometimes want to invoke Gradle without building a native dependency, e.g. when we just want
    // to invoke the Java tests. When we explicitly specify an ABI of 'none', no native dependencies are
    // added. When another ABI is specified explicitly, we're just going to build that ABI. In all other
    // cases, all ABIs are built.
    //
    // When invoking from the command line or to override the device default, set `-Pmapbox.abis=...` to
    // only build the desired architectures.
    //
    // When building from Android Studio, gradle.properties sets `android.buildOnlyTargetAbi=true` so that
    // only the architecture for the device you're running on gets built.
    def abi = 'all'
    if (!project.hasProperty('android.injected.invoked.from.ide') || project.hasProperty("mapbox.abis")) {
        // Errors when the user invokes Gradle from the command line and didn't set mapbox.abis
        abi = project.getProperty("mapbox.abis")
    }

    if (abi != 'none') {
        externalNativeBuild {
            cmake {
                path "../../../CMakeLists.txt"
                version "3.10.2"
            }
        }
    }

    // Allow determining the C++ STL we're using when building Mapbox GL.
    def stl = 'c++_static'
    if (project.hasProperty("mapbox.stl")) {
        stl = project.getProperty("mapbox.stl")
    }

    defaultConfig {
        if (abi != 'none') {
            externalNativeBuild {
                cmake {
                    arguments "-DANDROID_TOOLCHAIN=clang"
                    arguments "-DANDROID_STL=" + stl
                    arguments "-DANDROID_CPP_FEATURES=exceptions"
                    arguments "-DMBGL_PLATFORM=android"
                    arguments "-DMASON_PLATFORM=android"
                    arguments "-DNodeJS_EXECUTABLE=" + node
                    arguments "-Dnpm_EXECUTABLE=" + npm

                    // Enable ccache if the user has installed it.
                    if (ccache?.trim()) {
                        arguments "-DANDROID_CCACHE=" + ccache
                    }

                    cFlags "-Qunused-arguments"
                    cppFlags "-Qunused-arguments"

                    targets "mapbox-gl"

                    if (defaultPublishConfig.equalsIgnoreCase("debug")) {
                        targets "example-custom-layer"
                    }

                    if (project.hasProperty("mapbox.with_test")) {
                        targets "mbgl-test"
                    }

                    if (project.hasProperty("mapbox.with_benchmark")) {
                        targets "mbgl-benchmark"
                    }

                    if (abi != 'all') {
                        abiFilters abi.split(' ')
                    } else {
                        abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
                    }
                }
            }
        }

        // proguard config for .aar
        consumerProguardFiles 'proguard-rules.pro'
    }

    // avoid naming conflicts, force usage of prefix
    resourcePrefix 'mapbox_'

    sourceSets {
        // limit amount of exposed library resources
        main.res.srcDirs += 'src/main/res-public'
    }

    lintOptions {
        disable 'MissingTranslation', 'TypographyQuotes', 'ObsoleteLintCustomCheck', 'MissingPermission', 'WrongThreadInterprocedural'
        checkAllWarnings true
        warningsAsErrors false
    }

    testOptions {
        unitTests {
            returnDefaultValues true

            // Roboelectric 4.0 required config
            // http://robolectric.org/migrating/#migrating-to-40
            includeAndroidResources = true
        }
    }

    buildTypes {
        debug {
            testCoverageEnabled true
            jniDebuggable true
        }
    }
}

licenseReport {
    generateHtmlReport = false
    generateJsonReport = true
    copyHtmlReportToAssets = false
    copyJsonReportToAssets = false
}

def static getGitRevision() {
    def cmd = "git rev-parse --short HEAD"
    def proc = cmd.execute()
    def ref = proc.text.trim()
    return ref
}

configurations {
    all*.exclude group: 'commons-logging', module: 'commons-logging'
    all*.exclude group: 'commons-collections', module: 'commons-collections'
}

apply from: "${rootDir}/gradle/gradle-javadoc.gradle"
apply from: "${rootDir}/gradle/gradle-checkstyle.gradle"
apply from: "${rootDir}/gradle/gradle-dependencies-graph.gradle"
apply from: "${rootDir}/gradle/gradle-update-vendor-modules.gradle"
apply from: "${rootDir}/gradle/android-nitpick.gradle"
apply from: "${rootDir}/gradle/gradle-bintray.gradle"
apply from: "${rootDir}/gradle/jacoco-report.gradle"