build.gradle 7.27 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 {
6
    packagingOptions {
7
        exclude 'META-INF/main.kotlin_module'
8 9
    }

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

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

19
    flavorDimensions "target", "abi"
20

Geoffrey Métais's avatar
Geoffrey Métais committed
21
    lintOptions {
22 23
        abortOnError false
        disable 'MissingTranslation', 'ExtraTranslation'
Geoffrey Métais's avatar
Geoffrey Métais committed
24 25
    }

26 27 28 29 30 31 32 33 34 35 36 37
    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'
    }

38 39 40 41
    dataBinding {
        enabled = true
    }

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

45 46
        resValue "string", "build_time", buildTime()
        resValue "string", "build_host", hostName()
47
        resValue "string", "build_revision", revision()
48
        resValue "string", "build_vlc_revision", vlcRevision()
49

50 51 52 53
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName
54

55
        tasks.whenTaskAdded { task ->
56
            if (task.name.startsWith('merge')) {
57 58 59 60
                task.dependsOn luaPlaylistCopy
                task.dependsOn luaMetaCopy
            }
        }
Geoffrey Métais's avatar
Geoffrey Métais committed
61 62
    }

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    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
84 85
    buildTypes {
        release {
86
            signingConfig null
87
            minifyEnabled true
88
            shrinkResources false
89
            proguardFile 'proguard.cfg'
Geoffrey Métais's avatar
Geoffrey Métais committed
90
        }
91 92 93
        signedRelease {
            initWith release
            signingConfig = signingConfigs.release
Geoffrey Métais's avatar
Geoffrey Métais committed
94
            matchingFallbacks = ['release']
95
        }
96 97
        debug {
            applicationIdSuffix ".debug"
98
            jniDebuggable true
99
        }
Geoffrey Métais's avatar
Geoffrey Métais committed
100
    }
101
    productFlavors {
102 103 104 105 106 107 108 109 110
        vanilla {
            dimension "target"
            versionCode = 1
        }
        chrome {
            minSdkVersion 19
            dimension "target"
            versionCode = 2
        }
111
        ARMv7 {
112
            dimension "abi"
113 114 115
            versionCode = 4
        }
        x86 {
116
            dimension "abi"
117
            versionCode = 5
118
        }
119
        MIPS {
120
            dimension "abi"
121 122 123
            versionCode = 6
        }
        ARMv8 {
124
            dimension "abi"
125 126 127
            versionCode = 7
        }
        x86_64 {
128
            dimension "abi"
129 130 131
            versionCode = 8
        }
        MIPS64 {
132
            dimension "abi"
133 134 135 136 137 138
            versionCode = 9
        }
    }

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

140 141
        def generatedCode = variant.productFlavors.get(0).versionCode * 10000000 + defaultConfig.versionCode + variant.productFlavors.get(1).versionCode
        variant.mergedFlavor.versionCode = generatedCode
142
        //Custom APK name
Geoffrey Métais's avatar
Geoffrey Métais committed
143
        variant.outputs.all { output ->
144 145 146 147
            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
148
            outputFileName = outputName
149 150 151 152 153 154 155 156
            output.processManifest.doLast {
                // set the composite code
                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)
            }
157
        }
158 159 160 161 162 163 164 165 166 167 168
    }

    sourceSets.main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }
169
    sourceSets.release {
170
        manifest.srcFile 'flavors/release/AndroidManifest.xml'
171
    }
172 173 174
    sourceSets.debug {
        res.srcDirs = ['flavors/debug/res']
    }
175 176 177
    sourceSets.test {
        java.srcDirs = ['test']
    }
178 179 180 181
    sourceSets.chrome {
        manifest.srcFile 'flavors/chrome/AndroidManifest.xml'
        res.srcDirs = ['flavors/chrome/res']
    }
Geoffrey Métais's avatar
Geoffrey Métais committed
182 183
}

184 185 186 187 188
task generateSources (type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

Geoffrey Métais's avatar
Geoffrey Métais committed
189
dependencies {
Geoffrey Métais's avatar
Geoffrey Métais committed
190 191 192 193
    implementation project(':libvlc')
    implementation project(':medialibrary')
    implementation project(':api')
    implementation project(':axmlrpc')
Geoffrey Métais's avatar
Geoffrey Métais committed
194
    // AppCompat
195
    kapt 'com.android.databinding:compiler:3.0.1'
Geoffrey Métais's avatar
Geoffrey Métais committed
196 197 198 199 200 201 202 203
    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
204
    // Kotlin
205
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Geoffrey Métais's avatar
Geoffrey Métais committed
206 207 208 209 210 211 212 213 214
    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
215
}
216

217
static def buildTime() {
218 219 220
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}

221
static def hostName() {
222
    return System.getProperty("user.name") + "@" + InetAddress.localHost.hostName
223 224 225 226 227 228 229 230
}

def revision() {
    def code = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-parse', '--short', 'HEAD'
        standardOutput = code
    }
231 232 233 234 235
    return code.toString()
}

def vlcRevision() {
    def vlc = new ByteArrayOutputStream()
236 237 238 239 240
    exec {
        commandLine 'git', 'rev-parse', '--short', 'HEAD'
        workingDir '../vlc'
        standardOutput = vlc
    }
241
    return vlc.toString()
242
}