Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Static Badge Static Badge Static Badge Static Badge Static Badge

Apk2kotlin

A native C tool that decompiles Android APK files and reconstructs clean, compilable Android Studio Gradle projects with target source code in either Kotlin (.kt) or Java (.java).


Features

  • Native C Implementation: Written in C for fast execution and lightweight overhead.
  • Dual Target Language Support: Decompile and transpile APKs into Kotlin (.kt) or Java (.java) source trees.
  • Automatic Package Extraction: Parses package names and components directly from the decompiled AndroidManifest.xml.
  • Complete Gradle Project Structure: Generates settings.gradle.kts, build.gradle.kts, gradle.properties, app/build.gradle.kts, and app/src/main/AndroidManifest.xml.
  • Resource Sanitization & Preservation: Extracts layouts, drawables, values, and XML resources while sanitizing invalid file names.
  • Modular Design: Separated into single-function C modules with header declarations and a unified Makefile.
  • Multiplatform: Support for android (arm64 & x86_64), windows (arm64 & x86_64) and GNU linux (arm64 & x86_64).
  • One script: Just download the script for your os and execute it and it will do everything.

Architecture & Module Overview

The codebase is organized under src/ into distinct modules:

Module File Header Description
src/apk_to_smali.c src/apk_to_smali.h Extracts resources, Smali code, and AndroidManifest.xml via apktool
src/dex_to_smali.c src/dex_to_smali.h Disassembles raw .dex bytecode files to .smali
src/smali_to_kotlin.c src/smali_to_kotlin.h Decompiles bytecode and handles Kotlin (.kt) or Java (.java) transpilation
src/manifest_parser.c src/manifest_parser.h Extracts package="..." attribute from decompiled XML manifests
src/gradle_generator.c src/gradle_generator.h Creates Kotlin DSL Gradle build scripts and properties
src/file_utils.c src/file_utils.h Manages file I/O, directory creation, recursive copying, and resource sanitization
src/main.c N/A Main CLI entrypoint parsing arguments and driving execution

Prerequisites

Ensure the following dependencies are installed and available in system environment or binary paths:

  • GCC (gcc) and Make (make)
  • JDK 17 or higher (java)
  • apktool (in system PATH)
  • jadx (in system PATH)

Building from Source

To compile the native C binary in your arch using the provided Makefile:

make clean && make <win-x86_64|win-arm64|linux-x86_64|linux-arm64|android-x86_64|android-arm64>

Or to build all:

make clean && make all

The compiled binaries will be placed at bin/apk2kotlin.


Command-Line Usage

bin/apk2kotlin <input_apk> <output_project_dir> [kotlin|java]

Parameters

  1. <input_apk>: Path to the target .apk file.
  2. <output_project_dir>: Path where the generated Android Studio Gradle project will be created.
  3. [kotlin|java] (Optional): Target programming language for source output.
    • kotlin (default): Places .kt source files in app/src/main/kotlin/.
    • java: Places .java source files in app/src/main/java/.

Credits <3

  • Jadx for the dex decompile tool
  • Apktool for apk to smali
  • Bard for debugging

About

Get the kotlin/java source code from any android apk ready for compilation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages