build.gradle 3.41 KB
Newer Older
1 2
apply plugin: 'com.android.library'

3 4
import com.android.builder.core.DefaultManifestParser

5
android {
6 7
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
8 9 10

    sourceSets {
    main {
Edward Wang's avatar
Edward Wang committed
11
        jni.srcDirs = [] // Prevent gradle from building native code with ndk; we have our own Makefile for it.
Thomas Guillem's avatar
Thomas Guillem committed
12
        jniLibs.srcDirs = [ 'jni/libs', 'jni/loader/libs', 'private_libs/libs' ] // Where generated .so files are placed.
13 14 15 16 17 18
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
19
        assets.srcDirs = ['assets' ]
20 21 22 23 24
    }
    }

    buildTypes {
        release {
25
            minifyEnabled false
26 27 28
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
29 30 31

    // Make per-variant version code
    libraryVariants.all { variant ->
32
        def manifestParser = new DefaultManifestParser(android.sourceSets.main.manifest.srcFile)
33
        // get the version code of each flavor
34 35 36
        def vlcVersion = manifestParser.getVersionName()
        manifestParser = new DefaultManifestParser(file('../vlc-android/AndroidManifest.xml'))
        def androidVersion = manifestParser.getVersionName()
37 38 39 40
        //Custom APK name
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.aar')) {
41
                def fileName = "libvlc-${vlcVersion}-${androidVersion}.aar"
42 43 44 45
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }
46
}
47

48 49 50
/*
 * Include GDB files into apk
 */
Geoffrey Métais's avatar
Geoffrey Métais committed
51 52 53 54
//afterEvaluate {
//    Sync packageTask = project.getTasks().findByName("packageReleaseJniLibs")
//    packageTask.include(['**/gdbserver', '**/gdb.setup'])
//}
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
class BuildNative extends Exec {}

tasks.withType(BuildNative){
    /*
    Properties set for Android Studio own shell.
    when you run gradlew from cli, OS shell env variables will be used

    To be able to build from Android Studio, you have to set ndk.dir & sdk.dir
    properties in local.properties in the root folder, like this (for example):
    sdk.dir=/home/<username>/SDK/android-sdk-linux
    ndk.dir=/home/<username>/SDK/android-ndk-r10b
     */
    if (System.getenv('ANDROID_SDK') == null || System.getenv('ANDROID_NDK') == null) {
        Properties properties = new Properties()
        properties.load(project.rootProject.file('local.properties').newDataInputStream())
        environment 'ANDROID_NDK', properties.getProperty('ndk.dir')
        environment 'ANDROID_SDK', properties.getProperty('sdk.dir')
    }
    workingDir '..'
    commandLine './compile-libvlc.sh'
}

task buildDebugARMv7(type:BuildNative) {
    args('-a', "armeabi-v7a")
}
task buildDebugARM64(type:BuildNative) {
Geoffrey Métais's avatar
Geoffrey Métais committed
82
    args('-a', "arm64-v8a")
83 84 85 86 87 88 89 90 91 92 93 94 95
}
task buildDebugx86(type:BuildNative) {
    args('-a', "x86")
}
task buildDebugx86_64(type:BuildNative) {
    args('-a', "x86_64")
}
task buildDebugMIPS(type:BuildNative) {
    args('-a', "mips")
}
task buildDebugMIPS64(type:BuildNative) {
    args('-a', "mips64")
}
96 97 98 99 100 101

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

102 103 104 105
clean {
    delete 'build', 'jni/libs', 'jni/obj'
}

106
dependencies {
107
    compile "com.android.support:support-annotations:$rootProject.ext.appCompatVersion"
108
}