summaryrefslogtreecommitdiff
path: root/app/build.gradle
blob: 6dff8e344617beaa62fe3835d5704c351ffee8aa (plain)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
import java.util.concurrent.ExecutionException
import java.util.regex.Matcher
import java.util.regex.Pattern

apply plugin: 'com.android.application'
def appName = 'Bitmask'

android {
  compileSdkVersion 27
  buildToolsVersion '27.0.3'

  compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
  }

  defaultConfig {
    applicationId "se.leap.bitmaskclient"
    versionCode 136
    versionName "0.9.9"
    resValue "string", "app_name", appName
    vectorDrawables.useSupportLibrary = true
    buildConfigField 'boolean', 'openvpn3', 'false'


    //Build Config Fields for default donation details

    //This is the default donation URL and should be set to the donation page of LEAP
    // and this should not be set/altered anywhere else.
    buildConfigField 'String', 'default_donation_url', '"https://leap.se/en/about-us/donate"'
    //This is the donation URL and should be set to the relevant donation page.
    buildConfigField 'String', 'donation_url', 'null'
    //The field to enable donations in the app.
    buildConfigField 'boolean', 'enable_donation', 'true'
    //The field to enable donation reminder popup in the app if enable_donation is set to 'false' this will be disabled.
    buildConfigField 'boolean', 'enable_donation_reminder', 'true'
    //The duration in days to trigger the donation reminder
    buildConfigField 'int', 'donation_reminder_duration', '30'
    //skip the account creation / login screen if the provider offers anonymous vpn usage, use directly the anonymous cert instead
    buildConfigField 'boolean', 'priotize_anonymous_usage', 'false'
    //ignore the following config, only used in custom flavor
    buildConfigField "String", "customProviderUrl", '""'

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    dexOptions {
      jumboMode true
      multiDexEnabled true
    }
  }

  signingConfigs {
    release {
      storeFile project.hasProperty('storeFileProperty') ? file(storeFileProperty) : null
      storePassword project.hasProperty('storePasswordProperty') ?  storePasswordProperty : ""
      keyAlias project.hasProperty('keyAliasProperty') ?  keyAliasProperty : ""
      keyPassword project.hasProperty('keyPasswordProperty') ?  keyPasswordProperty : ""
    }
  }

  flavorDimensions "branding", "implementation"
  productFlavors {
    production {
      dimension "implementation"
    }
    insecure {
      dimension "implementation"
    }
    normal {
      dimension "branding"
    }


    custom {
      dimension "branding"

      //**************************************************************************
      //**************************************************************************
      //Configurations for custom branded app.

      //Change the package name as needed, e.g. "org.example.myapp"
      applicationId "se.leap.riseupvpn"
      //Set app name here
      appName = "Riseup VPN"
      resValue "string", "app_name", appName
      //Provider base url, e.g. '"https://example.com"'
      def customProviderUrl = '"https://riseup.net"'
      buildConfigField "String", "customProviderUrl", customProviderUrl
      //Change the versionCode as needed
      //versionCode 1
      //Change the versionName as needed
      //versionName "0.9.9RC1"

      //skip the account creation / login screen if the provider offers anonymous vpn usage, use directly the anonymous cert instead
      buildConfigField 'boolean', 'priotize_anonymous_usage', 'true'

      //Build Config Fields for default donation details

      //This is the donation URL and should be set to the relevant donation page.
      buildConfigField 'String', 'donation_url', '"https://riseup.net/vpn/donate"'
      //The field to enable donations in the app.
      buildConfigField 'boolean', 'enable_donation', 'true'
      //The field to enable donation reminder popup in the app if enable_donation is set to 'false' this will be disabled.
      buildConfigField 'boolean', 'enable_donation_reminder', 'true'
      //The duration in days to trigger the donation reminder
      buildConfigField 'int', 'donation_reminder_duration', '30'

      //**************************************************************************
      //**************************************************************************

    }
  }

  buildTypes {
    release {
      //runProguard true
      if(signingConfigs.contains(release))
        signingConfig signingConfigs.release.isSigningReady() ? signingConfigs.release : signingConfigs.debug
    }
    beta {
      initWith release
      applicationIdSuffix ".beta"
      resValue "string", "app_name", appName + " Beta"
    }
    debug {
      testCoverageEnabled = true
    }
  }

  lintOptions {
    abortOnError false
  }

  sourceSets {
    main {
      assets.srcDirs = ['assets', 'ovpnlibs/assets', '../ics-openvpn/main/build/ovpnassets']
      jniLibs.srcDirs = ['../ics-openvpn/main/build/intermediates/cmake/noovpn3/release/obj']
      jni.srcDirs = [] //disable automatic ndk-build
    }
    debug {
      assets.srcDirs = ['src/debug/assets']
    }

    test {
      resources.srcDirs += ['src/test/resources']
      java.srcDirs += ['src/sharedTest/java']
    }

    androidTest {
      java.srcDirs += ['src/sharedTest/java']
    }
  }
}

dependencies {
  testImplementation 'junit:junit:4.12'
  testImplementation 'org.mockito:mockito-core:2.8.9'
  testImplementation('org.powermock:powermock-api-mockito2:1.7.3')
          { exclude group: 'junit' exclude group: 'org.mockito' }
  testImplementation 'org.powermock:powermock-module-junit4:1.7.3'
  testImplementation 'org.powermock:powermock-core:1.7.3'
  testImplementation 'org.powermock:powermock-module-junit4-rule:1.7.3'
  testImplementation group: 'com.tngtech.java', name: 'junit-dataprovider', version: '1.10.0'

  androidTestImplementation 'org.mockito:mockito-core:2.8.9'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
  androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.1'
  androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.1'
  //TODO: remove that library
  androidTestImplementation 'com.jayway.android.robotium:robotium-solo:5.6.3'
  testImplementation 'junit:junit:4.12'
  testImplementation 'org.json:json:20170516'
  debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
  releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
  betaImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
  annotationProcessor 'com.jakewharton:butterknife:6.1.0'
  annotationProcessor 'com.squareup.dagger:dagger-compiler:1.2.2'
  implementation 'com.jakewharton:butterknife:6.1.0'
  //TODO: replace that library
  compileOnly 'com.squareup.dagger:dagger-compiler:1.2.2'
  //TODO: remove that library?
  implementation 'com.github.pedrovgs:renderers:1.5'
  implementation 'com.intellij:annotations:12.0'
  implementation 'com.google.code.gson:gson:2.8.2'
  implementation 'com.squareup.okhttp3:okhttp:3.9.0'
  implementation "com.android.support:support-core-utils:27.0.2"
  implementation 'com.android.support:support-annotations:27.0.2'
  implementation 'com.android.support:support-v4:27.0.2'
  implementation 'com.android.support:appcompat-v7:27.0.2'
  implementation 'com.android.support:design:27.0.2'
  implementation 'com.android.support:support-fragment:27.0.2'
  implementation 'com.android.support.constraint:constraint-layout:1.0.2'
  implementation 'com.android.support:multidex:1.0.2'
  implementation 'com.android.support:cardview-v7:27.0.2'
}

// Ensure the no-op dependency is always used in JVM tests.
configurations.all { config ->
  if (config.name.contains('UnitTest')) {
    config.resolutionStrategy.eachDependency { details ->
      if (details.requested.group == 'com.squareup.leakcanary' && details.requested.name == 'leakcanary-android') {
        details.useTarget(group: details.requested.group, name: 'leakcanary-android-no-op', version: details.requested.version)
      }
    }
  }
  resolutionStrategy.force "com.android.support:support-annotations:27.0.2"
  resolutionStrategy.force "com.android.support:support-v4:27.0.2"
  resolutionStrategy.force "com.android.support:support-core-utils:27.0.2"
  resolutionStrategy.force "com.android.support:appcompat-v7:27.0.2"
  resolutionStrategy.force "com.android.support:design:27.0.2"
  resolutionStrategy.force "com.android.support:support-fragment:27.0.2"
}

def processFileInplace(file, Closure processText) {
  def text = file.text
  file.write(processText(text))
}

task copyIcsOpenVPNClasses( type: Copy ) {
  println "copyIcsOpenVPNClasses"
//  from ('../ics-openvpn/main/') {
//    include '**/LaunchVPN.java'
//    include '**/OpenVPNSservice.java'
//    include '**/VpnProfile.java'
//    include '**/DisconnectVPN.java'
//    include '**/VpnProfile.java'
//    include '**/SeekBarTicks.java'
//    include '**/core/**.java'
//    include '**/activities/BaseActivity.java'
//    include '**/APIVpnProfile.java'
//    include '**/aidl/**/api/**.aidl'
//    include '**/aidl/**/core/**.aidl'
//
//    includeEmptyDirs = false
//
//    filter {
//      line -> line.replaceAll('de.blinkt.openvpn.R', 'se.leap.bitmaskclient.R')
//    }
//    filter {
//      line -> line.replaceAll('de.blinkt.openvpn.BuildConfig', 'se.leap.bitmaskclient.BuildConfig')
//    }
//    filter {
//      line -> line.replace('package de.blinkt.openvpn;', 'package de.blinkt.openvpn;\n\nimport se.leap.bitmaskclient.R;')
//    }
//  } into '.'
}

task copyIcsOpenVPNXml( type: Copy )  {
  println "copyIcsOpenVPNXml"
  from ('../ics-openvpn/main/') {
    include '**/strings.xml'
    include '**/refs.xml'
    include '**/white_rect.xml'
    include '**/plurals.xml'
    includeEmptyDirs = false

    rename 'strings.xml', 'strings-icsopenvpn.xml'
    rename 'plurals.xml', 'plurals-icsopenvpn.xml'
    filter {
      line -> line.replaceAll('.*name="app".*', '')
    }
  } into '.'
}

task copyIcsOpenVPNImages( type: Copy ) {
  println "copyIcsOpenVPNImages"
//  from ('../ics-openvpn/main/') {
//    include '**/ic_filter*.png'
//    include '**/ic_delete*.png'
//    include '**/ic_share*.png'
//    include '**/ic_close*.png'
//    include '**/ic_edit*.png'
//    include '**/ic_check*.png'
//    include '**/ic_pause*.png'
//    include '**/ic_play*.png'
//    include '**/ic_content_copy_white_*.png'
//    include '**/ic_add_circle_outline_white_*.png'
//    include '**/ic_warning_black_*.png'
//    include '**/ic_add_circle_outline_grey600_*.png'
//    include '**/ic_archive_grey600_*.png'
//    include '**/ic_receipt_white_*.png'
//    include '**/ic_sort_white_*.png'
//    include '**/ic_content_copy_white_*.png'
//    include '**/ic_archive_white_*.png'
//    include '**/ic_menu_archive*.png'
//    include '**/vpn_item_settings*.png'
//    include '**/ic_menu_log*.png'
//    include '**/ic_menu_copy_holo_light*.png'
//
//    includeEmptyDirs = false
//  } into '.'
}

// thanks to http://pleac.sourceforge.net/pleac_groovy/fileaccess.html
task removeDuplicatedStrings() {
  println "removeDuplicatedStrings"
  new File('.').eachFileRecurse {
    if(it.name.equals('strings.xml') || it.name.equals('plurals.xml')) {
      replaceDuplicatesForSource(it, it.name.substring(0, it.name.lastIndexOf('.')))
    }
  }
}

def replaceDuplicatesForSource(File it, String type) {
  def ics_openvpn_file = file(it.absolutePath.replace(type+'.xml', type+'-icsopenvpn.xml'))
  if(ics_openvpn_file.exists()) {
    def ics_openvpn_strings_names = (new XmlParser()).parse(ics_openvpn_file)
    def current_file = it

    ics_openvpn_strings_names.string.each {
      processFileInplace(current_file) { text ->
        text.replaceAll('.*name=\"' + it.attribute('name') + '\".*(\n)*.*string>.*\n+', '')
      }
    }
  }
}

task mergeUntranslatable( type: Copy ) {
  println "mergeUntranslatable"
  from ('../ics-openvpn/main/') {
    include '**/untranslatable.xml'
    rename 'untranslatable.xml', 'untranslatable-icsopenvpn.xml'
  } into '.'
  def bitmask_untranslatable = file('src/main/res/values/untranslatable.xml')
  def ics_openvpn_untranslatable = new File(bitmask_untranslatable.path.replace('untranslatable.xml', 'untranslatable-icsopenvpn.xml'))
  ics_openvpn_untranslatable.createNewFile()
  def string_continuation = false;
  ics_openvpn_untranslatable.eachLine { text ->
    if(text.contains('string name=')) {
      if(!bitmask_untranslatable.text.contains(text))
        bitmask_untranslatable << text
      if(text.contains('</string>'))
        string_continuation = true
    }
    else if(string_continuation) {
      bitmask_untranslatable << text
    }

    if(text.contains('</string>')) {
      string_continuation = false
      bitmask_untranslatable << System.getProperty("line.separator")
    }
  }

  bitmask_untranslatable.write(bitmask_untranslatable.text.replaceAll("</resources>", ""))
  bitmask_untranslatable << "</resources>"

  delete ics_openvpn_untranslatable
}

task copyIcsOpenVPNFiles( type: Copy ) {
  println "copyIcsOpenVPNFiles"
  copyIcsOpenVPNClasses.execute()
  copyIcsOpenVPNXml.execute()
  copyIcsOpenVPNImages.execute()
  //mergeUntranslatable.execute()
  removeDuplicatedStrings.execute()
}

task updateIcsOpenVpn( type: Exec ) {
  commandLine 'git', 'submodule', 'sync'
  commandLine 'git', 'submodule', 'update', '--init', '--recursive'
  copyIcsOpenVPNFiles.execute()
}


task cleanNative( type: Delete ) {
  def shouldClean = getCurrentFlavorForBetaOrRelease() == "production"
  println  "cleanNative: " + shouldClean

  if (shouldClean) {
    def dirName = "obj"
    file( dirName ).list().each{
      f -> delete "${dirName}/${f}"
    }
  }
}

task updateSdkLicences ( type: Exec ) {
  println "say yes to licenses"
  commandLine 'sh', 'yes', '|', 'sdkmanager', '--licenses'
}

def getCurrentFlavorForBetaOrRelease() {
  Gradle gradle = getGradle()
  String  tskReqStr = gradle.getStartParameter().getTaskRequests().toString()

  Pattern pattern;

  if( tskReqStr.contains( "assemble" ) )
    pattern = Pattern.compile("assemble(\\w+)(Beta|Release)")
  else
    pattern = Pattern.compile("generate(\\w+)(Beta|Release)")

  Matcher matcher = pattern.matcher( tskReqStr )

  if( matcher.find() )
    return matcher.group(1).toLowerCase()
  else
  {
    return "";
  }
}

def getCurrentFlavor() {
  Gradle gradle = getGradle()
  String tskReqStr = gradle.getStartParameter().getTaskRequests().toString()

  Pattern pattern;

  if (tskReqStr.contains("assemble"))
    pattern = Pattern.compile("assemble(\\w+)(Beta|Release|Debug)")
  else
    pattern = Pattern.compile("generate(\\w+)(Beta|Release|Debug)")

  Matcher matcher = pattern.matcher(tskReqStr)

  if (matcher.find())
    return matcher.group(1).toLowerCase()
  else {
    return "";
  }
}

task checkApplicationIdForCustomFlavor(type: Exec) {
  def currFlavor = getCurrentFlavor()
  if (currFlavor.contains("custom")) {
    android.applicationVariants.all { variant ->
      def mergedFlavor = variant.mergedFlavor
      if (variant.flavorName.toString().equalsIgnoreCase(currFlavor) &&
              mergedFlavor.getApplicationId().equalsIgnoreCase("org.sample.custom"))
        throw new ExecutionException("ERROR: please change the applicationId(org.sample.custom) if you want to build a custom branded app!")
    }
  }
}

task checkAppNameForCustomFlavor(type: Exec) {
  def currFlavor = getCurrentFlavor()
  if (currFlavor.contains("custom") && appName.equalsIgnoreCase("custom"))
    throw new ExecutionException("ERROR: please change the appName(Custom) if you want to build a custom branded app!")
}