JLChen
2021-01-04 ed86fe7ed952bb2151aac8841134246bbde152c9
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
196
197
198
199
200
201
apply plugin: 'com.android.application'
 
static def getPackageName() {
    return "org.linphone"
}
 
static def firebaseEnabled() {
    File googleFile = new File('app/google-services.json')
    return googleFile.exists()
}
 
task getGitVersion() {
    def gitVersion = "4.4.0"
    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
        }
 
        if (gitCommitsCount.toString().toInteger() == 0) {
            gitVersion = gitVersionStream.toString().trim()
        } else {
            gitVersion = gitVersionStream.toString().trim() + "." + gitCommitsCount.toString().trim() + "+" + gitCommitHash.toString().trim()
        }
        println("Git version: " + gitVersion)
    } catch (Exception e) {
        println("Git not found")
    }
    project.version = gitVersion
}
 
///// Exclude Files /////
 
def excludeFiles = []
if (!firebaseEnabled()) {
    excludeFiles.add('**/Firebase*')
    println '[Push Notification] Firebase disabled'
}
// Remove or comment if you want to use those
excludeFiles.add('**/XmlRpc*')
excludeFiles.add('**/InAppPurchase*')
 
def excludePackage = []
 
excludePackage.add('**/gdb.*')
excludePackage.add('**/libopenh264**')
excludePackage.add('**/**tester**')
excludePackage.add('**/LICENSE.txt')
 
/////////////////////////
 
repositories {
    maven {
        url file(LinphoneSdkBuildDir + '/maven_repository/')
    }
    maven {
        url "https://linphone.org/maven_repository"
    }
}
 
project.tasks['preBuild'].dependsOn 'getGitVersion'
 
android {
    lintOptions {
        abortOnError false
    }
 
    compileSdkVersion 29
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 4300
        versionName "${project.version}"
        applicationId getPackageName()
        multiDexEnabled true
    }
 
    applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "linphone-android-${variant.buildType.name}-${project.version}.apk"
        }
 
        // https://developer.android.com/studio/releases/gradle-plugin#3-6-0-behavior for extractNativeLibs
        if (variant.buildType.name == "release") {
            variant.getMergedFlavor().manifestPlaceholders = [linphone_address_mime_type: "vnd.android.cursor.item/vnd." + getPackageName() + ".provider.sip_address",
                                    linphone_file_provider: getPackageName() + ".provider",
                                    extractNativeLibs: "false"]
        } else {
            variant.getMergedFlavor().manifestPlaceholders = [linphone_address_mime_type: "vnd.android.cursor.item/vnd." + getPackageName() + ".provider.sip_address",
                                    linphone_file_provider: getPackageName() + ".debug.provider",
                                    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", "sync_account_type", getPackageName() + ".sync"
            resValue "string", "file_provider", getPackageName() + ".provider"
            resValue "string", "linphone_address_mime_type", "vnd.android.cursor.item/vnd." + getPackageName() + ".provider.sip_address"
 
            if (!firebaseEnabled()) {
                resValue "string", "gcm_defaultSenderId", "none"
            }
        }
        debug {
            applicationIdSuffix ".debug"
            debuggable true
            jniDebuggable true
 
            resValue "string", "sync_account_type", getPackageName() + ".sync"
            resValue "string", "file_provider", getPackageName() + ".debug.provider"
            resValue "string", "linphone_address_mime_type", "vnd.android.cursor.item/vnd." + getPackageName() + ".provider.sip_address"
 
            if (!firebaseEnabled()) {
                resValue "string", "gcm_defaultSenderId", "none"
            }
        }
    }
 
    sourceSets {
        main {
            java.excludes = excludeFiles
 
            packagingOptions {
                excludes = excludePackage
            }
        }
    }
 
    packagingOptions {
        pickFirst 'META-INF/NOTICE'
        pickFirst 'META-INF/LICENSE'
        exclude 'META-INF/MANIFEST.MF'
    }
}
 
dependencies {
    compileOnly 'org.jetbrains:annotations:19.0.0'
    if (firebaseEnabled()) {
        implementation 'com.google.firebase:firebase-messaging:19.0.1'
    }
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android:flexbox:1.1.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation "org.linphone:linphone-sdk-android:4.5+"
}
if (firebaseEnabled()) {
    apply plugin: 'com.google.gms.google-services'
}
 
task generateContactsXml(type: Copy) {
    from 'contacts.xml'
    into "src/main/res/xml/"
    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'
 
apply plugin: "com.diffplug.gradle.spotless"
spotless {
    java {
        target '**/*.java'
        googleJavaFormat('1.6').aosp()
        removeUnusedImports()
    }
}
project.tasks['preBuild'].dependsOn 'spotlessApply'