mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2026-01-11 05:46:16 +00:00
Negligible lookup maps used for matching fingerprints have been removed to reduce the likelihood of OOM when the maps are instantiated, commonly observed with 400M RAM. Additionally, lookup maps previously kept for the duration of the patcher instance are now cleared before the classes are compiled. This reduces the likelihood of OOM when compiling classes. On a related note, a linear increase in memory usage is observed with every compiled class until all classes are compiled implying compiled classes not being freed by GC because they are still referenced. After compiling a class, the class is technically free-able though. The classes are assumed to be referenced in the `multidexlib2` library that takes the list of all classes to compile multiple DEX with and seems to hold the reference to all these classes in memory until all DEX are compiled. A clever fix would involve splitting the list of classes into chunks and getting rid of the list of all classes so that after every DEX compilation, the corresponding split of classes can be freed.
74 lines
2.4 KiB
Kotlin
74 lines
2.4 KiB
Kotlin
package app.revanced.patcher
|
|
|
|
import app.revanced.patcher.patch.ResourcePatchContext
|
|
import brut.androlib.Config
|
|
import java.io.File
|
|
import java.util.logging.Logger
|
|
|
|
/**
|
|
* The configuration for the patcher.
|
|
*
|
|
* @param apkFile The apk file to patch.
|
|
* @param temporaryFilesPath A path to a folder to store temporary files in.
|
|
* @param aaptBinaryPath A path to a custom aapt binary.
|
|
* @param frameworkFileDirectory A path to the directory to cache the framework file in.
|
|
* @param multithreadingDexFileWriter Whether to use multiple threads for writing dex files.
|
|
* This has impact on memory usage and performance.
|
|
*/
|
|
class PatcherConfig(
|
|
internal val apkFile: File,
|
|
private val temporaryFilesPath: File = File("revanced-temporary-files"),
|
|
aaptBinaryPath: String? = null,
|
|
frameworkFileDirectory: String? = null,
|
|
@Deprecated("This is going to be removed in the future because it is not needed anymore.")
|
|
internal val multithreadingDexFileWriter: Boolean = false,
|
|
) {
|
|
private val logger = Logger.getLogger(PatcherConfig::class.java.name)
|
|
|
|
/**
|
|
* The mode to use for resource decoding and compiling.
|
|
*
|
|
* @see ResourcePatchContext.ResourceMode
|
|
*/
|
|
internal var resourceMode = ResourcePatchContext.ResourceMode.NONE
|
|
|
|
/**
|
|
* The configuration for decoding and compiling resources.
|
|
*/
|
|
internal val resourceConfig =
|
|
Config.getDefaultConfig().apply {
|
|
useAapt2 = true
|
|
aaptPath = aaptBinaryPath ?: ""
|
|
frameworkDirectory = frameworkFileDirectory
|
|
}
|
|
|
|
/**
|
|
* The path to the temporary apk files directory.
|
|
*/
|
|
internal val apkFiles = temporaryFilesPath.resolve("apk")
|
|
|
|
/**
|
|
* The path to the temporary patched files directory.
|
|
*/
|
|
internal val patchedFiles = temporaryFilesPath.resolve("patched")
|
|
|
|
/**
|
|
* Initialize the temporary files' directories.
|
|
* This will delete the existing temporary files directory if it exists.
|
|
*/
|
|
internal fun initializeTemporaryFilesDirectories() {
|
|
temporaryFilesPath.apply {
|
|
if (exists()) {
|
|
logger.info("Deleting existing temporary files directory")
|
|
|
|
if (!deleteRecursively()) {
|
|
logger.severe("Failed to delete existing temporary files directory")
|
|
}
|
|
}
|
|
}
|
|
|
|
apkFiles.mkdirs()
|
|
patchedFiles.mkdirs()
|
|
}
|
|
}
|