Optimize build scripts
- rewrite the"exportDex" task group - move the logic of deleting temporary files into a gradle script - fix "APPCENTER_KEY" property defining while debug building
This commit is contained in:
+40
-64
@@ -1,8 +1,6 @@
|
|||||||
import org.apache.tools.ant.taskdefs.condition.Os
|
import org.apache.tools.ant.taskdefs.condition.Os
|
||||||
|
|
||||||
import java.util.zip.ZipEntry
|
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
import java.util.zip.ZipInputStream
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.android.application'
|
id 'com.android.application'
|
||||||
@@ -21,6 +19,10 @@ cargo {
|
|||||||
|
|
||||||
def smaliFolder = projectDir.toPath().resolve("../smali").normalize()
|
def smaliFolder = projectDir.toPath().resolve("../smali").normalize()
|
||||||
def scriptsFolder = projectDir.toPath().resolve("../scripts").normalize()
|
def scriptsFolder = projectDir.toPath().resolve("../scripts").normalize()
|
||||||
|
//you can add own folders with decompiled smali code
|
||||||
|
def dexes=smaliFolder.toFile()
|
||||||
|
.listFiles( { f -> f.isDirectory() && f.name.startsWith("smali") } as FileFilter)
|
||||||
|
.size()
|
||||||
|
|
||||||
versionFile {
|
versionFile {
|
||||||
file = projectDir.toPath().resolve("src/main/assets/version.properties").toFile()
|
file = projectDir.toPath().resolve("src/main/assets/version.properties").toFile()
|
||||||
@@ -63,6 +65,10 @@ android {
|
|||||||
minifyEnabled true
|
minifyEnabled true
|
||||||
proguardFile 'proguard-rules.pro'
|
proguardFile 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
|
debug {
|
||||||
|
buildConfigField 'String', 'APPCENTER_KEY', '""'
|
||||||
|
minifyEnabled false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
@@ -82,70 +88,41 @@ dependencies {
|
|||||||
implementation 'com.microsoft.appcenter:appcenter-crashes:5.0.1'
|
implementation 'com.microsoft.appcenter:appcenter-crashes:5.0.1'
|
||||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
|
||||||
implementation 'net.sourceforge.streamsupport:streamsupport-minifuture:1.7.4'
|
implementation 'net.sourceforge.streamsupport:streamsupport-minifuture:1.7.4'
|
||||||
|
implementation 'com.google.guava:guava:23.3-android'
|
||||||
|
|
||||||
implementation fileTree(dir: 'libs', include: ['*.aar'])
|
implementation fileTree(dir: 'libs', include: ['*.aar'])
|
||||||
compileOnly fileTree(dir: 'libs', include: ['*.jar'])
|
compileOnly fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation 'com.google.guava:guava:23.3-android'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task generateBuildTasks() {
|
task generateBuildTasks() {
|
||||||
android.applicationVariants.all { variant ->
|
android.applicationVariants.all { variant ->
|
||||||
variant.outputs.each { output ->
|
variant.outputs.each { output ->
|
||||||
def buildType = output.name.toString().capitalize()
|
def buildType = output.name.toString().capitalize()
|
||||||
def lowerBuildType = buildType.toLowerCase()
|
|
||||||
task "exportDex$buildType"() {
|
task "exportDex$buildType"() {
|
||||||
dependsOn('assemble' + buildType)
|
dependsOn('assemble' + buildType)
|
||||||
doLast {
|
doLast {
|
||||||
try {
|
try {
|
||||||
var z = ""
|
def suffix=buildType.toLowerCase()
|
||||||
if (lowerBuildType != "debug") {
|
def zip=new ZipFile(new File(projectDir,"/build/outputs/apk/$suffix/app-$suffix${suffix!="debug"?"-unsigned.apk":".apk"}"))
|
||||||
z = "-unsigned"
|
def entries=zip.entries()
|
||||||
}
|
def dexCounter=dexes
|
||||||
|
while(entries.hasMoreElements())
|
||||||
File moduleDir = projectDir
|
{
|
||||||
ZipInputStream inputStream = new ZipInputStream(new FileInputStream(moduleDir.getAbsolutePath() + "/build/outputs/apk/$lowerBuildType/app-$lowerBuildType${z}.apk"))
|
def entry=entries.nextElement()
|
||||||
ZipFile file = new ZipFile(moduleDir.getAbsolutePath() + "/build/outputs/apk/$lowerBuildType/app-$lowerBuildType${z}.apk");
|
String filename
|
||||||
ZipEntry entry
|
if(entry.name.matches("^classes(?:(?=\\d)2|)\\.dex\$"))filename="classes${++dexCounter}.dex"
|
||||||
while ((entry = inputStream.nextEntry) != null) {
|
else if(entry.name=="assets/version.properties")filename="version.properties"
|
||||||
if (entry.getName().equals("classes.dex")) {
|
else continue
|
||||||
print('classes.dex found!')
|
println("Exporting "+entry.name)
|
||||||
|
def tmpFile=new File(projectDir,filename)
|
||||||
FileOutputStream outputStream = new FileOutputStream(new File(moduleDir.getAbsoluteFile(), "classes6.dex"))
|
def is=zip.getInputStream(entry)
|
||||||
|
def fos=new FileOutputStream(tmpFile)
|
||||||
byte[] buffer = new byte[1024]
|
def buff=new byte[0x800]
|
||||||
int len = 0
|
int len
|
||||||
while ((len = inputStream.read(buffer)) > 0) {
|
while((len=is.read(buff))>0)fos.write(buff,0,len)
|
||||||
outputStream.write(buffer, 0, len)
|
is.close()
|
||||||
}
|
fos.close()
|
||||||
outputStream.close()
|
|
||||||
}
|
|
||||||
if (entry.getName().equals("classes2.dex")) {
|
|
||||||
print('\nclasses2.dex found!')
|
|
||||||
|
|
||||||
FileOutputStream outputStream = new FileOutputStream(new File(moduleDir.getAbsoluteFile(), "classes7.dex"))
|
|
||||||
|
|
||||||
byte[] buffer = new byte[1024]
|
|
||||||
int len = 0
|
|
||||||
while ((len = inputStream.read(buffer)) > 0) {
|
|
||||||
outputStream.write(buffer, 0, len)
|
|
||||||
}
|
|
||||||
outputStream.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ZipEntry e : Collections.list(file.entries())) {
|
|
||||||
if (e.getName().endsWith("assets/version.properties")) {
|
|
||||||
var is = file.getInputStream(e)
|
|
||||||
FileOutputStream outputStream = new FileOutputStream(new File(moduleDir.getAbsoluteFile(), "version.properties"))
|
|
||||||
|
|
||||||
byte[] buffer = new byte[1024]
|
|
||||||
int len = 0
|
|
||||||
while ((len = is.read(buffer)) > 0) {
|
|
||||||
outputStream.write(buffer, 0, len)
|
|
||||||
}
|
|
||||||
outputStream.close()
|
|
||||||
|
|
||||||
print('\nversion.properties found!')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
@@ -155,17 +132,16 @@ task generateBuildTasks() {
|
|||||||
task "prepareDexForMerge$buildType"(type: Copy) {
|
task "prepareDexForMerge$buildType"(type: Copy) {
|
||||||
dependsOn('exportDex' + buildType)
|
dependsOn('exportDex' + buildType)
|
||||||
// Remove comment for native lib build
|
// Remove comment for native lib build
|
||||||
dependsOn('cargoBuild')
|
//dependsOn('cargoBuild')
|
||||||
into smaliFolder.toString()
|
into smaliFolder.toString()
|
||||||
from(projectDir) {
|
from(projectDir) {
|
||||||
include 'classes6.dex'
|
into '../smali'
|
||||||
include 'classes7.dex'
|
include "classes*.dex"
|
||||||
}
|
}
|
||||||
from(projectDir) {
|
from(projectDir) {
|
||||||
include 'version.properties'
|
include 'version.properties'
|
||||||
into 'assets'
|
into 'assets'
|
||||||
}
|
}
|
||||||
// Remove comment for native lib build
|
|
||||||
from('../native-effects/target/aarch64-linux-android/release'){
|
from('../native-effects/target/aarch64-linux-android/release'){
|
||||||
include 'libnative_effects.so'
|
include 'libnative_effects.so'
|
||||||
into 'lib/arm64-v8a'
|
into 'lib/arm64-v8a'
|
||||||
@@ -174,15 +150,16 @@ task generateBuildTasks() {
|
|||||||
include 'libnative_effects.so'
|
include 'libnative_effects.so'
|
||||||
into 'lib/armeabi-v7a'
|
into 'lib/armeabi-v7a'
|
||||||
}
|
}
|
||||||
doLast {
|
}
|
||||||
new File(projectDir, "classes6.dex").delete()
|
task "cleanTemporaryFiles$buildType"(type:Delete)
|
||||||
new File(projectDir, "classes7.dex").delete()
|
{
|
||||||
new File(projectDir, "version.properties").delete()
|
delete fileTree(dir:projectDir,include:["*.dex","version.properties"])
|
||||||
}
|
delete fileTree(dir:smaliFolder,include:['*.dex',"assets/version.properties"])
|
||||||
}
|
}
|
||||||
task "buildVTL$buildType"(type: Exec) {
|
task "buildVTL$buildType"(type: Exec) {
|
||||||
dependsOn('prepareDexForMerge' + buildType)
|
dependsOn('prepareDexForMerge' + buildType)
|
||||||
workingDir(projectDir.parentFile)
|
workingDir(projectDir.parentFile)
|
||||||
|
finalizedBy "cleanTemporaryFiles$buildType"
|
||||||
if (Os.isFamily("unix") || Os.isFamily("mac")) {
|
if (Os.isFamily("unix") || Os.isFamily("mac")) {
|
||||||
commandLine 'bash', '-c', './scripts/build.sh'
|
commandLine 'bash', '-c', './scripts/build.sh'
|
||||||
} else {
|
} else {
|
||||||
@@ -210,7 +187,6 @@ task generateBuildTasks() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
task generateRjava(type: Exec) {
|
task generateRjava(type: Exec) {
|
||||||
workingDir(projectDir.parentFile)
|
workingDir(projectDir.parentFile)
|
||||||
if (Os.isFamily("unix") || Os.isFamily("mac"))
|
if (Os.isFamily("unix") || Os.isFamily("mac"))
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ if "%ERRORLEVEL%" == "0" (
|
|||||||
echo %ESC%[31mFailed%ESC%[0m
|
echo %ESC%[31mFailed%ESC%[0m
|
||||||
exit /B 1
|
exit /B 1
|
||||||
)
|
)
|
||||||
del classes6.dex
|
|
||||||
del classes7.dex
|
|
||||||
del assets\version.properties
|
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo %ESC%[1;4mSign apk...%ESC%[0m
|
echo %ESC%[1;4mSign apk...%ESC%[0m
|
||||||
|
|||||||
+1
-5
@@ -33,8 +33,4 @@ cd ../scripts
|
|||||||
./apksigner sign --ks debug.keystore --ks-key-alias androiddebugkey --ks-pass pass:android ../scripts/VTLite.apk
|
./apksigner sign --ks debug.keystore --ks-key-alias androiddebugkey --ks-pass pass:android ../scripts/VTLite.apk
|
||||||
check_result
|
check_result
|
||||||
|
|
||||||
echo -e "${BOLD}VTosters Lite успешно собран! APK находится в папке scripts${NC}"
|
echo -e "${BOLD}VTosters Lite успешно собран! APK находится в папке scripts${NC}"
|
||||||
|
|
||||||
cd ../smali
|
|
||||||
rm classes6.dex
|
|
||||||
rm classes7.dex
|
|
||||||
Reference in New Issue
Block a user