linphone-android/app/build.gradle
2023-04-03 16:02:13 +02:00

536 lines
25 KiB
Groovy

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'org.jlleitschuh.gradle.ktlint'
id 'org.jetbrains.kotlin.android'
}
def appVersionName = "5.1.0"
def appVersionCode = 50090
static def getPackageName() {
return "org.linphone"
}
def firebaseAvailable = new File(projectDir.absolutePath + '/google-services.json').exists()
def crashlyticsAvailable = new File(projectDir.absolutePath + '/google-services.json').exists() && new File(LinphoneSdkBuildDir + '/libs/').exists() && new File(LinphoneSdkBuildDir + '/libs-debug/').exists()
if (firebaseAvailable) {
apply plugin: 'com.google.gms.google-services'
}
def gitBranch = new ByteArrayOutputStream()
task getGitVersion() {
def gitVersion = appVersionName
def gitVersionStream = new ByteArrayOutputStream()
def gitCommitsCount = new ByteArrayOutputStream()
def gitCommitHash = new ByteArrayOutputStream()
try {
exec {
executable "git" args "describe", "--abbrev=0"
standardOutput = gitVersionStream
}
exec {
executable "git" args "rev-list", gitVersionStream.toString().trim() + "..HEAD", "--count"
standardOutput = gitCommitsCount
}
exec {
executable "git" args "rev-parse", "--short", "HEAD"
standardOutput = gitCommitHash
}
exec {
executable "git" args "name-rev", "--name-only", "HEAD"
standardOutput = gitBranch
}
if (gitCommitsCount.toString().toInteger() == 0) {
gitVersion = gitVersionStream.toString().trim()
} else {
gitVersion = gitVersionStream.toString().trim() + "." + gitCommitsCount.toString().trim() + "+" + gitCommitHash.toString().trim()
}
println("Git version: " + gitVersion + " (" + appVersionCode + ")")
} catch (ignored) {
println("Git not found, using " + gitVersion + " (" + appVersionCode + ")")
}
project.version = gitVersion
}
configurations {
customImplementation.extendsFrom implementation
}
task linphoneSdkSource() {
doLast {
configurations.customImplementation.getIncoming().each {
it.getResolutionResult().allComponents.each {
if (it.id.getDisplayName().contains("linphone-sdk-android")) {
println 'Linphone SDK used is ' + it.moduleVersion.version + ' from ' + it.properties["repositoryName"]
}
}
}
}
}
project.tasks['preBuild'].dependsOn 'getGitVersion'
project.tasks['preBuild'].dependsOn 'linphoneSdkSource'
android {
compileSdkVersion 33
buildToolsVersion '33.0.0'
defaultConfig {
minSdkVersion 23
targetSdkVersion 33
versionCode appVersionCode
versionName "${project.version}"
applicationId getPackageName()
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testOptions {
animationsDisabled = true
}
}
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "linphone-android-${variant.buildType.name}-${project.version}.apk"
}
var enableFirebaseService = "false"
if (firebaseAvailable) {
enableFirebaseService = "true"
}
// See https://developer.android.com/studio/releases/gradle-plugin#3-6-0-behavior for why extractNativeLibs is set to true in debug flavor
if (variant.buildType.name == "release" || variant.buildType.name == "releaseWithCrashlytics") {
variant.getMergedFlavor().manifestPlaceholders = [linphone_address_mime_type: "vnd.android.cursor.item/vnd." + getPackageName() + ".provider.sip_address",
linphone_file_provider : getPackageName() + ".fileprovider",
appLabel : "@string/app_name",
firebaseServiceEnabled : enableFirebaseService,
extractNativeLibs : "false"]
} else {
variant.getMergedFlavor().manifestPlaceholders = [linphone_address_mime_type: "vnd.android.cursor.item/vnd." + getPackageName() + ".provider.sip_address",
linphone_file_provider : getPackageName() + ".debug.fileprovider",
appLabel : "@string/app_name_debug",
firebaseServiceEnabled : enableFirebaseService,
extractNativeLibs : "true"]
}
}
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
signingConfigs {
release {
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
}
}
buildTypes {
release {
minifyEnabled true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "linphone_app_branch", gitBranch.toString().trim()
resValue "string", "sync_account_type", getPackageName() + ".sync"
resValue "string", "file_provider", getPackageName() + ".fileprovider"
resValue "string", "linphone_address_mime_type", "vnd.android.cursor.item/vnd." + getPackageName() + ".provider.sip_address"
if (!firebaseAvailable) {
resValue "string", "gcm_defaultSenderId", "none"
}
resValue "bool", "crashlytics_enabled", "false"
}
releaseWithCrashlytics {
initWith release
resValue "bool", "crashlytics_enabled", crashlyticsAvailable.toString()
if (crashlyticsAvailable) {
apply plugin: 'com.google.firebase.crashlytics'
firebaseCrashlytics {
nativeSymbolUploadEnabled true
unstrippedNativeLibsDir file(LinphoneSdkBuildDir + '/libs-debug/').toString()
}
}
}
debug {
applicationIdSuffix ".debug"
debuggable true
jniDebuggable true
resValue "string", "linphone_app_branch", gitBranch.toString().trim()
resValue "string", "sync_account_type", getPackageName() + ".sync"
resValue "string", "file_provider", getPackageName() + ".debug.fileprovider"
resValue "string", "linphone_address_mime_type", "vnd.android.cursor.item/vnd." + getPackageName() + ".provider.sip_address"
resValue "bool", "crashlytics_enabled", crashlyticsAvailable.toString()
if (!firebaseAvailable) {
resValue "string", "gcm_defaultSenderId", "none"
}
if (crashlyticsAvailable) {
apply plugin: 'com.google.firebase.crashlytics'
firebaseCrashlytics {
nativeSymbolUploadEnabled false
}
}
}
}
buildFeatures {
dataBinding = true
}
adbOptions {
installOptions '-g', '-r'
}
namespace 'org.linphone'
testBuildType 'debug'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.core:core-splashscreen:1.0.0'
implementation 'androidx.emoji2:emoji2:1.3.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.0'
implementation 'androidx.media:media:1.6.0'
implementation "androidx.security:security-crypto-ktx:1.1.0-alpha05"
implementation "androidx.window:window:1.0.0"
implementation 'androidx.core:core-ktx:1.9.0'
def nav_version = "2.5.3"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation "androidx.slidingpanelayout:slidingpanelayout:1.2.0"
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.gridlayout:gridlayout:1.0.0"
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'androidx.drawerlayout:drawerlayout:1.2.0'
// https://github.com/material-components/material-components-android/blob/master/LICENSE Apache v2.0
implementation 'com.google.android.material:material:1.8.0'
// https://github.com/google/flexbox-layout/blob/main/LICENSE Apache v2.0
implementation 'com.google.android.flexbox:flexbox:3.0.0'
// https://github.com/coil-kt/coil/blob/main/LICENSE.txt Apache v2.0
def coil_version = "2.2.2"
implementation("io.coil-kt:coil:$coil_version")
implementation("io.coil-kt:coil-gif:$coil_version")
implementation("io.coil-kt:coil-svg:$coil_version")
implementation("io.coil-kt:coil-video:$coil_version")
// https://github.com/Baseflow/PhotoView/blob/master/LICENSE Apache v2.0
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
implementation platform('com.google.firebase:firebase-bom:31.2.3')
if (crashlyticsAvailable) {
debugImplementation 'com.google.firebase:firebase-crashlytics-ndk'
releaseWithCrashlyticsImplementation 'com.google.firebase:firebase-crashlytics-ndk'
releaseCompileOnly 'com.google.firebase:firebase-crashlytics-ndk'
} else {
compileOnly 'com.google.firebase:firebase-crashlytics-ndk'
}
if (firebaseAvailable) {
implementation 'com.google.firebase:firebase-messaging'
}
implementation 'org.linphone:linphone-sdk-android:5.2+'
// Only enable leak canary prior to release
//debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
// UITests dependencies
androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test:core:1.5.0'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
task generateContactsXml(type: Copy) {
from 'contacts.xml'
into "src/main/res/xml/"
outputs.upToDateWhen { file('src/main/res/xml/contacts.xml').exists() }
filter {
line ->
line
.replaceAll('%%AUTO_GENERATED%%', 'This file has been automatically generated, do not edit or commit !')
.replaceAll('%%PACKAGE_NAME%%', getPackageName())
}
}
project.tasks['preBuild'].dependsOn 'generateContactsXml'
ktlint {
android = true
ignoreFailures = true
}
project.tasks['preBuild'].dependsOn 'ktlintFormat'
if (crashlyticsAvailable) {
afterEvaluate {
assembleReleaseWithCrashlytics.finalizedBy(uploadCrashlyticsSymbolFileReleaseWithCrashlytics)
packageReleaseWithCrashlytics.finalizedBy(uploadCrashlyticsSymbolFileReleaseWithCrashlytics)
}
}
// screenshots ui tests
def reportsDirectory = new File(buildDir, "reports${File.separator}androidTests${File.separator}connected").absolutePath
def screenshotDirectory = new File(reportsDirectory, "screenshots").absolutePath
def embedScreenshotsTask = task('embedScreenshots', group: 'reporting') {
ext.updateSummaryValues = { failedTestJunitReportContent, newFailures ->
def totalCounterStr = "id=\"tests\">\n<div class=\"counter\">"
def totalCounterStart = failedTestJunitReportContent.indexOf(totalCounterStr) + totalCounterStr.length()
def totalCounterEnd = failedTestJunitReportContent.indexOf("</div>", totalCounterStart)
def failureCounterStr = "id=\"failures\">\n<div class=\"counter\">"
def failureCounterStart = failedTestJunitReportContent.indexOf(failureCounterStr, totalCounterEnd) + failureCounterStr.length()
def failureCounterEnd = failedTestJunitReportContent.indexOf("</div>", failureCounterStart)
def percentInfoStr = "id=\"successRate\">\n<div class=\"percent\">"
def percentInfoStart = failedTestJunitReportContent.indexOf(percentInfoStr, failureCounterEnd) + percentInfoStr.length()
def percentInfoEnd = failedTestJunitReportContent.indexOf("%</div>", percentInfoStart)
def total = failedTestJunitReportContent.substring(totalCounterStart, totalCounterEnd).toInteger()
def failure = failedTestJunitReportContent.substring(failureCounterStart, failureCounterEnd).toInteger() + newFailures
def percent = ((1 - failure / total) * 100).toInteger()
failedTestJunitReportContent = failedTestJunitReportContent.substring(0, failureCounterStart) + "$failure" + failedTestJunitReportContent.substring(failureCounterEnd)
failedTestJunitReportContent = failedTestJunitReportContent.substring(0, percentInfoStart) + "$percent" + failedTestJunitReportContent.substring(percentInfoEnd)
return [failedTestJunitReportContent, failure, percent]
}
ext.addFailedTestsHeader = { failedTestJunitReportContent, mode ->
def tab0 = "<a href=\"#tab0\">${mode}</a>\n</li>\n</ul>\n<div id=\"tab0\" class=\"tab\">"
def tab0Index = failedTestJunitReportContent.indexOf(tab0)
if (tab0Index != -1) {
def header = ""
if (mode == "Classes") header = "<ul class=\"linkList\">\n<table>\n<thead>\n<tr>\n<th>Class</th>\n<th>Test</th>\n</tr>\n</thead>\n</table>\n</ul>\n"
def newtab0 = "<a href=\"#tab0\">Failed tests</a>\n</li>\n<li>\n<a href=\"#tab1\">${mode}</a>\n</li>\n</ul>\n<div id=\"tab0\" class=\"tab\">\n<h2>Failed tests</h2>\n${header}</div>\n<div id=\"tab1\" class=\"tab\">"
failedTestJunitReportContent = failedTestJunitReportContent.replace(tab0, newtab0)
}
return failedTestJunitReportContent
}
ext.updateRecapValues = { failedTestJunitReportContent, name, failures, percent, variant ->
failedTestJunitReportContent = failedTestJunitReportContent.replace("\"success\"$variant>\n<a href=\"${name}", "\"failures\">\n<a href=\"${name}")
def startIndex = failedTestJunitReportContent.lastIndexOf("${name}.html")
startIndex = failedTestJunitReportContent.indexOf("<td>", startIndex) + 4
startIndex = failedTestJunitReportContent.indexOf("<td>", startIndex) + 4
def endIndex = failedTestJunitReportContent.indexOf("</td>", startIndex)
failedTestJunitReportContent = failedTestJunitReportContent.substring(0, startIndex) + "${failures}" + failedTestJunitReportContent.substring(endIndex)
startIndex = failedTestJunitReportContent.indexOf("<td class=", startIndex) + 10
endIndex = failedTestJunitReportContent.indexOf("</td>", startIndex)
failedTestJunitReportContent = failedTestJunitReportContent.substring(0, startIndex) + "\"failures\">${percent}%" + failedTestJunitReportContent.substring(endIndex)
return failedTestJunitReportContent
}
doFirst {
def failureScreenshotsDirectory = new File(reportsDirectory, 'failures')
if (!failureScreenshotsDirectory.exists()) {
println "Could not find screenshot failures at $failureScreenshotsDirectory Skipping..."
return
}
def indexJunitReportFile = new File(reportsDirectory, "index.html")
if (!indexJunitReportFile.exists()) {
println "Could not find JUnit report file for test class '${indexJunitReportFile}'"
return
}
def indexJunitReportContent = indexJunitReportFile.text
failureScreenshotsDirectory.eachFile { failedTestClassDirectory ->
def failedTestClassName = failedTestClassDirectory.name
def failedTestPackageName = failedTestClassName.substring(0, failedTestClassName.lastIndexOf("."))
def packageJunitReportFile = new File(reportsDirectory, "${failedTestPackageName}.html")
if (!packageJunitReportFile.exists()) {
println "Could not find JUnit report file for test class '${packageJunitReportFile}'"
return
}
def packageJunitReportContent = packageJunitReportFile.text
failedTestClassDirectory.eachFile { failedTestFile ->
def failedTestName = failedTestFile.name
def failedTestClassJunitReportFile = new File(reportsDirectory, "${failedTestClassName}.html")
if (!failedTestClassJunitReportFile.exists()) {
println "Could not find JUnit report file for test class '${failedTestClassJunitReportFile}'"
return
}
def failedTestJunitReportContent = failedTestClassJunitReportFile.text
def failures = 0
failedTestFile.eachFile { failedTestCase ->
def failedTestCaseDescription = failedTestCase.name
def pt1 = failedTestCaseDescription.indexOf(".")
def line = failedTestCaseDescription.substring(0, pt1)
def pt2 = failedTestCaseDescription.indexOf(".", pt1 + 1)
def name = failedTestCaseDescription.substring(pt1 + 1, pt2)
def pt3 = failedTestCaseDescription.indexOf(".", pt2 + 1)
if (pt3 != -1) {
name += " (${failedTestCaseDescription.substring(pt2 + 1, pt3)})"
}
failedTestJunitReportContent = addFailedTestsHeader(failedTestJunitReportContent, "Tests")
packageJunitReportContent = addFailedTestsHeader(packageJunitReportContent, "Classes")
indexJunitReportContent = addFailedTestsHeader(indexJunitReportContent, "Classes")
def failedTest = "<h3 class=\"failures\">${failedTestName}</h3>"
def failedTestIndex = failedTestJunitReportContent.indexOf(failedTest)
def screenshotReport = ""
if (failedTestIndex == -1) {
//test.html
def newtestDiv = "<div class=\"test\">\n<a name=\"${failedTestName}\"></a>\n${failedTest}\n<span class=\"code\">\n<pre>\n</pre>\n</span>\n</div>\n"
def endDiv = "</div>\n<div id=\"tab1\""
failedTestJunitReportContent = failedTestJunitReportContent.replace(endDiv, newtestDiv + endDiv)
failedTestJunitReportContent = failedTestJunitReportContent.replace("<td>${failedTestName}</td>\n<td class=\"success\">passed", "<td>${failedTestName}</td>\n<td class=\"failures\">failed")
def boxStr = "\"infoBox success\" id=\"successRate\""
if (failedTestJunitReportContent.indexOf(boxStr) != -1) {
failedTestJunitReportContent = failedTestJunitReportContent.replace(boxStr, "\"infoBox failures\" id=\"successRate\"")
}
//package.html
newtestDiv = "<tr>\n<td class=\"failures\">\n<a href=\"${failedTestClassName}.html\">${failedTestClassName.substring(failedTestClassName.lastIndexOf(".") + 1)}</a>\n</td>\n"
newtestDiv += "<td class=\"failures\">\n<a href=\"${failedTestClassName}.html#${failedTestName}\">${failedTestName}</a>\n</td>\n</tr>\n"
endDiv = "</table>\n</ul>\n</div>\n<div id=\"tab1\""
packageJunitReportContent = packageJunitReportContent.replace(endDiv, newtestDiv + endDiv)
if (packageJunitReportContent.indexOf(boxStr) != -1) {
packageJunitReportContent = packageJunitReportContent.replace(boxStr, "\"infoBox failures\" id=\"successRate\"")
}
//index.html
newtestDiv = "<tr>\n<td class=\"failures\">\n<a href=\"${failedTestClassName}.html\">${failedTestClassName.substring(failedTestClassName.lastIndexOf(".") + 1)}</a>\n</td>\n"
newtestDiv += "<td class=\"failures\">\n<a href=\"${failedTestClassName}.html#${failedTestName}\">${failedTestName}</a>\n</td>\n</tr>\n"
endDiv = "</table>\n</ul>\n</div>\n<div id=\"tab1\""
indexJunitReportContent = indexJunitReportContent.replace(endDiv, newtestDiv + endDiv)
if (indexJunitReportContent.indexOf(boxStr) != -1) {
indexJunitReportContent = indexJunitReportContent.replace(boxStr, "\"infoBox failures\" id=\"successRate\"")
}
failedTestIndex = failedTestJunitReportContent.indexOf(failedTest)
failures += 1
} else screenshotReport = "\n\n"
def imagesrc = new File("failures", failedTestClassName + File.separator + failedTestName + File.separator + failedTestCaseDescription).toString()
screenshotReport += "display conflicts detected with \'${name}\' line ${line}:\n<img src=\"${imagesrc}\" width =\"800\" />\n"
def insertIndex = failedTestJunitReportContent.indexOf("</pre>", failedTestIndex)
def firstPart = failedTestJunitReportContent.substring(0, insertIndex)
def secondPart = failedTestJunitReportContent.substring(insertIndex)
failedTestJunitReportContent = firstPart + screenshotReport + secondPart
failedTestClassJunitReportFile.write(failedTestJunitReportContent)
}
if (failures != 0) {
failedTestJunitReportContent = failedTestJunitReportContent.replace("<td>${failedTestName}</td>\n<td class=\"success\">passed", "<td>${failedTestName}</td>\n<td class=\"failures\">failed")
def classSummaryValues = updateSummaryValues(failedTestJunitReportContent, failures)
def packageSummaryValues = updateSummaryValues(packageJunitReportContent, failures)
def indexSummaryValues = updateSummaryValues(indexJunitReportContent, failures)
failedTestJunitReportContent = classSummaryValues[0]
packageJunitReportContent = packageSummaryValues[0]
indexJunitReportContent = indexSummaryValues[0]
packageJunitReportContent = updateRecapValues(packageJunitReportContent, failedTestClassName, classSummaryValues[1], classSummaryValues[2], "")
indexJunitReportContent = updateRecapValues(indexJunitReportContent, failedTestClassName, classSummaryValues[1], classSummaryValues[2], "/")
indexJunitReportContent = updateRecapValues(indexJunitReportContent, failedTestPackageName, packageSummaryValues[1], packageSummaryValues[2], "")
failedTestClassJunitReportFile.write(failedTestJunitReportContent)
packageJunitReportFile.write(packageJunitReportContent)
indexJunitReportFile.write(indexJunitReportContent)
}
}
}
print "see report at: ${new File(reportsDirectory, "index.html")}"
}
}
def clearScreenshotsTask = task('clearScreenshots', type: Exec) {
executable "${android.getAdbExe().toString()}"
args 'shell', 'rm', '-r', '/sdcard/Pictures/linphone_uitests'
}
def fetchScreenshotsTask = task('fetchScreenshots', type: Exec, group: 'reporting') {
executable "${android.getAdbExe().toString()}"
args 'pull', '/sdcard/Pictures/linphone_uitests/.', screenshotDirectory
doFirst {
new File(screenshotDirectory).mkdirs()
}
finalizedBy {
clearScreenshotsTask
}
}
def launchScreenshotsComparisonTask = task('launchScreenshotsComparison', type: Exec, group: 'reporting') {
workingDir "$rootDir/screport/"
def windowed = "true"
if (project.hasProperty("screportWindowed")) {
windowed = screportWindowed
}
commandLine "python3", "launch.py", "-rp", "$projectDir/src/androidTest/java/org/linphone/screenshots", "-sp", "$projectDir/build/reports/androidTests/connected/screenshots", "-wd", "$windowed"
dependsOn() {
fetchScreenshotsTask
}
finalizedBy {
embedScreenshotsTask
}
}
def isScreenshotComparisonNeededTask = task('isScreenshotComparisonNeeded', type: Exec, group: 'reporting') {
commandLine "${android.getAdbExe().toString()}", 'shell', 'cd', '/sdcard/Pictures/linphone_uitests', '||', 'echo false'
standardOutput = new ByteArrayOutputStream()
doLast {
launchScreenshotsComparisonTask.onlyIf { "$standardOutput" == "" }
fetchScreenshotsTask.onlyIf { "$standardOutput" == "" }
clearScreenshotsTask.onlyIf { "$standardOutput" == "" }
embedScreenshotsTask.onlyIf { "$standardOutput" == "" }
}
finalizedBy {
launchScreenshotsComparisonTask
}
}
gradle.projectsEvaluated {
connectedDebugAndroidTest.finalizedBy {
isScreenshotComparisonNeededTask
}
}