summaryrefslogtreecommitdiff
path: root/app/build.gradle
blob: ccd54dc94b455eb58e15069e45e5aafd7e3dad2d (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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
import java.util.regex.Matcher
import java.util.regex.Pattern

apply plugin: 'com.android.application'

android {
  ndkVersion "21.4.7075529"
  namespace = "se.leap.bitmaskclient"

  compileOptions {
    targetCompatibility = JavaVersion.VERSION_17
    sourceCompatibility = JavaVersion.VERSION_17
  }

  viewBinding {
    enabled = true
  }

  packaging {
    jniLibs {
      useLegacyPackaging = true
    }
  }

  buildFeatures {
    buildConfig true
    aidl true
  }

  defaultConfig {
    applicationId "se.leap.bitmaskclient"
    // the factor 1000 is used so that gplay users can upgrade from split apks ((current version number - 1) * 1000) + n
    // to extracted bundle apks, supplied by google
    // however we don't calculate the versionCode here, because F-Droid doesn't like that
    versionCode 177000
    versionName "1.5.0RC1"
    compileSdk 34
    minSdkVersion 21
    targetSdkVersion 34
    vectorDrawables.useSupportLibrary = true
    buildConfigField 'boolean', 'openvpn3', 'false'


    //Build Config Fields for default donation details

    // preferred API version the client should client try in case the provider supports it
    // If the provider doesn't the client falls back to lower available API versions
    buildConfigField 'int', 'preferred_client_api_version', '5'
    //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://riseuplabs.org/leap"'
    // custom donation url, only used in Custom flavor
    buildConfigField 'String', 'donation_url', 'null'
    //The field to enable donations in the app.
    buildConfigField 'boolean', 'enable_donation', 'false'
    //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', '7'
    //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'
    //allow manual gateway selection
    buildConfigField 'boolean', 'allow_manual_gateway_selection', 'true'
    // obfsvpn Debugging config fields to pin and configure a particular proxy
    // demo.bitmask.net provider
    buildConfigField "String", "obfsvpn_port", '"4431"'
    buildConfigField "String", "obfsvpn_ip", '"37.218.241.208"'
    buildConfigField "String", "obfsvpn_cert", '"k0L4LFg0Wk98v7P66xvgAx2ud+kggvjZX/qul3iFTJGH5X7xSHT+vVL4UZR0WI3SkmDzUg"'
    buildConfigField 'boolean', 'obfsvpn_use_kcp', 'true'
    // default to UDP usage
    buildConfigField 'boolean', 'prefer_udp', 'false'

    // static update url pointing to the latest stable release apk
    buildConfigField "String", "update_apk_url", '"https://dl.bitmask.net/client/android/Bitmask-Android-latest.apk"'
    // the the pgp signature file of the apk
    buildConfigField "String", "signature_url", '"https://dl.bitmask.net/client/android/Bitmask-Android-latest.apk.sig"'
    // the version file contains the versionCode of the latest release
    buildConfigField "String", "version_file_url", '"https://dl.bitmask.net/client/android/versioncode.txt"'

    // if center_actionbar_title is set to true, the actionbar title and subtitle will be centered, otherwise default
    buildConfigField 'boolean', 'actionbar_center_title', 'true'
    buildConfigField 'boolean', 'actionbar_capitalize_title', 'true'

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

    ndk {
      abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
    }

    bundle {
      language {
        enableSplit = true
      }
      density {
        enableSplit = true
      }
      abi {
        enableSplit = true
      }
    }
  }

  flavorDimensions "branding", "implementation", "abi"
  productFlavors {
    productFlavors.all {
      ext.appName = null
      ext.splitApk = false
    }
    production {
      dimension "implementation"
    }

    normal {
      dimension "branding"
      appName = "Bitmask"
      splitApk = true
    }

    custom {
      dimension "branding"

      //**************************************************************************
      //**************************************************************************
      //Configurations for custom branded app.
      //
      //In order to configure the URLs for your custom provider (required!), please
      //check out app/src/custom/README.md
      //
      //Change the package name as needed, e.g. "org.example.myapp"
      applicationId "se.leap.riseupvpn"
      //Set app name here
      appName = "Riseup VPN"
      //Change the versionCode as needed
      //versionCode 1
      //Change the versionName as needed
      //versionName "0.9.9RC1"


      // preferred API version the client should client try in case the provider supports it
      // If the provider doesn't the client falls back to lower available API versions
      buildConfigField 'int', 'preferred_client_api_version', '5'
      //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'
      //allow manual gateway selection
      buildConfigField 'boolean', 'allow_manual_gateway_selection', 'true'
      // obfsvpn Debugging config fields to pin and configure a particular proxy
      buildConfigField "String", "obfsvpn_port", '"443"'
      buildConfigField "String", "obfsvpn_ip", '"159.223.173.205"'
      buildConfigField "String", "obfsvpn_cert", '"8nuAbPJwFrKc/29KcCfL5LBuEWxQrjBASYXdUbwcm9d9pKseGK4r2Tg47e23+t6WghxGGw"'
      buildConfigField 'boolean', 'obfsvpn_use_kcp', 'true'
      // default to UDP usage
      buildConfigField 'boolean', 'prefer_udp', 'true'

      //Build Config Fields for automatic apk update checks

      // static update url pointing to the latest stable release apk
      def apkURL = '"https://dl.bitmask.net/RiseupVPN/android/RiseupVPN-Android-latest.apk"'
      buildConfigField "String", "update_apk_url", apkURL
      // the the pgp signature file of the apk
      def signatureURL = '"https://dl.bitmask.net/RiseupVPN/android/RiseupVPN-Android-latest.apk.sig"'
      buildConfigField "String", "signature_url", signatureURL
      // the version file should contain a single line with the versionCode of the latest release
      buildConfigField "String", "version_file_url", '"https://dl.bitmask.net/client/android/versioncode.txt"' //'"https://dl.bitmask.net/RiseupVPN/android/versioncode.txt"'

      //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', '7'

      // ActionBar design

      // if center_actionbar_title is set to true, the actionbar title and subtitle will be centered, otherwise default
      buildConfigField 'boolean', 'actionbar_center_title', 'true'
      buildConfigField 'boolean', 'actionbar_capitalize_title', 'false'

      // Build apks for each architecture, in addition to one 'fat' apk containing libraries for all all architectures
      // enable this if you're publishing in gplay
      ext {
        splitApk = true
      }

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

    }

    fatweb {
      dimension "abi"
      ext {
        abiVersionCode = 0
        abiFilter = "web"
      }
    }

    fat {
      dimension "abi"
      ext {
        abiVersionCode = 0
        abiFilter = ""
      }
    }

    x86 {
      dimension "abi"
      ndk {
        abiFilters "x86"
      }
      ext {
        abiVersionCode = 1
        abiFilter = "x86"
      }
    }

    armv7 {
      dimension "abi"
      ndk {
        abiFilters "armeabi-v7a"
      }
      ext {
        abiVersionCode = 2
        abiFilter = "armeabi-v7a"
      }
    }

    x86_64 {
      dimension "abi"
      ndk {
        abiFilters "x86_64"
      }
      ext {
        abiVersionCode = 3
        abiFilter = "x86_64"
      }
    }

    arm64 {
      dimension "abi"
      ndk {
        abiFilters "arm64-v8a"
      }
      ext {
        abiVersionCode = 4
        abiFilter = "arm64-v8a"
      }
    }
  }

  buildTypes {
    buildTypes.all {
      ext.appSuffix = ""
    }
    release {
      //runProguard true
      //ndk.debugSymbolLevel = "full"
      //minifyEnabled = true
      //shrinkResources true
      buildConfigField "Boolean", "DEBUG_MODE", "false"
    }
    beta {
      initWith release
      applicationIdSuffix ".beta"
      appSuffix = " Beta"
      buildConfigField "Boolean", "DEBUG_MODE", "true"
      testCoverageEnabled = false

      // tor-android doesn't know this build-type, fallback to release in that case
      matchingFallbacks = ['release']
    }
    debug {
      testCoverageEnabled = false
      buildConfigField "Boolean", "DEBUG_MODE", "true"
    }
  }

  lintOptions {
    abortOnError false
  }

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

    }
    debug {
      assets.srcDirs = ['src/debug/assets']
    }

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

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

    fat {
      java.srcDirs += ['src/notFatweb/java']
    }

    x86 {
      java.srcDirs += ['src/notFatweb/java']
    }

    x86_64 {
      java.srcDirs += ['src/notFatweb/java']
    }

    armv7 {
      java.srcDirs += ['src/notFatweb/java']
    }

    arm64 {
      java.srcDirs += ['src/notFatweb/java']
    }

  }

  /**
   * BUILD VARAIANTS:
   * =================
   * Development builds:
   * --------------------
   * customProductionFatDebug -> branded development build, includes all ABIs
   * normalProductionFatDebug -> Bitmask development build, includes all ABIS
   * customProductionFatwebDebug -> branded development build, includes all ABIs, for distribution through a download page
   * normalProductionFatWebDebug ->  Bitmask development build, includes all ABIS, for distribution through a download page
   *
   * Branded Releases:
   * -----------------
   * customProductionFatBeta -> branded build, includes all ABI's, Beta release
   * customProductionFatRelease -> branded build, includes all ABI's, stable release (-> F-Droid, GPlay if not splitApk is set to true)
   * customProductionFatwebRelease -> branded build, includes all ABI's, stable release (-> F-Droid, GPlay if not splitApk is set to true), for distribution through a download page
   *
   * Bitmask Beta releases:
   * ----------------------
   * normalProductionArm64Beta  ->  Bitmask build, only for ABI arm64, for GPlay Beta channel with split apks (1 of 4)
   * normalProductionArmv7Beta  ->  Bitmask build, only for ABI armeabi-v7a, for GPlay Beta channel with split apks (2 of 4)
   * normalProductionX86Beta    ->  Bitmask build, only for ABI x86, for GPlay Beta channel with split apks (3 of 4)
   * normalProductionX86_64Beta ->  Bitmask build, only for ABI x86 64 bit, for GPlay Beta channel with split apks (4 of 4)
   * normalProductionFatBeta    ->  Bitmask build, including all ABIS, for izzysoft's F-Droid repo and beta link on download page
   *
   * Bitmask Stable releases:
   * ------------------------
   * normalProductionArm64Release  ->  Bitmask build, only for ABI arm64, for GPlay releases with split apks (1 of 4)
   * normalProductionArmv7Release  ->  Bitmask build, only for ABI armeabi-v7a, for GPlay releases with split apks (2 of 4)
   * normalProductionX86Release    ->  Bitmask build, only for ABI x86, for GPlay releases with split apks (3 of 4)
   * normalProductionX86_64Release ->  Bitmask build, only for ABI x86 64 bit, for GPlay releases with split apks (4 of 4)
   * normalProductionFatRelease    ->  Bitmask build, including all ABIS, for official F-Droid repo
   * normalProductionFatWebRelease ->  Bitmask build, including all ABIS, for distribution through a download page
   */

  variantFilter { variant ->

    def names = variant.flavors*.name
    def buildTypeName = variant.buildType.name
    // flavorDimensions "branding" -> 0, "implementation" -> 1, "abi" -> 2
    def supportsSplitApk = variant.flavors[0].splitApk
    def branding = variant.flavors[0].name
    // To check for a certain build type, use variant.buildType.name == "<buildType>"
    if (((buildTypeName.contains("debug") && !(names.contains("fatweb") || names.contains("fat"))) ||
            (names.contains("fatweb") && buildTypeName.contains("beta")) ||
            (!supportsSplitApk && !names.contains("fat")))
    ) {
      // Gradle ignores any variants that satisfy the conditions above.
      setIgnore(true)
    }
  }
}

dependencies {
  testImplementation 'junit:junit:4.13.2'
  //outdated mockito-core version due to powermock dependency
  testImplementation 'org.mockito:mockito-core:3.6.0'
  testImplementation('org.powermock:powermock-api-mockito2:2.0.9')
       //   { exclude group: 'junit' exclude group: 'org.mockito' }

  testImplementation 'org.robolectric:robolectric:4.13'
  testImplementation 'org.conscrypt:conscrypt-openjdk-uber:2.5.2'

  testImplementation 'org.powermock:powermock-module-junit4:2.0.9'
  testImplementation 'org.powermock:powermock-core:2.0.9'
  testImplementation 'org.powermock:powermock-module-junit4-rule:2.0.9'
  testImplementation group: 'com.tngtech.java', name: 'junit-dataprovider', version: '1.10.0'

  androidTestImplementation 'org.mockito:mockito-core:3.9.0'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
  androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.5.0'
  androidTestImplementation 'androidx.test.espresso:espresso-intents:3.5.0'
  androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'

  androidTestImplementation 'tools.fastlane:screengrab:2.1.1'
  testImplementation 'tools.fastlane:screengrab:2.1.1'

  testImplementation 'org.json:json:20180813'
  androidTestImplementation 'androidx.test.ext:junit:1.1.4'
  debugImplementation 'com.squareup.leakcanary:leakcanary-android-core:2.9.1'
  debugImplementation 'androidx.fragment:fragment-testing:1.6.2'
  debugImplementation 'androidx.test:core:1.5.0'

  implementation 'com.google.code.gson:gson:2.10.1'
  implementation 'com.squareup.okhttp3:okhttp:4.10.0'
  implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.10.0'
  implementation 'org.conscrypt:conscrypt-android:2.5.2'
  implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
  implementation 'androidx.security:security-crypto:1.1.0-alpha06'
  implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
  implementation 'androidx.annotation:annotation:1.7.0'
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  implementation 'androidx.core:core:1.12.0'
  implementation 'androidx.appcompat:appcompat:1.6.1'
  implementation 'com.google.android.material:material:1.10.0'
  implementation 'androidx.fragment:fragment:1.6.2'
  implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
  implementation 'androidx.multidex:multidex:2.0.1'
  implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
  implementation 'androidx.lifecycle:lifecycle-process:2.7.0'
  implementation 'de.hdodenhof:circleimageview:3.1.0'
  // swagger dependencies
  implementation 'io.swagger:swagger-annotations:1.5.17'
  implementation 'io.gsonfire:gson-fire:1.8.0'
  implementation 'org.threeten:threetenbp:1.3.5'


  // Start:: CameraX dependencies
  implementation 'com.google.mlkit:barcode-scanning:17.3.0'
  implementation 'androidx.camera:camera-core:1.3.4'
  implementation 'androidx.camera:camera-camera2:1.3.4'
  implementation 'androidx.camera:camera-lifecycle:1.3.4'
  implementation 'androidx.camera:camera-view:1.3.4'
  implementation 'androidx.camera:camera-mlkit-vision:1.4.0-rc04'
  // End:: CameraX dependencies


  //implementation 'info.guardianproject:tor-android:0.4.5.7'
  //implementation 'info.guardianproject:jtorctl:0.4.5.7'
  implementation project(path: ':tor-android:tor-android-binary')

  fatwebImplementation project(path: ':lib-bitmask-core-web')
  fatImplementation project(path: ':lib-bitmask-core')
  x86Implementation project(path: ':lib-bitmask-core-x86')
  x86_64Implementation project(path: ':lib-bitmask-core-x86_64')
  armv7Implementation project(path: ':lib-bitmask-core-armv7')
  arm64Implementation project(path: ':lib-bitmask-core-arm64')
}

android.applicationVariants.all { variant ->
  // configure app name and apk file name for different build variants
  def flavors = variant.productFlavors
  // flavorDimensions "branding" -> 0, "implementation" -> 1, "abi" -> 2
  def branding = flavors[0]
  def trimmedAppName = branding.appName.replaceAll(' ', '')
  def abiDimension = flavors[2]
  def abiFilter = abiDimension.abiFilter
  if (abiFilter.length() > 0) {
    abiFilter = "_"+abiFilter
  }
  def buildType = variant.buildType
  def tag = getTag()
  if (tag.length() > 0) {
    tag = "_"+tag
  }

  variant.resValue "string", "app_name",  "\"${branding.appName}${buildType.appSuffix}\""

  variant.outputs.all { output ->
    output.outputFileName = "${trimmedAppName}${abiFilter}_${buildType.name}${tag}.apk"
  }

  // reconfigure version codes for split builds
  variant.outputs.each { output ->
      // if not a fat build
      if (abiDimension.abiVersionCode > 0) {
          output.versionCodeOverride = android.defaultConfig.versionCode + abiDimension.abiVersionCode
      }
  }

  // remove unrelated abi specific assets
  variant.mergeAssetsProvider.get().doLast {
    // if not a fat build
    if (abiDimension.abiVersionCode > 0) {
      def filesToDelete = fileTree(dir: variant.mergeAssets.outputDir, excludes: ["*pie_openvpn.${abiDimension.abiFilter}",
                                                                                  'urls/',
                                                                                  '*.url',
                                                                                  '*.json',
                                                                                  '*.pem',
                                                                                  'fronts'])
      delete(filesToDelete)
    }
  }
}

subprojects {
  afterEvaluate {project ->
    if (project.hasProperty("android")) {
      android {
        compileSdkVersion 34
      }
    }
  }
}

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

def getTag() {
  String commit = "git log --pretty=format:'%h' -n 1".execute().text.trim().replaceAll("'", "")
  return ("git describe --tags --exact-match "+ commit).execute().text.trim()
}

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 "";
  }
}