Nagram/TMessagesProj/build.gradle

520 lines
16 KiB
Groovy
Raw Normal View History

2020-06-24 16:15:30 +00:00
import cn.hutool.core.io.FileUtil
import cn.hutool.json.JSONObject
2020-03-30 12:00:09 +00:00
import java.security.MessageDigest
apply plugin: 'com.android.application'
2020-06-24 16:15:30 +00:00
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
2013-10-25 15:19:00 +00:00
2020-07-08 04:00:22 +00:00
def serviceAccountCredentialsFile = rootProject.file("service_account_credentials.json")
if (serviceAccountCredentialsFile.isFile()) {
setupPlay()
play.serviceAccountCredentials = serviceAccountCredentialsFile
} else if (System.getenv().containsKey("ANDROID_PUBLISHER_CREDENTIALS")) {
setupPlay()
}
void setupPlay() {
apply plugin: 'com.github.triplet.play'
play {
track = "production"
defaultToAppBundles = true
userFraction = 1
}
}
2016-10-11 11:57:01 +00:00
configurations {
compile.exclude module: 'support-v4'
}
2020-07-19 07:44:11 +00:00
def okHttpVersion = '4.8.0'
def fcmVersion = '20.2.3'
2020-07-08 04:00:22 +00:00
def crashlyticsVersion = '17.1.1'
2020-06-24 16:15:30 +00:00
def playCoreVersion = '1.7.3'
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
2020-06-25 14:01:18 +00:00
classpath "cn.hutool:hutool-all:5.3.8"
2020-06-24 16:15:30 +00:00
}
}
2020-07-08 03:28:13 +00:00
repositories {
2020-07-19 07:44:11 +00:00
jcenter()
2020-07-08 03:28:13 +00:00
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
2013-10-25 15:19:00 +00:00
dependencies {
2020-06-24 16:15:30 +00:00
implementation 'androidx.core:core:1.5.0-alpha01'
2019-05-14 12:08:05 +00:00
implementation 'androidx.palette:palette:1.0.0'
implementation 'androidx.viewpager:viewpager:1.0.0'
2020-04-30 19:07:00 +00:00
implementation 'androidx.exifinterface:exifinterface:1.2.0'
2020-06-24 16:15:30 +00:00
implementation "androidx.interpolator:interpolator:1.0.0"
2020-04-24 09:21:58 +00:00
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
implementation 'com.android.support:multidex:1.0.3'
2019-05-14 12:08:05 +00:00
2020-06-25 14:01:18 +00:00
// replace zxing with latest
// TODO: fix problem with android L
implementation 'com.google.zxing:core:3.4.0'
2020-07-02 09:08:56 +00:00
compileOnly 'org.checkerframework:checker-qual:3.5.0'
compileOnly 'org.checkerframework:checker-compat-qual:2.5.5'
2020-07-02 09:08:56 +00:00
// don't change this :)
//noinspection GradleDependency
implementation 'com.googlecode.mp4parser:isoparser:1.0.6'
2018-08-27 08:33:11 +00:00
implementation 'com.stripe:stripe-android:2.0.2'
2020-01-18 11:57:04 +00:00
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.osmdroid:osmdroid-android:6.1.6'
2020-06-24 16:15:30 +00:00
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72"
2020-07-19 07:44:11 +00:00
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'
2020-06-24 16:15:30 +00:00
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
implementation "com.squareup.okhttp3:okhttp-dnsoverhttps:$okHttpVersion"
2020-07-19 07:44:11 +00:00
implementation 'dnsjava:dnsjava:3.2.2'
2020-06-24 16:15:30 +00:00
implementation 'org.dizitart:nitrite:3.4.2'
2020-07-19 07:44:11 +00:00
implementation 'cn.hutool:hutool-core:5.3.9'
implementation 'cn.hutool:hutool-crypto:5.3.9'
2020-06-24 16:15:30 +00:00
implementation 'org.tukaani:xz:1.8'
2020-07-19 07:44:11 +00:00
implementation project(":openpgp-api")
2020-06-24 16:15:30 +00:00
compileOnly files('libs/libv2ray.aar')
compileOnly "com.google.firebase:firebase-messaging:$fcmVersion"
compileOnly "com.google.firebase:firebase-crashlytics:$crashlyticsVersion"
compileOnly "com.google.android.play:core:$playCoreVersion"
2020-07-08 03:28:13 +00:00
compileOnly 'com.vanniktech:emoji-ios:0.7.0-SNAPSHOT'
compileOnly 'com.vanniktech:emoji-google:0.7.0-SNAPSHOT'
compileOnly 'com.vanniktech:emoji-twitter:0.7.0-SNAPSHOT'
compileOnly 'com.vanniktech:emoji-facebook:0.7.0-SNAPSHOT'
2020-06-24 16:15:30 +00:00
releaseImplementation "com.google.firebase:firebase-messaging:$fcmVersion"
releaseImplementation "com.google.firebase:firebase-crashlytics:$crashlyticsVersion"
releaseImplementation "com.google.android.play:core:$playCoreVersion"
}
2020-06-24 16:15:30 +00:00
2020-07-08 04:00:22 +00:00
def verName = "6.2.0.3-rc03"
def verCode = 56
2020-06-24 16:15:30 +00:00
task writeUpdateInfo {
def info = new JSONObject()
info.set("version", verName)
info.set("versionCode", verCode)
info.set("defaultFlavor", "full")
info.set("defaultApkName", "NekoX-full-arm64-v8a-release.apk.xz")
FileUtil.writeUtf8String(info.toStringPretty(), new File("build/update.json"))
2019-06-11 05:56:33 +00:00
}
2020-06-24 16:15:30 +00:00
tasks.findByName("preBuild").finalizedBy(writeUpdateInfo)
2013-10-25 15:19:00 +00:00
android {
2019-12-31 13:08:08 +00:00
compileSdkVersion 29
2020-03-30 12:00:09 +00:00
buildToolsVersion '29.0.3'
2020-06-24 16:15:30 +00:00
ndkVersion rootProject.ext.ndkVersion
defaultConfig.applicationId = "nekox.messenger"
2017-12-08 17:35:59 +00:00
2020-06-24 16:15:30 +00:00
defaultConfig {
minSdkVersion 16
//noinspection OldTargetApi
targetSdkVersion 28
2015-10-29 17:10:07 +00:00
2020-06-24 16:15:30 +00:00
versionName verName
versionCode verCode
def appId = null
def appHash = null
//obtain your own keys at https://core.telegram.org/api/obtaining_api_id
if (project.rootProject.file('local.properties').exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
appId = properties.getProperty("TELEGRAM_APP_ID") ?: System.getenv("TELEGRAM_APP_ID")
appHash = properties.getProperty("TELEGRAM_APP_HASH") ?: System.getenv("TELEGRAM_APP_HASH")
}
buildConfigField 'int', 'APP_ID', appId != null ? appId : "1391584"
buildConfigField 'String', 'APP_HASH', "\"" + (appHash != null ? appHash : "355c91550b0d658cfb7ff89dcf91a08c") + "\""
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK:=jni/Application.mk", "APP_PLATFORM:=android-16", "--jobs=8"
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
}
}
bundle {
language {
enableSplit = false
}
}
2016-10-11 11:57:01 +00:00
externalNativeBuild {
ndkBuild {
path "jni/Android.mk"
}
}
2018-07-30 02:07:02 +00:00
lintOptions {
disable 'MissingTranslation'
disable 'ExtraTranslation'
2019-09-10 10:56:11 +00:00
disable 'BlockedPrivateApi'
2018-07-30 02:07:02 +00:00
}
2020-06-24 16:15:30 +00:00
packagingOptions {
exclude '/fabric/**'
exclude '/META-INF/*.version'
exclude '/META-INF/*.kotlin_module'
exclude '/builddef.lst'
exclude '/*.txt'
}
2017-03-30 23:58:05 +00:00
dexOptions {
jumboMode = true
}
2015-01-02 22:15:07 +00:00
compileOptions {
2018-08-27 08:33:11 +00:00
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
2015-01-02 22:15:07 +00:00
}
2020-06-24 16:15:30 +00:00
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
2013-12-20 19:25:49 +00:00
signingConfigs {
2020-01-28 07:01:42 +00:00
def keystorePwd = null
def alias = null
def pwd = null
2020-06-24 16:15:30 +00:00
Properties properties
2020-01-28 07:01:42 +00:00
if (project.rootProject.file('local.properties').exists()) {
2020-06-24 16:15:30 +00:00
properties = new Properties()
2020-01-28 07:01:42 +00:00
properties.load(project.rootProject.file('local.properties').newDataInputStream())
2020-06-24 16:15:30 +00:00
} else {
def base64 = System.getenv("LOCAL_PROPERTIES")
if (base64 != null && !base64.isBlank()) {
properties = new Properties()
properties.load(new ByteArrayInputStream(Base64.decoder.decode(base64)))
}
2020-01-28 07:01:42 +00:00
}
2020-06-24 16:15:30 +00:00
if (properties != null) {
keystorePwd = properties.getProperty("KEYSTORE_PASS")
alias = properties.getProperty("ALIAS_NAME")
pwd = properties.getProperty("ALIAS_PASS")
}
keystorePwd = keystorePwd ?: System.getenv("KEYSTORE_PASS")
alias = alias ?: System.getenv("ALIAS_NAME")
pwd = pwd ?: System.getenv("ALIAS_PASS")
2019-06-11 05:56:33 +00:00
release {
2020-06-24 16:15:30 +00:00
storeFile project.file('release.keystore')
storePassword keystorePwd
keyAlias alias
keyPassword pwd
2013-12-20 19:25:49 +00:00
}
2020-06-24 16:15:30 +00:00
2013-12-20 19:25:49 +00:00
}
buildTypes {
debug {
debuggable true
2014-11-10 11:05:22 +00:00
jniDebuggable true
2020-04-24 09:21:58 +00:00
multiDexEnabled true
2020-06-25 16:44:36 +00:00
signingConfig signingConfigs.release
2019-12-31 13:08:08 +00:00
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2020-06-24 16:15:30 +00:00
}
2019-12-31 13:08:08 +00:00
2020-06-24 16:15:30 +00:00
releaseNoGcm {
initWith debug
2019-01-23 17:03:33 +00:00
debuggable false
jniDebuggable false
minifyEnabled true
2020-06-24 16:15:30 +00:00
shrinkResources true
2020-07-19 07:44:11 +00:00
matchingFallbacks = ['debug']
2019-01-23 17:03:33 +00:00
}
2013-12-20 19:25:49 +00:00
release {
2020-06-24 16:15:30 +00:00
initWith releaseNoGcm
2020-07-19 07:44:11 +00:00
matchingFallbacks = ['debug']
2020-06-24 16:15:30 +00:00
}
foss {
initWith release
2020-07-19 07:44:11 +00:00
matchingFallbacks = ['debug']
2013-12-20 19:25:49 +00:00
}
}
2020-07-08 04:00:22 +00:00
sourceSets {
2014-11-21 19:36:21 +00:00
2020-07-08 04:00:22 +00:00
main {
jni.srcDirs = ['./jni/']
}
2020-06-24 16:15:30 +00:00
2020-07-08 04:00:22 +00:00
debug {
jniLibs.srcDir 'src/main/libs'
}
2020-06-24 16:15:30 +00:00
2020-07-08 04:00:22 +00:00
releaseNoGcm {
jniLibs.srcDir 'src/main/libs'
}
2020-06-24 16:15:30 +00:00
2020-07-08 04:00:22 +00:00
release {
jniLibs.srcDir 'src/main/libs'
manifest.srcFile 'src/gservcies/AndroidManifest.xml'
}
2020-06-24 16:15:30 +00:00
2020-07-08 04:00:22 +00:00
foss {
jni.srcDirs = ['./jni/']
}
2020-06-24 16:15:30 +00:00
2020-07-08 04:00:22 +00:00
}
2020-06-24 16:15:30 +00:00
2020-07-08 04:00:22 +00:00
splits.abi {
2017-12-08 17:35:59 +00:00
2020-07-08 04:00:22 +00:00
enable true
universalApk true
2016-03-16 12:26:32 +00:00
2020-06-24 16:15:30 +00:00
}
2020-03-30 12:00:09 +00:00
def tgVoipDexFileName = "libtgvoip.dex"
def tgVoipDexClasses = ["AudioRecordJNI", "AudioTrackJNI", "NativeTgVoipDelegate", "NativeTgVoipInstance", "TgVoipNativeLoader", "Resampler", "VLog"]
def tgVoipDexClassesPath = "org/telegram/messenger/voip"
def dxUtilPath = "${sdkDirectory.path}/build-tools/${buildToolsVersion}/dx"
2020-06-24 16:15:30 +00:00
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
dxUtilPath += ".bat"
}
2019-05-14 12:08:05 +00:00
2020-06-24 16:15:30 +00:00
flavorDimensions "version"
2019-05-14 12:08:05 +00:00
2020-06-24 16:15:30 +00:00
productFlavors {
mini {
versionNameSuffix '-mini'
}
2020-07-08 03:28:13 +00:00
miniNoEmoji {
versionNameSuffix '-mini-no-emoji'
}
miniAppleEmoji {
versionNameSuffix '-mini-apple-emoji'
}
miniNotoEmoji {
versionNameSuffix '-mini-noto-emoji'
}
miniTwitterEmoji {
versionNameSuffix '-mini-twitter-emoji'
}
miniFacebookEmoji {
versionNameSuffix '-mini-facebook-emoji'
}
2020-06-24 16:15:30 +00:00
full {}
2020-07-08 03:28:13 +00:00
fullNoEmoji {
versionNameSuffix '-full-no-emoji'
}
fullAppleEmoji {
versionNameSuffix '-full-apple-emoji'
}
fullNotoEmoji {
versionNameSuffix '-full-noto-emoji'
}
fullTwitterEmoji {
versionNameSuffix '-full-twitter-emoji'
}
fullFacebookEmoji {
versionNameSuffix '-full-facebook-emoji'
}
2020-06-24 16:15:30 +00:00
}
2019-05-14 12:08:05 +00:00
2020-07-08 03:28:13 +00:00
sourceSets.all { set ->
if (set.name.startsWith("full")) {
set.dependencies {
implementation files('libs/libv2ray.aar')
implementation files('libs/ss-rust-release.aar')
implementation files('libs/ssr-libev-release.aar')
}
}
if (set.name.matches("(mini|full).*")) {
if (set.name.contains("Apple")) {
set.dependencies {
implementation 'com.vanniktech:emoji-ios:0.7.0-SNAPSHOT'
}
} else if (set.name.contains("Noto")) {
set.dependencies {
implementation 'com.vanniktech:emoji-google:0.7.0-SNAPSHOT'
}
} else if (set.name.contains("Twitter")) {
set.dependencies {
implementation 'com.vanniktech:emoji-twitter:0.7.0-SNAPSHOT'
}
} else if (set.name.contains("Facebook")) {
set.dependencies {
implementation 'com.vanniktech:emoji-facebook:0.7.0-SNAPSHOT'
}
2020-07-08 04:00:22 +00:00
} else if (!set.name.contains("NoEmoji")) {
2020-07-08 03:28:13 +00:00
set.assets.srcDirs = ["src/main/assets", "src/emojis/blob"]
}
2020-06-24 16:15:30 +00:00
}
}
tasks.all { task ->
if (((task.name.endsWith('Ndk') || task.name.startsWith('generateJsonModel') || task.name.startsWith('externalNativeBuild'))) && !task.name.contains("Foss")) {
task.enabled = false
}
if (task.name.contains("uploadCrashlyticsMappingFile")) {
enabled = false
}
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
2020-07-08 03:28:13 +00:00
outputFileName = outputFileName.replace("TMessagesProj", "NekoX")
2017-12-08 17:35:59 +00:00
}
2020-03-30 12:00:09 +00:00
def assembleTgVoipDexTaskName = "assemble${variant.name.capitalize()}TgVoipDex"
task "${assembleTgVoipDexTaskName}" {
doLast {
def sourceDir = (File) android.sourceSets.main.java.srcDirs[0]
def classesDir = "${buildDir}/intermediates/javac/${variant.name}/classes"
def javaDir = "${buildDir}/intermediates/java_tgvoip/${variant.name}/java"
def tgVoipDir = new File(classesDir, tgVoipDexClassesPath)
def javaVoipDirFile = new File(javaDir, tgVoipDexClassesPath)
def tgVoipDexJavaFile = new File(javaVoipDirFile, "TgVoipDex.java")
if (!javaVoipDirFile.exists()) {
javaVoipDirFile.mkdirs()
}
def assetsDirFile = new File(buildDir, "intermediates/merged_assets/${variant.name}/out")
if (!assetsDirFile.exists()) {
assetsDirFile.mkdirs()
}
def tgVoipDexFile = new File(assetsDirFile, tgVoipDexFileName)
def classes = tgVoipDir.list(new FilenameFilter() {
@Override
boolean accept(File dir, String name) {
// handle inner and anonymous classes
return tgVoipDexClasses.any { name == "${it}.class" || name.startsWith("${it}\$") && name.endsWith(".class") }
}
}).collect { "${tgVoipDexClassesPath}/${it}" }
// 1. create libtgvoip.dex
exec {
workingDir classesDir
commandLine([dxUtilPath, "--dex", "--output=${tgVoipDexFile}"] + classes)
}
// 2. remove classes from the main dex
project.delete classes.collect { "${classesDir}/${it}" }
// 3. insert checksum of libtgvoip.dex into TgVoipDex.java
def digest = MessageDigest.getInstance("SHA1")
def fileInputStream = tgVoipDexFile.newInputStream()
def buffer = new byte[4096]
def len
while ((len = fileInputStream.read(buffer)) > 0) {
digest.update(buffer, 0, len)
}
def dexChecksum = new String(Base64.getEncoder().encode(digest.digest())).trim()
tgVoipDexJavaFile.write(new String(new File(sourceDir, "${tgVoipDexClassesPath}/TgVoipDex.java").readBytes()).replace("\$CHECKSUM\$", dexChecksum))
exec {
commandLine([findJavac(), "-d", classesDir, tgVoipDexJavaFile.absolutePath])
}
}
}
tasks.findByName("compile${variant.name.capitalize()}JavaWithJavac").finalizedBy(assembleTgVoipDexTaskName)
tasks.findByName("${assembleTgVoipDexTaskName}").mustRunAfter tasks.findByName("merge${variant.name.capitalize()}Assets")
2016-03-16 12:26:32 +00:00
}
2013-10-25 15:19:00 +00:00
}
2016-04-22 13:49:00 +00:00
2020-03-30 12:00:09 +00:00
private static File findJavaHome() {
String javaPath = System.getProperty("java.home")
if (javaPath != null) {
File javaBase = new File(javaPath)
if (javaBase.exists()) {
2020-06-24 16:15:30 +00:00
if (javaBase.getName().equalsIgnoreCase("jre") && new File(javaBase.getParentFile(), System.getProperty("os.name").toLowerCase().contains("windows") ? "bin/java.exe" : "bin/java").exists()) {
2020-03-30 12:00:09 +00:00
return javaBase.getParentFile()
} else {
return javaBase
}
} else {
return null
}
} else {
return null
}
}
private static File findJavac() {
File javaHome = findJavaHome()
if (javaHome != null) {
2020-06-24 16:15:30 +00:00
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
return new File(javaHome.getParent(), "bin/javac.exe")
} else {
return new File(javaHome, "bin/javac")
}
2020-03-30 12:00:09 +00:00
} else {
return null
}
}
2020-06-24 16:15:30 +00:00
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
tasks.all { task ->
if (task.name.startsWith('uploadCrashlyticsMappingFile')) {
task.enabled = false
} else if (((task.name.contains('Crashlytics'))) && !task.name.endsWith("Release")) {
task.enabled = false
} else if (((task.name.endsWith('GoogleServices'))) && !task.name.endsWith("ReleaseGoogleServices")) {
task.enabled = false
}
}
}