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