mirror of https://github.com/NekoX-Dev/NekoX.git
416 lines
13 KiB
Groovy
416 lines
13 KiB
Groovy
import cn.hutool.core.io.FileUtil
|
|
import cn.hutool.json.JSONObject
|
|
import cn.hutool.system.SystemUtil
|
|
import java.security.MessageDigest
|
|
|
|
apply plugin: 'com.android.application'
|
|
apply plugin: 'kotlin-android'
|
|
apply plugin: 'kotlin-android-extensions'
|
|
|
|
configurations {
|
|
compile.exclude module: 'support-v4'
|
|
}
|
|
|
|
buildscript {
|
|
|
|
repositories {
|
|
jcenter()
|
|
mavenCentral()
|
|
google()
|
|
}
|
|
|
|
dependencies {
|
|
|
|
classpath 'cn.hutool:hutool-all:5.3.2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dependencies {
|
|
|
|
implementation 'androidx.core:core:1.3.0-rc01'
|
|
implementation 'androidx.palette:palette:1.0.0'
|
|
implementation 'androidx.viewpager:viewpager:1.0.0'
|
|
implementation 'androidx.exifinterface:exifinterface:1.2.0'
|
|
implementation "androidx.interpolator:interpolator:1.0.0"
|
|
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
|
|
compileOnly 'com.android.support:multidex:1.0.3'
|
|
|
|
compileOnly 'org.checkerframework:checker-qual:3.4.0'
|
|
compileOnly 'org.checkerframework:checker-compat-qual:2.5.5'
|
|
implementation 'com.googlecode.mp4parser:isoparser:1.1.22'
|
|
implementation 'com.google.code.gson:gson:2.8.6'
|
|
implementation 'org.osmdroid:osmdroid-android:6.1.6'
|
|
implementation 'com.google.zxing:core:3.4.0'
|
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72"
|
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5"
|
|
|
|
def okHttpVersion = '4.6.0'
|
|
|
|
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
|
|
implementation "com.squareup.okhttp3:okhttp-dnsoverhttps:$okHttpVersion"
|
|
implementation 'dnsjava:dnsjava:3.0.2'
|
|
implementation 'org.dizitart:nitrite:3.4.1'
|
|
implementation 'net.lingala.zip4j:zip4j:2.5.2'
|
|
|
|
implementation 'cn.hutool:hutool-all:5.3.2'
|
|
implementation 'org.tukaani:xz:1.8'
|
|
|
|
implementation files('libs/libv2ray.aar')
|
|
implementation files('libs/ss-libev-release.aar')
|
|
implementation files('libs/ssr-libev-release.aar')
|
|
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
|
|
|
|
def fcmVersion = '20.1.6'
|
|
def crashlyticsVersion = '17.0.0'
|
|
def playCoreVersion = '1.7.2'
|
|
|
|
compileOnly "com.google.firebase:firebase-messaging:$fcmVersion"
|
|
compileOnly "com.google.firebase:firebase-crashlytics:$crashlyticsVersion"
|
|
compileOnly "com.google.android.play:core:$playCoreVersion"
|
|
|
|
releaseImplementation "com.google.firebase:firebase-messaging:$fcmVersion"
|
|
releaseImplementation "com.google.firebase:firebase-crashlytics:$crashlyticsVersion"
|
|
releaseImplementation "com.google.android.play:core:$playCoreVersion"
|
|
|
|
}
|
|
|
|
def verName = "6.1.1.0"
|
|
def verCode = 32
|
|
|
|
task writeUpdateInfo {
|
|
|
|
def info = new JSONObject()
|
|
|
|
info.set("version", verName)
|
|
info.set("versionCode", verCode)
|
|
info.set("defaultApkName","NekoX-afat-armeabi-v7a-release.apk.xz")
|
|
|
|
FileUtil.writeUtf8String(info.toStringPretty(), new File("build/update.json"))
|
|
|
|
}
|
|
|
|
tasks.findByName("preBuild").finalizedBy(writeUpdateInfo)
|
|
|
|
android {
|
|
compileSdkVersion 29
|
|
buildToolsVersion '29.0.3'
|
|
ndkVersion "21.0.6113669"
|
|
|
|
defaultConfig.applicationId = "nekox.messenger"
|
|
|
|
defaultConfig {
|
|
minSdkVersion 16
|
|
targetSdkVersion 28
|
|
|
|
versionName verName
|
|
versionCode verCode
|
|
|
|
vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi']
|
|
|
|
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"
|
|
}
|
|
}
|
|
|
|
manifestPlaceholders = [applicationClassName: "MultiDexApplicationLoader"]
|
|
|
|
}
|
|
|
|
externalNativeBuild {
|
|
ndkBuild {
|
|
path "jni/Android.mk"
|
|
}
|
|
}
|
|
|
|
lintOptions {
|
|
disable 'MissingTranslation'
|
|
disable 'ExtraTranslation'
|
|
disable 'BlockedPrivateApi'
|
|
}
|
|
|
|
packagingOptions {
|
|
|
|
exclude '/fabric/**'
|
|
exclude '/kotlin/**'
|
|
exclude '/META-INF/*.version'
|
|
exclude '/META-INF/*.kotlin_module'
|
|
exclude '/builddef.lst'
|
|
exclude '/*.txt'
|
|
|
|
}
|
|
|
|
dexOptions {
|
|
jumboMode = true
|
|
}
|
|
|
|
compileOptions {
|
|
sourceCompatibility JavaVersion.VERSION_1_8
|
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
}
|
|
|
|
kotlinOptions {
|
|
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
|
}
|
|
|
|
signingConfigs {
|
|
def keystorePwd = null
|
|
def alias = null
|
|
def pwd = null
|
|
Properties properties
|
|
|
|
if (project.rootProject.file('local.properties').exists()) {
|
|
properties = new Properties()
|
|
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
|
} else {
|
|
def base64 = System.getenv("LOCAL_PROPERTIES")
|
|
if (base64 != null && !base64.isBlank()) {
|
|
properties = new Properties()
|
|
properties.load(new ByteArrayInputStream(Base64.decoder.decode(base64)))
|
|
}
|
|
}
|
|
|
|
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")
|
|
|
|
release {
|
|
|
|
storeFile project.file('release.keystore')
|
|
storePassword keystorePwd
|
|
keyAlias alias
|
|
keyPassword pwd
|
|
}
|
|
|
|
debug {
|
|
|
|
storeFile project.file('debug.keystore')
|
|
storePassword "android"
|
|
keyAlias "androiddebugkey"
|
|
keyPassword "android"
|
|
|
|
}
|
|
}
|
|
|
|
buildTypes {
|
|
debug {
|
|
debuggable true
|
|
jniDebuggable true
|
|
signingConfig signingConfigs.debug
|
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
}
|
|
|
|
releaseNoGcm {
|
|
initWith debug
|
|
debuggable false
|
|
jniDebuggable false
|
|
minifyEnabled true
|
|
shrinkResources true
|
|
signingConfig signingConfigs.release
|
|
}
|
|
|
|
release {
|
|
initWith releaseNoGcm
|
|
}
|
|
|
|
foss {
|
|
initWith release
|
|
}
|
|
}
|
|
|
|
sourceSets.main {
|
|
jni.srcDirs = []
|
|
}
|
|
|
|
sourceSets.debug {
|
|
jniLibs.srcDir 'src/main/libs'
|
|
}
|
|
|
|
sourceSets.releaseNoGcm {
|
|
jniLibs.srcDir 'src/main/libs'
|
|
}
|
|
|
|
sourceSets.release {
|
|
jniLibs.srcDir 'src/main/libs'
|
|
manifest.srcFile 'src/gservcies/AndroidManifest.xml'
|
|
}
|
|
|
|
sourceSets.foss {
|
|
jni.srcDirs = ['./jni/']
|
|
}
|
|
|
|
flavorDimensions "version"
|
|
|
|
splits {
|
|
|
|
abi {
|
|
|
|
enable true
|
|
|
|
reset()
|
|
include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
|
|
|
universalApk true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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"
|
|
|
|
if (SystemUtil.getOsInfo().isWindows()) {
|
|
dxUtilPath += ".bat"
|
|
}
|
|
|
|
flavorDimensions "minApi"
|
|
|
|
productFlavors {
|
|
afat {
|
|
dependencies {
|
|
implementation 'com.android.support:multidex:1.0.3'
|
|
}
|
|
multiDexEnabled true
|
|
}
|
|
|
|
minApi21 {
|
|
minSdkVersion 21
|
|
multiDexEnabled false
|
|
versionNameSuffix '-minApi21'
|
|
}
|
|
}
|
|
|
|
tasks.all { task ->
|
|
if (((task.name.endsWith('Ndk') || task.name.startsWith('generateJsonModel') || task.name.startsWith('externalNativeBuild'))) && !task.name.contains("Foss")) {
|
|
task.enabled = false
|
|
}
|
|
}
|
|
|
|
applicationVariants.all { variant ->
|
|
|
|
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")
|
|
}
|
|
|
|
}
|
|
|
|
private static File findJavaHome() {
|
|
String javaPath = System.getProperty("java.home")
|
|
if (javaPath != null) {
|
|
File javaBase = new File(javaPath)
|
|
if (javaBase.exists()) {
|
|
if (javaBase.getName().equalsIgnoreCase("jre") && new File(javaBase.getParentFile(), "bin/java").exists()) {
|
|
return javaBase.getParentFile()
|
|
} else {
|
|
return javaBase
|
|
}
|
|
} else {
|
|
return null
|
|
}
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
|
|
private static File findJavac() {
|
|
File javaHome = findJavaHome()
|
|
if (javaHome != null) {
|
|
return new File(javaHome, "bin/javac")
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
|
|
apply plugin: 'com.google.gms.google-services'
|
|
apply plugin: 'com.google.firebase.crashlytics'
|
|
|
|
android {
|
|
|
|
tasks.all { task ->
|
|
if (((task.name.contains('Crashlytics'))) && !task.name.endsWith("Release")) {
|
|
task.enabled = false
|
|
}
|
|
if (((task.name.endsWith('GoogleServices'))) && !task.name.endsWith("ReleaseGoogleServices")) {
|
|
task.enabled = false
|
|
}
|
|
}
|
|
|
|
} |