| 7 |
| apply plugin: 'kotlin-android' |
| 8 | apply plugin: 'kotlin-android-extensions' |
| 9 |
| 10 | def verName = "6.3.0.0-preview-3" |
| 11 | def verCode = 60 |
| 12 |
| 13 | def serviceAccountCredentialsFile = rootProject.file("service_account_credentials.json") |
| 14 |
| 15 | def beta = verName.contains("preview") |
| 16 |
| 17 | if (serviceAccountCredentialsFile.isFile()) { |
| 18 |
| 19 | setupPlay(beta) |
| 20 |
| 21 | play.serviceAccountCredentials = serviceAccountCredentialsFile |
| 22 |
| 23 | } else if (System.getenv().containsKey("ANDROID_PUBLISHER_CREDENTIALS")) { |
| 24 |
| 25 | setupPlay(beta) |
| 26 |
| 27 | } |
| 28 |
| 29 | void setupPlay(boolean beta) { |
| 30 |
| 31 | apply plugin: 'com.github.triplet.play' |
| 32 |
| 33 | play { |
| 34 |
| 35 | track = beta ? "beta" : "production" |
| 36 |
| 37 | defaultToAppBundles = true |
| 38 |
| 39 | userFraction = 1 |
| 40 |
| 41 | } |
| 42 |
| 43 |
| 44 | } |
| 45 |
| 46 | configurations { |
| 47 | compile.exclude module: 'support-v4' |
| 48 | } |
| 49 |
| 50 | def okHttpVersion = '4.8.0' |
| 51 | def fcmVersion = '20.2.3' |
| 52 | def crashlyticsVersion = '17.1.1' |
| 53 | def playCoreVersion = '1.8.0' |
| 54 |
| 55 | buildscript { |
| 56 |
| 57 | repositories { |
| 58 | jcenter() |
| 59 | mavenCentral() |
| 60 | google() |
| 61 | } |
| 62 |
| 63 | dependencies { |
| 64 | classpath 'cn.hutool:hutool-all:5.3.10' |
| 65 | } |
| 66 |
| 67 | } |
| 68 |
| 69 | repositories { |
| 70 |
| 71 | jcenter() |
| 72 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } |
| 73 |
| 74 | } |
| 75 |
| 76 | dependencies { |
| 77 |
| 78 | implementation 'androidx.core:core-ktx:1.5.0-alpha01' |
| 79 | implementation 'androidx.palette:palette-ktx:1.0.0' |
| 80 | implementation 'androidx.viewpager:viewpager:1.0.0' |
| 81 | implementation 'androidx.exifinterface:exifinterface:1.2.0' |
| 82 | implementation "androidx.interpolator:interpolator:1.0.0" |
| 83 | implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0' |
| 84 | implementation 'androidx.multidex:multidex:2.0.1' |
| 85 | implementation "androidx.sharetarget:sharetarget:1.0.0" |
| 86 |
| 87 | // replace zxing with latest |
| 88 | // TODO: fix problem with android L |
| 89 | implementation 'com.google.zxing:core:3.4.0' |
| 90 |
| 91 | compileOnly 'org.checkerframework:checker-qual:3.5.0' |
| 92 | compileOnly 'org.checkerframework:checker-compat-qual:2.5.5' |
| 93 |
| 94 | // don't change this :) |
| 95 | //noinspection GradleDependency |
| 96 | implementation 'com.googlecode.mp4parser:isoparser:1.0.6' |
| 97 |
| 98 | implementation 'com.stripe:stripe-android:2.0.2' |
| 99 | implementation 'com.google.code.gson:gson:2.8.6' |
| 100 | implementation 'org.osmdroid:osmdroid-android:6.1.8' |
| 101 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72" |
| 102 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8' |
| 103 |
| 104 | implementation "com.squareup.okhttp3:okhttp:$okHttpVersion" |
| 105 | implementation "com.squareup.okhttp3:okhttp-dnsoverhttps:$okHttpVersion" |
| 106 | implementation 'dnsjava:dnsjava:3.2.2' |
| 107 | implementation 'org.dizitart:nitrite:3.4.2' |
| 108 |
| 109 | implementation 'cn.hutool:hutool-core:5.3.10' |
| 110 | implementation 'cn.hutool:hutool-crypto:5.3.10' |
| 111 |
| 112 | implementation 'org.tukaani:xz:1.8' |
| 113 | implementation project(":openpgp-api") |
| 114 |
| 115 |
| 116 | compileOnly files('libs/libv2ray.aar') |
| 117 |
| 118 | compileOnly "com.google.firebase:firebase-messaging:$fcmVersion" |
| 119 | compileOnly "com.google.firebase:firebase-crashlytics:$crashlyticsVersion" |
| 120 | compileOnly "com.google.android.play:core:$playCoreVersion" |
| 121 |
| 122 | compileOnly 'com.vanniktech:emoji-ios:0.7.0-SNAPSHOT' |
| 123 | compileOnly 'com.vanniktech:emoji-google:0.7.0-SNAPSHOT' |
| 124 | compileOnly 'com.vanniktech:emoji-twitter:0.7.0-SNAPSHOT' |
| 125 | compileOnly 'com.vanniktech:emoji-facebook:0.7.0-SNAPSHOT' |
| 126 |
| 127 | releaseImplementation "com.google.firebase:firebase-messaging:$fcmVersion" |
| 128 | releaseImplementation "com.google.firebase:firebase-crashlytics:$crashlyticsVersion" |
| 129 | releaseImplementation "com.google.android.play:core:$playCoreVersion" |
| 130 |
| 131 | } |
| 132 |
| 133 | task writeUpdateInfo { |
| 134 |
| 135 | def info = new JSONObject() |
| 136 |
| 137 | info.set("version", verName) |
| 138 | info.set("versionCode", verCode) |
| 139 | info.set("defaultFlavor", "full") |
| 140 | info.set("defaultApkName", "NekoX-full-arm64-v8a-release.apk.xz") |
| 141 |
| 142 | FileUtil.writeUtf8String(info.toStringPretty(), new File("build/update.json")) |
| 143 |
| 144 | } |
| 145 |
| 146 | tasks.findByName("preBuild").finalizedBy(writeUpdateInfo) |
| 147 |
| 148 | android { |
| 149 | compileSdkVersion 30 |
| 150 | buildToolsVersion '30.0.1' |
| 151 | ndkVersion rootProject.ext.ndkVersion |
| 152 |
| 153 | defaultConfig.applicationId = "nekox.messenger" |
| 154 |
| 155 | defaultConfig { |
| 156 | minSdkVersion 16 |
| 157 | //noinspection OldTargetApi |
| 158 | targetSdkVersion 28 |
| 159 |
| 160 | versionName verName |
| 161 | versionCode verCode |
| 162 |
| 163 | def appId = null |
| 164 | def appHash = null |
| 165 |
| 166 | //obtain your own keys at https://core.telegram.org/api/obtaining_api_id |
| 167 |
| 168 | if (project.rootProject.file('local.properties').exists()) { |
| 169 | Properties properties = new Properties() |
| 170 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
| 171 | appId = properties.getProperty("TELEGRAM_APP_ID") ?: System.getenv("TELEGRAM_APP_ID") |
| 172 | appHash = properties.getProperty("TELEGRAM_APP_HASH") ?: System.getenv("TELEGRAM_APP_HASH") |
| 173 | } |
| 174 |
| 175 | buildConfigField 'int', 'APP_ID', appId != null ? appId : "1391584" |
| 176 | buildConfigField 'String', 'APP_HASH', "\"" + (appHash != null ? appHash : "355c91550b0d658cfb7ff89dcf91a08c") + "\"" |
| 177 |
| 178 | externalNativeBuild { |
| 179 | ndkBuild { |
| 180 | arguments "NDK_APPLICATION_MK:=jni/Application.mk", "APP_PLATFORM:=android-16", "--jobs=8" |
| 181 | abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64" |
| 182 | } |
| 183 | } |
| 184 |
| 185 | } |
| 186 |
| 187 | bundle { |
| 188 | language { |
| 189 | enableSplit = false |
| 190 | } |
| 191 | } |
| 192 |
| 193 | externalNativeBuild { |
| 194 | ndkBuild { |
| 195 | path "jni/Android.mk" |
| 196 | } |
| 197 | } |
| 198 |
| 199 | lintOptions { |
| 200 | disable 'MissingTranslation' |
| 201 | disable 'ExtraTranslation' |
| 202 | disable 'BlockedPrivateApi' |
| 203 | } |
| 204 |
| 205 | packagingOptions { |
| 206 |
| 207 | exclude '/fabric/**' |
| 208 | exclude '/META-INF/*.version' |
| 209 | exclude '/META-INF/*.kotlin_module' |
| 210 | exclude '/builddef.lst' |
| 211 | exclude '/*.txt' |
| 212 |
| 213 | } |
| 214 |
| 215 | dexOptions { |
| 216 | jumboMode = true |
| 217 | } |
| 218 |
| 219 | compileOptions { |
| 220 | sourceCompatibility JavaVersion.VERSION_1_8 |
| 221 | targetCompatibility JavaVersion.VERSION_1_8 |
| 222 | } |
| 223 |
| 224 | kotlinOptions { |
| 225 | jvmTarget = JavaVersion.VERSION_1_8.toString() |
| 226 | } |
| 227 |
| 228 | signingConfigs { |
| 229 | def keystorePwd = null |
| 230 | def alias = null |
| 231 | def pwd = null |
| 232 | Properties properties |
| 233 |
| 234 | if (project.rootProject.file('local.properties').exists()) { |
| 235 | properties = new Properties() |
| 236 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
| 237 | } else { |
| 238 | def base64 = System.getenv("LOCAL_PROPERTIES") |
| 239 | if (base64 != null && !base64.isBlank()) { |
| 240 | properties = new Properties() |
| 241 | properties.load(new ByteArrayInputStream(Base64.decoder.decode(base64))) |
| 242 | } |
| 243 | } |
| 244 |
| 245 | if (properties != null) { |
| 246 | keystorePwd = properties.getProperty("KEYSTORE_PASS") |
| 247 | alias = properties.getProperty("ALIAS_NAME") |
| 248 | pwd = properties.getProperty("ALIAS_PASS") |
| 249 | } |
| 250 |
| 251 | keystorePwd = keystorePwd ?: System.getenv("KEYSTORE_PASS") |
| 252 | alias = alias ?: System.getenv("ALIAS_NAME") |
| 253 | pwd = pwd ?: System.getenv("ALIAS_PASS") |
| 254 |
| 255 | release { |
| 256 |
| 257 | storeFile project.file('release.keystore') |
| 258 | storePassword keystorePwd |
| 259 | keyAlias alias |
| 260 | keyPassword pwd |
| 261 | } |
| 262 |
| 263 | } |
| 264 |
| 265 | buildTypes { |
| 266 | debug { |
| 267 | debuggable true |
| 268 | jniDebuggable true |
| 269 | multiDexEnabled true |
| 270 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
| 271 | } |
| 272 |
| 273 | releaseNoGcm { |
| 274 | initWith debug |
| 275 | debuggable false |
| 276 | jniDebuggable false |
| 277 | minifyEnabled true |
| 278 | shrinkResources true |
| 279 | matchingFallbacks = ['debug'] |
| 280 | signingConfig signingConfigs.release |
| 281 | } |
| 282 |
| 283 | release { |
| 284 | initWith releaseNoGcm |
| 285 | } |
| 286 |
| 287 | foss { |
| 288 | initWith release |
| 289 | } |
| 290 | } |
| 291 |
| 292 | sourceSets { |
| 293 |
| 294 | main { |
| 295 | jni.srcDirs = ['./jni/'] |
| 296 | } |
| 297 |
| 298 | debug { |
| 299 | jniLibs.srcDir 'src/main/libs' |
| 300 | } |
| 301 |
| 302 | releaseNoGcm { |
| 303 | jniLibs.srcDir 'src/main/libs' |
| 304 | } |
| 305 |
| 306 | release { |
| 307 | jniLibs.srcDir 'src/main/libs' |
| 308 | manifest.srcFile 'src/gservcies/AndroidManifest.xml' |
| 309 | } |
| 310 |
| 311 | foss { |
| 312 | jni.srcDirs = ['./jni/'] |
| 313 | } |
| 314 |
| 315 | } |
| 316 |
| 317 | splits.abi { |
| 318 |
| 319 | enable true |
| 320 | universalApk true |
| 321 |
| 322 | } |
| 323 |
| 324 | def tgVoipDexFileName = "libtgvoip.dex" |
| 325 | def tgVoipDexClasses = ["AudioRecordJNI", "AudioTrackJNI", "NativeTgVoipDelegate", "NativeTgVoipInstance", "TgVoipNativeLoader", "Resampler", "VLog"] |
| 326 | def tgVoipDexClassesPath = "org/telegram/messenger/voip" |
| 327 | def dxUtilPath = "${sdkDirectory.path}/build-tools/${buildToolsVersion}/dx" |
| 328 |
| 329 | if (System.getProperty("os.name").toLowerCase().contains("windows")) { |
| 330 | dxUtilPath += ".bat" |
| 331 | } |
| 332 |
| 333 | flavorDimensions "version" |
| 334 |
| 335 | productFlavors { |
| 336 | mini { |
| 337 | versionNameSuffix '-mini' |
| 338 | } |
| 339 | miniNoEmoji { |
| 340 | versionNameSuffix '-mini-no-emoji' |
| 341 | } |
| 342 | miniAppleEmoji { |
| 343 | versionNameSuffix '-mini-apple-emoji' |
| 344 | } |
| 345 | miniNotoEmoji { |
| 346 | versionNameSuffix '-mini-noto-emoji' |
| 347 | } |
| 348 | miniTwitterEmoji { |
| 349 | versionNameSuffix '-mini-twitter-emoji' |
| 350 | } |
| 351 | miniFacebookEmoji { |
| 352 | versionNameSuffix '-mini-facebook-emoji' |
| 353 | } |
| 354 | full {} |
| 355 | fullNoEmoji { |
| 356 | versionNameSuffix '-full-no-emoji' |
| 357 | } |
| 358 | fullAppleEmoji { |
| 359 | versionNameSuffix '-full-apple-emoji' |
| 360 | } |
| 361 | fullNotoEmoji { |
| 362 | versionNameSuffix '-full-noto-emoji' |
| 363 | } |
| 364 | fullTwitterEmoji { |
| 365 | versionNameSuffix '-full-twitter-emoji' |
| 366 | } |
| 367 | fullFacebookEmoji { |
| 368 | versionNameSuffix '-full-facebook-emoji' |
| 369 | } |
| 370 | } |
| 371 |
| 372 | sourceSets.all { set -> |
| 373 | if (set.name.startsWith("full")) { |
| 374 | set.dependencies { |
| 375 | implementation files('libs/libv2ray.aar') |
| 376 | implementation files('libs/ss-rust-release.aar') |
| 377 | implementation files('libs/ssr-libev-release.aar') |
| 378 | } |
| 379 | } |
| 380 | if (set.name.matches("(mini|full).*")) { |
| 381 | if (set.name.contains("Apple")) { |
| 382 | set.dependencies { |
| 383 | implementation 'com.vanniktech:emoji-ios:0.7.0-SNAPSHOT' |
| 384 | } |
| 385 | } else if (set.name.contains("Noto")) { |
| 386 | set.dependencies { |
| 387 | implementation 'com.vanniktech:emoji-google:0.7.0-SNAPSHOT' |
| 388 | } |
| 389 | } else if (set.name.contains("Twitter")) { |
| 390 | set.dependencies { |
| 391 | implementation 'com.vanniktech:emoji-twitter:0.7.0-SNAPSHOT' |
| 392 | } |
| 393 | } else if (set.name.contains("Facebook")) { |
| 394 | set.dependencies { |
| 395 | implementation 'com.vanniktech:emoji-facebook:0.7.0-SNAPSHOT' |
| 396 | } |
| 397 | } else if (!set.name.contains("NoEmoji")) { |
| 398 | set.assets.srcDirs = ["src/main/assets", "src/emojis/blob"] |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 |
| 403 | tasks.all { task -> |
| 404 | if (((task.name.endsWith('Ndk') || task.name.startsWith('generateJsonModel') || task.name.startsWith('externalNativeBuild'))) && !task.name.contains("Foss")) { |
| 405 | task.enabled = false |
| 406 | } |
| 407 | if (task.name.contains("uploadCrashlyticsMappingFile")) { |
| 408 | enabled = false |
| 409 | } |
| 410 | } |
| 411 |
| 412 | applicationVariants.all { variant -> |
| 413 | variant.outputs.all { output -> |
| 414 | outputFileName = outputFileName.replace("TMessagesProj", "NekoX") |
| 415 | } |
| 416 |
| 417 | def assembleTgVoipDexTaskName = "assemble${variant.name.capitalize()}TgVoipDex" |
| 418 |
| 419 | task "${assembleTgVoipDexTaskName}" { |
| 420 | doLast { |
| 421 | def sourceDir = (File) android.sourceSets.main.java.srcDirs[0] |
| 422 | def classesDir = "${buildDir}/intermediates/javac/${variant.name}/classes" |
| 423 | def javaDir = "${buildDir}/intermediates/java_tgvoip/${variant.name}/java" |
| 424 | def tgVoipDir = new File(classesDir, tgVoipDexClassesPath) |
| 425 | def javaVoipDirFile = new File(javaDir, tgVoipDexClassesPath) |
| 426 | def tgVoipDexJavaFile = new File(javaVoipDirFile, "TgVoipDex.java") |
| 427 | if (!javaVoipDirFile.exists()) { |
| 428 | javaVoipDirFile.mkdirs() |
| 429 | } |
| 430 | def assetsDirFile = new File(buildDir, "intermediates/merged_assets/${variant.name}/out") |
| 431 | if (!assetsDirFile.exists()) { |
| 432 | assetsDirFile.mkdirs() |
| 433 | } |
| 434 | def tgVoipDexFile = new File(assetsDirFile, tgVoipDexFileName) |
| 435 |
| 436 | def classes = tgVoipDir.list(new FilenameFilter() { |
| 437 | @Override |
| 438 | boolean accept(File dir, String name) { |
| 439 | // handle inner and anonymous classes |
| 440 | return tgVoipDexClasses.any { name == "${it}.class" || name.startsWith("${it}\$") && name.endsWith(".class") } |
| 441 | } |
| 442 | }).collect { "${tgVoipDexClassesPath}/${it}" } |
| 443 |
| 444 | // 1. create libtgvoip.dex |
| 445 | exec { |
| 446 | workingDir classesDir |
| 447 | commandLine([dxUtilPath, "--dex", "--output=${tgVoipDexFile}"] + classes) |
| 448 | } |
| 449 |
| 450 | // 2. remove classes from the main dex |
| 451 | project.delete classes.collect { "${classesDir}/${it}" } |
| 452 |
| 453 | // 3. insert checksum of libtgvoip.dex into TgVoipDex.java |
| 454 | def digest = MessageDigest.getInstance("SHA1") |
| 455 | def fileInputStream = tgVoipDexFile.newInputStream() |
| 456 | def buffer = new byte[4096] |
| 457 | def len |
| 458 | while ((len = fileInputStream.read(buffer)) > 0) { |
| 459 | digest.update(buffer, 0, len) |
| 460 | } |
| 461 | def dexChecksum = new String(Base64.getEncoder().encode(digest.digest())).trim() |
| 462 | tgVoipDexJavaFile.write(new String(new File(sourceDir, "${tgVoipDexClassesPath}/TgVoipDex.java").readBytes()).replace("\$CHECKSUM\$", dexChecksum)) |
| 463 | exec { |
| 464 | commandLine([findJavac(), "-d", classesDir, tgVoipDexJavaFile.absolutePath]) |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 |
| 469 | tasks.findByName("compile${variant.name.capitalize()}JavaWithJavac").finalizedBy(assembleTgVoipDexTaskName) |
| 470 | tasks.findByName("${assembleTgVoipDexTaskName}").mustRunAfter tasks.findByName("merge${variant.name.capitalize()}Assets") |
| 471 | } |
| 472 |
| 473 | } |
| 474 |
| 475 | private static File findJavaHome() { |
| 476 | String javaPath = System.getProperty("java.home") |
| 477 | if (javaPath != null) { |
| 478 | File javaBase = new File(javaPath) |
| 479 | if (javaBase.exists()) { |
| 480 | if (javaBase.getName().equalsIgnoreCase("jre") && new File(javaBase.getParentFile(), System.getProperty("os.name").toLowerCase().contains("windows") ? "bin/java.exe" : "bin/java").exists()) { |
| 481 | return javaBase.getParentFile() |
| 482 | } else { |
| 483 | return javaBase |
| 484 | } |
| 485 | } else { |
| 486 | return null |
| 487 | } |
| 488 | } else { |
| 489 | return null |
| 490 | } |
| 491 | } |
| 492 |
| 493 | private static File findJavac() { |
| 494 | File javaHome = findJavaHome() |
| 495 | if (javaHome != null) { |
| 496 | if (System.getProperty("os.name").toLowerCase().contains("windows")) { |
| 497 | return new File(javaHome.getParent(), "bin/javac.exe") |
| 498 | } else { |
| 499 | return new File(javaHome, "bin/javac") |
| 500 | } |
| 501 | } else { |
| 502 | return null |
| 503 | } |
| 504 | } |
| 505 |
| 506 | apply plugin: 'com.google.gms.google-services' |
| 507 | apply plugin: 'com.google.firebase.crashlytics' |
| 508 |
| 509 | android { |
| 510 |
| 511 | tasks.all { task -> |
| 512 | if (task.name.startsWith('uploadCrashlyticsMappingFile')) { |
| 513 | task.enabled = false |
| 514 | } else if (((task.name.contains('Crashlytics'))) && !task.name.endsWith("Release")) { |
| 515 | task.enabled = false |
| 516 | } else if (((task.name.endsWith('GoogleServices'))) && !task.name.endsWith("ReleaseGoogleServices")) { |
| 517 | task.enabled = false |
| 518 | } |
| 519 | } |
| 520 |
| 521 | } |