revanced-patcher/docs/1_patcher_intro.md
oSumAtrIX 11a911dc67 feat: Convert APIs to Kotlin DSL (#298)
This commit converts various APIs to Kotlin DSL.

BREAKING CHANGE: Various old APIs are removed, and DSL APIs are added instead.
2024-08-06 16:53:42 +02:00

4.9 KiB


                       

Continuing the legacy of Vanced

💉 Introduction to ReVanced Patcher

To create patches for Android apps, it is recommended to know the basic concept of ReVanced Patcher.

📙 How it works

ReVanced Patcher is a library that allows modifying Android apps by applying patches. It is built on top of Smali for bytecode manipulation and Androlib (Apktool) for resource decoding and encoding.

ReVanced Patcher receives a list of patches and applies them to a given APK file. It then returns the modified components of the APK file, such as modified dex files and resources, that can be repackaged into a new APK file.

ReVanced Patcher has a simple API that allows you to load patches from RVP (JAR or DEX container) files and apply them to an APK file. Later on, you will learn how to create patches.

val patches = loadPatchesFromJar(setOf(File("revanced-patches.rvp")))

val patcherResult = Patcher(PatcherConfig(apkFile = File("some.apk"))).use { patcher ->
    // Here you can access metadata about the APK file through patcher.context.packageMetadata
    // such as package name, version code, version name, etc.

    // Add patches.
    patcher += patches

    // Execute the patches.
    runBlocking {
        patcher().collect { patchResult ->
            if (patchResult.exception != null)
                logger.info("\"${patchResult.patch}\" failed:\n${patchResult.exception}")
            else
                logger.info("\"${patchResult.patch}\" succeeded")
        }
    }

    // Compile and save the patched APK file components.
    patcher.get()
}

// The result of the patcher contains the modified components of the APK file that can be repackaged into a new APK file.
val dexFiles = patcherResult.dexFiles
val resources = patcherResult.resources

⏭️ What's next

The next page teaches the fundamentals of ReVanced Patches.

Continue: 🧩 Introduction to ReVanced Patches