build.gradle 8.14 KB
Newer Older
Geoffrey Métais's avatar
Geoffrey Métais committed
1
apply plugin: 'com.android.application'
Geoffrey Métais's avatar
Geoffrey Métais committed
2 3
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
Geoffrey Métais's avatar
Geoffrey Métais committed
4 5

android {
Geoffrey Métais's avatar
Geoffrey Métais committed
6 7 8
    packagingOptions {
    }

9 10
    dexOptions {
        maxProcessCount 8
11
        javaMaxHeapSize "2g"
12 13 14
        preDexLibraries true
    }

15 16
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
Geoffrey Métais's avatar
Geoffrey Métais committed
17

18
    flavorDimensions "target", "abi"
19

Geoffrey Métais's avatar
Geoffrey Métais committed
20
    lintOptions {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
21 22
        abortOnError false
        disable 'MissingTranslation', 'ExtraTranslation'
Geoffrey Métais's avatar
Geoffrey Métais committed
23 24
    }

25 26 27 28 29 30 31 32 33 34 35 36
    task luaPlaylistCopy(type: Copy) {
        from '../vlc/share/lua/playlist'
        into 'assets/lua/playlist'
        exclude '**/*.txt'
    }

    task luaMetaCopy(type: Copy) {
        from '../vlc/share/lua/meta'
        into 'assets/lua/meta'
        exclude '**/*.txt'
    }

37 38 39 40
    dataBinding {
        enabled = true
    }

Geoffrey Métais's avatar
Geoffrey Métais committed
41 42
    defaultConfig {
        applicationId "org.videolan.vlc"
43

44 45
        resValue "string", "build_time", buildTime()
        resValue "string", "build_host", hostName()
46
        resValue "string", "build_revision", revision()
Geoffrey Métais's avatar
Geoffrey Métais committed
47
        resValue "string", "build_vlc_revision", vlcRevision()
48

49 50 51 52
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName
Geoffrey Métais's avatar
Geoffrey Métais committed
53

54
        tasks.whenTaskAdded { task ->
Thomas Guillem's avatar
Thomas Guillem committed
55
            if (task.name.startsWith('merge')) {
56 57 58 59 60
                task.dependsOn luaPlaylistCopy
                task.dependsOn luaMetaCopy
            }
        }

61
        //Set the build ABI according to build types only if not launched from compile.sh
62
        if (System.getenv('CLI') == null)
63 64
            tasks.whenTaskAdded { task ->
                if (task.name.startsWith('assemble')) {
Thomas Guillem's avatar
Thomas Guillem committed
65
                    if (task.name.endsWith('ARMv7Debug'))
66 67 68 69 70 71 72 73 74 75 76 77
                        task.dependsOn(":libvlc:buildDebugARMv7")
                    else if (task.name.endsWith('ARMv8Debug'))
                        task.dependsOn(":libvlc:buildDebugARM64")
                    else if (task.name.endsWith('X86Debug'))
                        task.dependsOn(":libvlc:buildDebugx86")
                    else if (task.name.endsWith('X86_64Debug'))
                        task.dependsOn(":libvlc:buildDebugx86_64")
                    else if (task.name.endsWith('MIPSDebug'))
                        task.dependsOn(":libvlc:buildDebugMIPS")
                    else if (task.name.endsWith('MIPS64Debug'))
                        task.dependsOn(":libvlc:buildDebugMIPS64")
                }
78
            }
Geoffrey Métais's avatar
Geoffrey Métais committed
79 80
    }

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    signingConfigs {
        release {
            /*
            To set this properties, create file gradle.properties with these 3 props.
            e.g.
            keyStoreFile=/home/<username>/.android/debug.keystore
            storealias=androiddebugkey
            storepwd=android
             */
            storeFile file(keyStoreFile)
            keyAlias storealias
            if (System.getenv('PASSWORD_KEYSTORE') != null && !System.getenv('PASSWORD_KEYSTORE').isEmpty()){
                storePassword = System.getenv('PASSWORD_KEYSTORE')
                keyPassword = System.getenv('PASSWORD_KEYSTORE')
            } else {
                storePassword storepwd
                keyPassword storepwd
            }
        }
    }

Geoffrey Métais's avatar
Geoffrey Métais committed
102 103
    buildTypes {
        release {
104
            signingConfig null
105
            minifyEnabled true
106
            shrinkResources false
107
            proguardFile 'proguard.cfg'
Geoffrey Métais's avatar
Geoffrey Métais committed
108
        }
109 110 111
        signedRelease {
            initWith release
            signingConfig = signingConfigs.release
Geoffrey Métais's avatar
Geoffrey Métais committed
112
            matchingFallbacks = ['release']
113
        }
Geoffrey Métais's avatar
Geoffrey Métais committed
114 115
        debug {
            applicationIdSuffix ".debug"
116
            jniDebuggable true
Geoffrey Métais's avatar
Geoffrey Métais committed
117
        }
Geoffrey Métais's avatar
Geoffrey Métais committed
118
    }
119
    productFlavors {
120 121 122 123 124 125 126 127 128
        vanilla {
            dimension "target"
            versionCode = 1
        }
        chrome {
            minSdkVersion 19
            dimension "target"
            versionCode = 2
        }
129
        ARMv7 {
130
            dimension "abi"
131 132 133
            versionCode = 4
        }
        x86 {
134
            dimension "abi"
135
            versionCode = 5
136
        }
137
        MIPS {
138
            dimension "abi"
139 140 141
            versionCode = 6
        }
        ARMv8 {
142
            dimension "abi"
143 144 145
            versionCode = 7
        }
        x86_64 {
146
            dimension "abi"
147 148 149
            versionCode = 8
        }
        MIPS64 {
150
            dimension "abi"
151 152 153 154 155 156
            versionCode = 9
        }
    }

    // make per-variant version code
    applicationVariants.all { variant ->
157 158

        //Custom APK name
Geoffrey Métais's avatar
Geoffrey Métais committed
159
        variant.outputs.all { output ->
160 161 162 163
            def outputName = "VLC-Android-"
            if (variant.productFlavors.get(0).name != "vanilla")
                outputName += variant.productFlavors.get(0).name.toUpperCase() + "-"
            outputName += variant.versionName + "-" + variant.productFlavors.get(1).name + ".apk"
Geoffrey Métais's avatar
Geoffrey Métais committed
164
            outputFileName = outputName
165 166 167 168 169 170 171 172 173
            output.processManifest.doLast {
                // set the composite code
                def generatedCode = variant.productFlavors.get(0).versionCode * 10000000 + defaultConfig.versionCode + variant.productFlavors.get(1).versionCode
                String manifestPath = "$manifestOutputDirectory/AndroidManifest.xml"
                def manifestContent = file(manifestPath).getText()
                manifestContent = manifestContent.replace('android:versionCode="1"',
                        String.format('android:versionCode="%s"', generatedCode))
                file(manifestPath).write(manifestContent)
            }
174
        }
175 176 177 178 179 180 181 182 183 184 185
    }

    sourceSets.main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }
186
    sourceSets.release {
187
        manifest.srcFile 'flavors/release/AndroidManifest.xml'
188
    }
189 190 191
    sourceSets.debug {
        res.srcDirs = ['flavors/debug/res']
    }
192 193 194
    sourceSets.test {
        java.srcDirs = ['test']
    }
195 196 197 198
    sourceSets.chrome {
        manifest.srcFile 'flavors/chrome/AndroidManifest.xml'
        res.srcDirs = ['flavors/chrome/res']
    }
Geoffrey Métais's avatar
Geoffrey Métais committed
199 200
}

201 202 203 204 205
task generateSources (type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

Geoffrey Métais's avatar
Geoffrey Métais committed
206
dependencies {
Geoffrey Métais's avatar
Geoffrey Métais committed
207 208 209 210
    implementation project(':libvlc')
    implementation project(':medialibrary')
    implementation project(':api')
    implementation project(':axmlrpc')
Geoffrey Métais's avatar
Geoffrey Métais committed
211
    // AppCompat
Geoffrey Métais's avatar
Geoffrey Métais committed
212 213 214 215 216 217 218 219
    implementation "com.android.support:recyclerview-v7:$rootProject.ext.appCompatVersion"
    implementation "com.android.support:design:$rootProject.ext.appCompatVersion"
    implementation "com.android.support:support-annotations:$rootProject.ext.appCompatVersion"
    implementation "com.android.support:preference-v7:$rootProject.ext.appCompatVersion"
    implementation "com.android.support:leanback-v17:$rootProject.ext.appCompatVersion"
    implementation "com.android.support:preference-leanback-v17:$rootProject.ext.appCompatVersion"
    implementation "com.android.support.constraint:constraint-layout:$rootProject.ext.constraintLayoutVersion"
    testImplementation 'junit:junit:4.12'
Geoffrey Métais's avatar
Geoffrey Métais committed
220 221 222 223 224 225 226 227 228 229 230
    // Kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    kapt "com.android.databinding:compiler:$rootProject.ext.android_plugin_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.ext.kotlinx_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.ext.kotlinx_version"
}

kotlin {
    experimental {
        coroutines "enable"
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
231
}
232

233
static def buildTime() {
234 235 236
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}

237
static def hostName() {
238
    return System.getProperty("user.name") + "@" + InetAddress.localHost.hostName
239 240 241 242 243 244 245 246
}

def revision() {
    def code = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-parse', '--short', 'HEAD'
        standardOutput = code
    }
Geoffrey Métais's avatar
Geoffrey Métais committed
247 248 249 250 251
    return code.toString()
}

def vlcRevision() {
    def vlc = new ByteArrayOutputStream()
252 253 254 255 256
    exec {
        commandLine 'git', 'rev-parse', '--short', 'HEAD'
        workingDir '../vlc'
        standardOutput = vlc
    }
Geoffrey Métais's avatar
Geoffrey Métais committed
257
    return vlc.toString()
258
}