build.gradle 5.72 KB
Newer Older
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
// Project information
buildDir = 'bin'

def getPackageName() {
    return "org.linphone"
}

def firebaseEnable() {
    File googleFile = new File('google-services.json')
    return googleFile.exists()
}

buildscript {
    File googleFile = new File('google-services.json')
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
	if (googleFile.exists()) {
            classpath 'com.google.gms:google-services:3.1.0'
	}
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
        google()
        maven{
            url "https://gitlab.linphone.org/BC/public/maven_repository/raw/master"
        }

    }
}

apply plugin: 'com.android.application'

dependencies {
    androidTestImplementation('com.android.support.test.espresso:espresso-core:+') {
        exclude module: 'support-annotations'
    }
    androidTestImplementation 'com.jayway.android.robotium:robotium-solo:5.6.3'
    androidTestImplementation 'junit:junit:4.12'
    implementation 'org.apache.commons:commons-compress:1.16.1'
    if (firebaseEnable()) {
        implementation 'com.google.firebase:firebase-messaging:15.0.2'
    }
    implementation 'com.android.support:support-v4:27.0.1'
//    implementation project(':liblinphone-sdk')
//    releaseImplementation 'org.linphone.maven:liblinphone-sdk:4.0.0-RELEASE'
    debugImplementation 'org.linphone.maven:liblinphone-sdk:4.0.0'
}

if (firebaseEnable()) {
    apply plugin: 'com.google.gms.google-services'
}

///// Exclude Files /////
def excludeFiles = []
// Exclude firebase file if not enable
if (!firebaseEnable()) {
    excludeFiles.add('**/Firebase*')
    println '[Push Notification] Firebase disabled'
} else {
    excludeFiles.add('**/gcm*')
    println '[Push Notification] Firebase enabled'
}

excludeFiles.add('src/android/org/linphone/tutorials/*.java')

def excludePackage = []

excludePackage.add('**/gdb.*')
excludePackage.add('**/libopenh264**')
excludePackage.add('**/**tester**')
excludePackage.add('**/LICENSE.txt')
/////////////////////////

android {
    defaultConfig {
        compileSdkVersion 28
        buildToolsVersion "28.0.0"
        applicationId getPackageName()
        multiDexEnabled true

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
        disable 'MissingTranslation', 'UnusedResources'
    }
    // Signing
    signingConfigs {
        release {
            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
        packaged {
            initWith release
            signingConfig null
            matchingFallbacks = ['debug', 'release']
        }
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            def srcDirs = ['src/android']
            java.srcDirs = srcDirs
            resources.srcDirs = srcDirs
            aidl.srcDirs = srcDirs
            renderscript.srcDirs = srcDirs
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            java.excludes = excludeFiles

            // Exclude some useless files
            packagingOptions {
                excludes = excludePackage
            }
        }

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
    sourceSets {
        androidTest {
            manifest.srcFile 'AndroidManifest.xml'
            def srcDirs = ['src/android', 'src/androidTest']
            java.srcDirs = srcDirs
            resources.srcDirs = srcDirs
            aidl.srcDirs = srcDirs
            renderscript.srcDirs = srcDirs
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            java.excludes = excludeFiles

            // Exclude some useless files
            packagingOptions {
                excludes = excludePackage
            }
        }

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
    packagingOptions {
        pickFirst 'META-INF/NOTICE'
        pickFirst 'META-INF/LICENSE'
        exclude 'META-INF/MANIFEST.MF'
    }
}

// Grant permissions
android.applicationVariants.all { variant ->
    def applicationId = getPackageName()
    def adb = android.getAdbExecutable().toString()
    def variantName = variant.name.capitalize()
    def grantPermissionTask = tasks.create("grant${variantName}Permissions").doLast({
        "${adb} devices".execute().text.eachLine {
            "${adb} shell pm grant ${applicationId} android.permission.RECORD_AUDIO".execute()
            "${adb} shell pm grant ${applicationId} android.permission.WRITE_EXTERNAL_STORAGE".execute()
            "${adb} shell pm grant ${applicationId} android.permission.CAMERA".execute()
            "${adb} shell pm grant ${applicationId} android.permission.READ_PHONE_STATE".execute()
            "${adb} shell pm grant ${applicationId} android.permission.READ_CONTACTS".execute()
            "${adb} shell pm grant ${applicationId} android.permission.WRITE_CONTACTS".execute()
        }
    })
}

task runApplication {
    doLast {
        def result = exec {
            executable = android.getAdbExecutable().toString()
            ignoreExitValue true
            args = ['shell', 'monkey', '-p', getPackageName(), '-c', 'android.intent.category.LAUNCHER', '1']
        }
    }
}