mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2024-12-03 17:30:09 +01:00
449 lines
15 KiB
Groovy
449 lines
15 KiB
Groovy
import java.security.MessageDigest
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
apply plugin: 'com.android.application'
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
google()
|
|
jcenter()
|
|
}
|
|
|
|
configurations {
|
|
compile.exclude module: 'support-v4'
|
|
}
|
|
|
|
configurations.all {
|
|
exclude group: 'com.google.firebase', module: 'firebase-core'
|
|
}
|
|
|
|
dependencies {
|
|
implementation 'androidx.core:core:1.1.0-beta01'
|
|
implementation 'androidx.palette:palette:1.0.0'
|
|
implementation 'androidx.exifinterface:exifinterface:1.1.0'
|
|
|
|
compileOnly 'org.checkerframework:checker-qual:2.5.2'
|
|
compileOnly 'org.checkerframework:checker-compat-qual:2.5.0'
|
|
implementation 'com.google.firebase:firebase-messaging:20.1.3'
|
|
implementation 'com.google.android.gms:play-services-maps:17.0.0'
|
|
implementation 'com.google.android.gms:play-services-auth:17.0.0'
|
|
implementation 'com.google.android.gms:play-services-vision:16.2.0'
|
|
implementation 'com.google.android.gms:play-services-wearable:17.0.0'
|
|
implementation 'com.google.android.gms:play-services-location:17.0.0'
|
|
implementation 'com.googlecode.mp4parser:isoparser:1.0.6'
|
|
implementation 'com.stripe:stripe-android:2.0.2'
|
|
implementation 'com.google.code.gson:gson:2.8.6'
|
|
implementation files('libs/libgsaverification-client.aar')
|
|
implementation "com.microsoft.appcenter:appcenter-analytics:3.1.0"
|
|
}
|
|
|
|
android {
|
|
compileSdkVersion 29
|
|
buildToolsVersion '29.0.3'
|
|
ndkVersion "21.0.6113669"
|
|
|
|
defaultConfig.applicationId = "tw.nekomimi.nekogram"
|
|
|
|
sourceSets.main.jniLibs.srcDirs = ['./jni/']
|
|
|
|
externalNativeBuild {
|
|
ndkBuild {
|
|
path "jni/Android.mk"
|
|
}
|
|
}
|
|
|
|
lintOptions {
|
|
disable 'MissingTranslation'
|
|
disable 'ExtraTranslation'
|
|
disable 'BlockedPrivateApi'
|
|
}
|
|
|
|
dexOptions {
|
|
jumboMode = true
|
|
}
|
|
|
|
compileOptions {
|
|
sourceCompatibility JavaVersion.VERSION_1_8
|
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
}
|
|
|
|
signingConfigs {
|
|
def keystorePwd = null
|
|
def alias = null
|
|
def pwd = null
|
|
if (project.rootProject.file('local.properties').exists()) {
|
|
Properties properties = new Properties()
|
|
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
|
keystorePwd = properties.getProperty("RELEASE_STORE_PASSWORD")
|
|
alias = properties.getProperty("RELEASE_KEY_ALIAS")
|
|
pwd = properties.getProperty("RELEASE_KEY_PASSWORD")
|
|
}
|
|
release {
|
|
storeFile file("config/release.keystore")
|
|
storePassword keystorePwd != null ? keystorePwd : System.getenv("KEYSTORE_PASS")
|
|
keyAlias alias != null ? alias : System.getenv("ALIAS_NAME")
|
|
keyPassword pwd != null ? pwd : System.getenv("ALIAS_PASS")
|
|
}
|
|
debug {
|
|
storeFile file("config/release.keystore")
|
|
storePassword keystorePwd != null ? keystorePwd : System.getenv("KEYSTORE_PASS")
|
|
keyAlias alias != null ? alias : System.getenv("ALIAS_NAME")
|
|
keyPassword pwd != null ? pwd : System.getenv("ALIAS_PASS")
|
|
}
|
|
}
|
|
|
|
|
|
buildTypes {
|
|
debug {
|
|
debuggable true
|
|
jniDebuggable true
|
|
signingConfig signingConfigs.debug
|
|
applicationIdSuffix ".beta"
|
|
minifyEnabled true
|
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
}
|
|
|
|
/*debugAsan {
|
|
debuggable true
|
|
jniDebuggable true
|
|
signingConfig signingConfigs.debug
|
|
applicationIdSuffix ".beta"
|
|
minifyEnabled true
|
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
|
|
packagingOptions {
|
|
doNotStrip "**.so"
|
|
}
|
|
|
|
sourceSets {
|
|
main {
|
|
jniLibs {
|
|
srcDir {
|
|
'jniLibs'
|
|
}
|
|
}
|
|
resources {
|
|
srcDir {
|
|
'jniRes'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}*/
|
|
|
|
debugMultidex {
|
|
initWith debug
|
|
minifyEnabled false
|
|
multiDexEnabled true
|
|
dependencies {
|
|
implementation 'com.android.support:multidex:1.0.3'
|
|
}
|
|
manifestPlaceholders = [applicationClassName: "MultiDexApplicationLoader"]
|
|
}
|
|
|
|
HA {
|
|
debuggable false
|
|
jniDebuggable false
|
|
signingConfig signingConfigs.debug
|
|
applicationIdSuffix ".beta"
|
|
minifyEnabled true
|
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
}
|
|
|
|
release {
|
|
debuggable false
|
|
jniDebuggable false
|
|
signingConfig signingConfigs.release
|
|
minifyEnabled true
|
|
shrinkResources false
|
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
multiDexEnabled true
|
|
dependencies {
|
|
implementation 'com.android.support:multidex:1.0.3'
|
|
}
|
|
manifestPlaceholders = [applicationClassName: "MultiDexApplicationLoader"]
|
|
}
|
|
}
|
|
|
|
sourceSets.debug {
|
|
manifest.srcFile 'config/debug/AndroidManifest.xml'
|
|
}
|
|
|
|
/*sourceSets.debugAsan {
|
|
manifest.srcFile 'config/debug/AndroidManifest.xml'
|
|
}*/
|
|
|
|
sourceSets.debugMultidex {
|
|
manifest.srcFile 'config/debug/AndroidManifest.xml'
|
|
java.srcDirs = ['src/multidex/java']
|
|
}
|
|
|
|
sourceSets.HA {
|
|
manifest.srcFile 'config/debug/AndroidManifest.xml'
|
|
}
|
|
|
|
sourceSets.release {
|
|
manifest.srcFile 'config/release/AndroidManifest.xml'
|
|
java.srcDirs = ['src/multidex/java']
|
|
}
|
|
|
|
flavorDimensions "minApi"
|
|
|
|
productFlavors {
|
|
armv7 {
|
|
ndk {
|
|
abiFilters "armeabi-v7a"
|
|
}
|
|
ext {
|
|
abiVersionCode = 1
|
|
}
|
|
}
|
|
x86 {
|
|
ndk {
|
|
abiFilters "x86"
|
|
}
|
|
ext {
|
|
abiVersionCode = 2
|
|
}
|
|
}
|
|
armv7_SDK23 {
|
|
ndk {
|
|
abiFilters "armeabi-v7a"
|
|
}
|
|
sourceSets.debug {
|
|
manifest.srcFile 'config/debug/AndroidManifest_SDK23.xml'
|
|
}
|
|
sourceSets.release {
|
|
manifest.srcFile 'config/release/AndroidManifest_SDK23.xml'
|
|
}
|
|
minSdkVersion 23
|
|
ext {
|
|
abiVersionCode = 3
|
|
}
|
|
}
|
|
x86_SDK23 {
|
|
ndk {
|
|
abiFilters "x86"
|
|
}
|
|
sourceSets.debug {
|
|
manifest.srcFile 'config/debug/AndroidManifest_SDK23.xml'
|
|
}
|
|
sourceSets.release {
|
|
manifest.srcFile 'config/release/AndroidManifest_SDK23.xml'
|
|
}
|
|
minSdkVersion 23
|
|
ext {
|
|
abiVersionCode = 4
|
|
}
|
|
}
|
|
arm64 {
|
|
ndk {
|
|
abiFilters "arm64-v8a"
|
|
}
|
|
ext {
|
|
abiVersionCode = 5
|
|
}
|
|
}
|
|
x64 {
|
|
ndk {
|
|
abiFilters "x86_64"
|
|
}
|
|
ext {
|
|
abiVersionCode = 6
|
|
}
|
|
}
|
|
arm64_SDK23 {
|
|
ndk {
|
|
abiFilters "arm64-v8a"
|
|
}
|
|
sourceSets.debug {
|
|
manifest.srcFile 'config/debug/AndroidManifest_SDK23.xml'
|
|
}
|
|
/*sourceSets.debugAsan {
|
|
manifest.srcFile 'config/debug/AndroidManifest_SDK23.xml'
|
|
}*/
|
|
sourceSets.release {
|
|
manifest.srcFile 'config/release/AndroidManifest_SDK23.xml'
|
|
}
|
|
minSdkVersion 23
|
|
ext {
|
|
abiVersionCode = 7
|
|
}
|
|
}
|
|
x64_SDK23 {
|
|
ndk {
|
|
abiFilters "x86_64"
|
|
}
|
|
sourceSets.debug {
|
|
manifest.srcFile 'config/debug/AndroidManifest_SDK23.xml'
|
|
}
|
|
sourceSets.release {
|
|
manifest.srcFile 'config/release/AndroidManifest_SDK23.xml'
|
|
}
|
|
minSdkVersion 23
|
|
ext {
|
|
abiVersionCode = 8
|
|
}
|
|
}
|
|
afat {
|
|
sourceSets.debug {
|
|
manifest.srcFile 'config/debug/AndroidManifest_SDK23.xml'
|
|
}
|
|
/*sourceSets.debugAsan {
|
|
manifest.srcFile 'config/debug/AndroidManifest_SDK23.xml'
|
|
}*/
|
|
sourceSets.release {
|
|
manifest.srcFile 'config/release/AndroidManifest_SDK23.xml'
|
|
}
|
|
ext {
|
|
abiVersionCode = 9
|
|
}
|
|
}
|
|
}
|
|
|
|
defaultConfig.versionCode = 10 * 1913
|
|
|
|
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 (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
dxUtilPath = "${sdkDirectory.path}\\build-tools\\${buildToolsVersion}\\dx.bat"
|
|
}
|
|
|
|
applicationVariants.all { variant ->
|
|
variant.outputs.all { output ->
|
|
outputFileName = "Nekogram-${defaultConfig.versionName}-${defaultConfig.versionCode / 10}-${variant.productFlavors.get(0).name}-${buildType.name}.apk"
|
|
output.getProcessManifestProvider().get().doLast {
|
|
def abiVersion = variant.productFlavors.get(0).abiVersionCode
|
|
|
|
def outputDir = manifestOutputDirectory
|
|
File directory
|
|
if (outputDir instanceof File) {
|
|
directory = outputDir
|
|
} else {
|
|
directory = outputDir.get().asFile
|
|
}
|
|
|
|
String manifestPath = directory.toString() + "/AndroidManifest.xml"
|
|
def manifestContent = file(manifestPath).getText()
|
|
|
|
manifestContent = manifestContent.replace(String.format('android:versionCode="%d"', defaultConfig.versionCode), String.format('android:versionCode="%s"', defaultConfig.versionCode + abiVersion))
|
|
file(manifestPath).write(manifestContent)
|
|
}
|
|
}
|
|
|
|
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")
|
|
}
|
|
|
|
variantFilter { variant ->
|
|
def names = variant.flavors*.name
|
|
if (variant.buildType.name != "release" && !names.contains("afat")) {
|
|
setIgnore(true)
|
|
}
|
|
}
|
|
|
|
defaultConfig {
|
|
minSdkVersion 16
|
|
targetSdkVersion 28
|
|
versionName "6.0.1.1"
|
|
|
|
vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi']
|
|
|
|
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: "ApplicationLoader"]
|
|
}
|
|
}
|
|
|
|
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) {
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
return new File(javaHome.getParent(), "bin/javac.exe")
|
|
} else {
|
|
return new File(javaHome, "bin/javac")
|
|
}
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
|
|
apply plugin: 'com.google.gms.google-services'
|