### Example Environment Setup Script Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/04-configuration.md A bash script snippet for setting up essential environment variables in `~/.bashrc` or `~/.zshrc`. Includes Java, Android, Gradle, and Morphe specific variables. ```bash # ~/.bashrc or ~/.zshrc # Java export JAVA_HOME=/usr/lib/jvm/java-21-zulu export PATH=$JAVA_HOME/bin:$PATH # Android export ANDROID_HOME=$HOME/Android/Sdk export PATH=$ANDROID_HOME/platform-tools:$PATH export PATH=$ANDROID_HOME/tools:$PATH # Gradle export GRADLE_OPTS="-Xmx2g" export GRADLE_USER_HOME=~/.gradle # Morphe export MORPHE_DEBUG=false ``` -------------------------------- ### Install APK Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Install an APK file onto the connected device. ```bash adb install patched.apk ``` -------------------------------- ### Full gradle.properties Example Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/04-configuration.md A comprehensive example of `gradle.properties` including GitHub Packages authentication, JDK configuration, build performance settings, and memory allocation. ```properties # GitHub Packages gpr.user = john-doe gpr.key = ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxx # JDK org.gradle.java.home = /usr/lib/jvm/java-21-zulu # Build performance org.gradle.parallel = true org.gradle.workers.max = 4 org.gradle.daemon = true # Memory settings org.gradle.jvmargs = -Xmx2g ``` -------------------------------- ### Install Application Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Installs an Android application package (APK) onto the device. Use flags like -r to replace an existing installation, -d to allow downgrades, or -s to install on SD card. ```bash adb install app.apk ``` ```bash adb install -r app.apk ``` ```bash adb install --user app.apk ``` ```bash adb install -d app.apk ``` ```bash adb install -s app.apk ``` -------------------------------- ### Start Application Component Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Starts a specific component (like an Activity) of an Android application. Requires the package name and the component name. ```bash adb shell am start -n app.morphe.android.youtube/app.morphe.android.youtube.MainActivity ``` -------------------------------- ### Get General Help Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Display general help information for the Morphe CLI, listing available commands. ```bash # General help java -jar morphe-cli-all.jar help ``` -------------------------------- ### Install APK for Specific User Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Install an APK for a particular user profile on the device. ```bash adb install --user patched.apk ``` -------------------------------- ### Patch APK and Install via ADB Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Patch an APK, save it to a specified output file, and then install the patched APK onto a connected device using ADB. Requires ADB to be set up. ```bash java -jar morphe-cli-all.jar patch \ --patches morphe-patches-template/build/libs/patches-1.0.0.mpp \ --out morphe.apk \ --install \ input.apk ``` -------------------------------- ### Fingerprint Example with Strings, Parameters, and Return Type Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/07-patch-management.md Illustrates creating a Fingerprint to identify a target method based on literal strings, parameter types, and the return type. ```kotlin Fingerprint( strings = arrayOf("watch?v=", "youtube.com"), parameters = listOf("String", "String"), returnType = "void" ) ``` -------------------------------- ### Automatic APK Installation Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Patch an APK and automatically install the patched version onto a connected device. ```bash java -jar morphe-cli-all.jar patch \ --patches patches.mpp \ --install \ input.apk ``` -------------------------------- ### Set JAVA_HOME Environment Variable Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/05-error-codes.md Configure the JAVA_HOME environment variable to point to your JDK installation. This is crucial for Gradle and other Java-based tools. The example uses Zulu JDK 21, adjust the path as necessary. Make the changes permanent by adding them to your shell's configuration file. ```bash # Find JDK installation which java java -version # Set JAVA_HOME export JAVA_HOME=/usr/lib/jvm/java-21-zulu export PATH=$JAVA_HOME/bin:$PATH # Verify java -version # Make permanent (add to ~/.bashrc or ~/.zshrc) echo 'export JAVA_HOME=/usr/lib/jvm/java-21-zulu' >> ~/.bashrc source ~/.bashrc ``` -------------------------------- ### Install APK to SD Card using ADB Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/11-android-requirements.md If your device supports an SD card, you can use this ADB command to install an APK directly to the SD card, saving internal storage space. ```bash adb install -s patched.apk ``` -------------------------------- ### Get All Device Properties Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Retrieves all system properties available on the Android device. ```bash adb shell getprop ``` -------------------------------- ### Set ANDROID_HOME Environment Variable Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/05-error-codes.md Configure the ANDROID_HOME environment variable to point to your Android SDK installation. This is necessary for tools like ADB. The example assumes the default Android Studio location. Make the changes permanent by adding them to your shell's configuration file. ```bash # Set ANDROID_HOME (Android Studio default location) export ANDROID_HOME=$HOME/Android/Sdk export PATH=$ANDROID_HOME/platform-tools:$PATH # Verify adb devices # Make permanent echo 'export ANDROID_HOME=$HOME/Android/Sdk' >> ~/.bashrc echo 'export PATH=$ANDROID_HOME/platform-tools:$PATH' >> ~/.bashrc ``` -------------------------------- ### Configure Garbage Collection for Faster Patching Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Optimize garbage collection settings for improved patching performance. This example uses the G1 GC and sets a maximum pause time. ```bash java -Xms256m \ -XX:+UseG1GC \ -XX:MaxGCPauseMillis=200 \ -jar morphe-cli-all.jar patch ... ``` -------------------------------- ### Verify JDK Installation Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/02-development-setup.md Check if the installed Java Development Kit version is 21 or newer. This command should be run in your terminal after setting the JAVA_HOME environment variable. ```bash java -version ``` -------------------------------- ### ADB Installation Alias Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Alias for installing an Android application with the -r flag for reinstallation. ```shell alias adb-install='adb install -r' ``` -------------------------------- ### ADB Wireless Connection Setup Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/04-configuration.md Establishes a wireless ADB connection to an Android device (Android 11+). Requires the device's IP address. ```bash adb tcpip 5555 adb connect :5555 adb devices ``` -------------------------------- ### List Installed Packages Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Lists installed packages on the device. Filters can be applied to show only system packages (-s), third-party packages (-3), or packages matching a pattern using grep. ```bash adb shell pm list packages ``` ```bash adb shell pm list packages -s ``` ```bash adb shell pm list packages -3 ``` ```bash adb shell pm list packages | grep morphe ``` ```bash adb shell pm list packages | grep youtube ``` -------------------------------- ### Troubleshoot Permission Denied Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Addresses 'permission denied' errors, guiding users to check device authorization and reconnect for wireless debugging. ```bash # Check if authorized adb devices # If "unauthorized", device may need approval # Check device for authorization dialog # For wireless, try reconnecting adb disconnect adb connect :5555 ``` -------------------------------- ### Get Help for Specific Command Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Display detailed help information for a specific Morphe CLI command, such as 'patch'. ```bash # Help for patch command java -jar morphe-cli-all.jar help patch ``` -------------------------------- ### Get Specific Device Properties Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Retrieves specific system properties like model, Android version, build number, and codename. ```bash # Device model adb shell getprop ro.product.model # Android version adb shell getprop ro.build.version.release # Build number adb shell getprop ro.build.id # Device codename adb shell getprop ro.product.device ``` -------------------------------- ### Verify ADB Connection Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Check if ADB is installed and accessible on your system. ```bash adb devices ``` -------------------------------- ### Patch APK with Morphe CLI Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/05-error-codes.md Example of how to correctly use the Morphe CLI to patch an APK, including specifying the patches file and the input APK path. ```bash java -jar morphe-cli-all.jar patch \ --patches patches.mpp \ /home/user/Downloads/YouTube.apk ``` -------------------------------- ### Quick Diagnostics Script Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/09-troubleshooting-guide.md A bash script to gather system information, list installed relevant apps, check microG status, view app permissions, and capture recent error logs. Useful for diagnosing general app behavior and issues. ```bash #!/bin/bash echo "=== System Info ===" adb shell getprop ro.build.version.release adb shell getprop ro.product.model echo "=== Installed Apps ===" adb shell pm list packages | grep -E "morphe|youtube|microg" echo "=== microG Status ===" adb shell pm list packages | grep microg echo "=== Permissions ===" adb shell dumpsys package permissions app.morphe.android.youtube echo "=== Recent Errors ===" הראשונה logcat | grep -E "morphe|Error|Exception" & sleep 10 kill %1 ``` -------------------------------- ### Set JAVA_HOME for JDK 21+ Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/05-error-codes.md Set the JAVA_HOME environment variable to point to your JDK 21+ installation to resolve 'UnsupportedClassVersionError'. ```bash export JAVA_HOME=/path/to/jdk-21 ``` -------------------------------- ### Get Package Information Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Retrieves detailed information about a specific package, including its path, version, and permissions. Useful for debugging and analysis. ```bash adb shell dumpsys package app.morphe.android.youtube ``` -------------------------------- ### JDK Configuration in gradle.properties Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/04-configuration.md Specify the JDK installation directory for Gradle builds. Ensure the JDK version is 21 or higher. ```properties # JDK version (required: 21+) org.gradle.java.home = /path/to/jdk-21 # Example paths: # Linux/Mac: /usr/lib/jvm/java-21-zulu # Windows: C:\\Program Files\\Java\\zulu-21 ``` -------------------------------- ### Gradle Wrapper Usage Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Use the Gradle Wrapper script (`gradlew` or `gradlew.bat`) instead of a globally installed Gradle version for consistent builds across environments. This ensures the correct Gradle version is used for the project. ```bash # Unix/Linux/macOS ./gradlew # Windows gradlew.bat # Examples ./gradlew build ./gradlew clean buildAndroid ./gradlew publishToMavenLocal ``` -------------------------------- ### Extract APK using ADB Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/10-supported-apps.md Use ADB commands to find the path of an installed application and extract its APK file. This is useful for obtaining the original APK for patching. ```bash # Find app path adb shell pm path com.google.android.youtube # Extract APK adb pull /data/app/com.google.android.youtube-xxxxx/base.apk ``` -------------------------------- ### Build and Patch APK with Morphe CLI Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/00-quick-start.md Clone the Morphe CLI and patches template, build them, and then use the CLI to patch an APK. The patched APK is automatically installed via ADB. ```bash # Prerequisites: JDK 21+, Gradle, Morphe CLI built # 1. Clone and build CLI git clone -b dev https://github.com/MorpheApp/morphe-cli cd morphe-cli ./gradlew build # 2. Clone patches template cd .. git clone -b dev https://github.com/MorpheApp/morphe-patches-template cd morphe-patches-template ./gradlew buildAndroid # 3. Patch APK cd .. java -jar morphe-cli/build/libs/morphe-cli-*-all.jar patch \ --patches morphe-patches-template/build/libs/patches*.mpp \ --out morphe.apk \ --install \ original.apk # 4. App automatically installs via ADB ``` -------------------------------- ### Build Morphe CLI and Patches Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/02-development-setup.md This script builds the Morphe CLI JAR and the Android patches MPP file. It then uses the CLI to patch an input APK and install the resulting Morphe APK. ```bash #!/bin/sh cd morphe-cli ./gradlew build cd .. cd morphe-patches-template rm -f patches/build/libs/patches*.mpp ./gradlew buildAndroid cd .. # Patch and install APK java -Xms152m -jar morphe-cli/build/libs/morphe-cli*-all.jar \ patch \ --patches morphe-patches-template/build/libs/patches*.mpp \ --out morphe.apk \ input.apk \ --install ``` -------------------------------- ### Get APK Path Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Retrieves the file system path of the APK for a given package. Useful for locating the installed application file on the device. ```bash adb shell pm path app.morphe.android.youtube ``` -------------------------------- ### Create gradle.properties File Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/05-error-codes.md Use this command to create the ~/.gradle/gradle.properties file if it's missing. Ensure you replace placeholders with your actual GitHub username, token, and JDK path. ```bash mkdir -p ~/.gradle cat > ~/.gradle/gradle.properties << 'EOF' gpr.user = your-github-username gpr.key = your-github-token org.gradle.java.home = /path/to/jdk-21 EOF ``` -------------------------------- ### Create Release Keystore Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/04-configuration.md Creates a release keystore for signing production-ready APKs. Ensure you replace with a secure password. ```bash keytool -genkey -v -keystore release.keystore \ -storepass \ -alias morphe-release \ -keypass \ -keyalg RSA \ -keysize 4096 \ -validity 10000 ``` -------------------------------- ### Clean and Build Project (including tests) Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Performs a standard clean build of the project, including the execution of all tests. ```bash ./gradlew clean build ``` -------------------------------- ### Enable Verbose and Debug Output Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Demonstrates how to enable verbose, info, and debug logging for Gradle commands to aid in troubleshooting build issues. ```bash ./gradlew build -d # Debug output ./gradlew build -i # Info output ./gradlew build -v # Verbose output ``` -------------------------------- ### Configure App Link User Selection for Multiple URL Patterns Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Allows users to select how to handle multiple URL patterns for a given package, managing app link behavior. ```bash adb shell pm set-app-links-user-selection \ --user 0 \ --package app.morphe.android.youtube \ true \ youtube.com # Additional patterns adb shell pm set-app-links-user-selection \ --user 0 \ --package app.morphe.android.youtube \ true \ youtu.be adb shell pm set-app-links-user-selection \ --user 0 \ --package app.morphe.android.youtube \ true \ m.youtube.com adb shell pm set-app-links-user-selection \ --user 0 \ --package app.morphe.android.youtube \ true \ www.youtube.com ``` -------------------------------- ### List Running Processes Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Lists all running processes on the device in a detailed format. ```bash adb shell ps aux adb shell ps | grep morphe ``` -------------------------------- ### Show Display Information Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Retrieves detailed information about the device's display. ```bash adb shell dumpsys display ``` -------------------------------- ### Configure Android Build Types and Product Flavors Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Sets up Android build types (debug and release) with specific configurations and defines product flavors ('youtube', 'music') for different application variants. ```kotlin android { buildTypes { debug { debuggable = true minifyEnabled = false } release { debuggable = false minifyEnabled = true signingConfig = signingConfigs.getByName("release") } } flavorDimensions("app") productFlavors { create("youtube") { dimension = "app" } create("music") { dimension = "app" } } } ``` -------------------------------- ### Patch APK using Morphe CLI Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/06-features.md Use the Morphe CLI tool to patch an input APK file with specified patches. The `--install` flag can be used to directly install the patched APK after creation. ```bash java -jar morphe-cli-all.jar patch \ --patches patches.mpp \ --out morphe.apk \ --install \ input.apk ``` -------------------------------- ### Create Debug Keystore Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/04-configuration.md Generates a default debug keystore for development builds using the keytool command. ```bash keytool -genkey -v -keystore ~/.android/debug.keystore \ -storepass android \ -alias androiddebugkey \ -keypass android \ -keyalg RSA \ -keysize 2048 \ -validity 10000 \ -dname "CN=Android Debug,O=Android,C=US" ``` -------------------------------- ### Troubleshoot Dependency Not Found Errors Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Provides commands to check the dependency tree, verify configured repositories, and ensure authentication details are correct for resolving 'dependency not found' issues. ```bash # Check dependencies ./gradlew dependencies # Verify repositories ./gradlew repositories # Check for authentication issues # Verify gradle.properties has GitHub credentials ``` -------------------------------- ### Build Patch Files Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/07-patch-management.md Navigate to the patch template directory and execute the Gradle build command to compile patch files. ```bash cd morphe-patches-template ./gradlew buildAndroid ``` -------------------------------- ### Add Before-Launch Task for Library Publication Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/02-development-setup.md Configures a before-launch task to publish core libraries locally. This ensures the latest versions are available. ```text Run Gradle Task > morphe-patcher:publishToMavenLocal Run Gradle Task > morphe-library:publishToMavenLocal ``` -------------------------------- ### Uninstall Conflicting App Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/05-error-codes.md Remove an existing installation of an app to resolve conflicts. Replace 'app.morphe.android.youtube' with the target package name. ```bash adb uninstall app.morphe.android.youtube ``` -------------------------------- ### Configure Release Signing Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Sets up a 'release' signing configuration for Android builds, specifying the keystore file, passwords, and key alias. This configuration is then applied to the release build type. ```kotlin android { signingConfigs { create("release") { storeFile = file("path/to/keystore.jks") storePassword = System.getenv("KEYSTORE_PASSWORD") keyAlias = "release-key" keyPassword = System.getenv("KEY_PASSWORD") } } buildTypes { release { signingConfig = signingConfigs.getByName("release") } } } ``` -------------------------------- ### Logcat with Brief Format Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Displays log messages in the default, concise format. ```bash adb logcat -v brief ``` -------------------------------- ### Capture Detailed Logs Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/05-error-codes.md These commands demonstrate how to capture detailed logs from Gradle builds and ADB sessions to files. This is useful for offline analysis or when specific errors are hard to reproduce in real-time. ```bash # Save Gradle build log ./gradlew build > build.log 2>&1 # Capture ADB logs to file 燬 logcat > logcat.log & # Use app, then stop with: kill %1 # Grep for errors grep -i "error\|exception\|fatal" logcat.log ``` -------------------------------- ### Build Morphe CLI from Source Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Build the Morphe CLI JAR file from its source code using Gradle. ```bash cd morphe-cli ./gradlew build ``` -------------------------------- ### Execute Shell Script Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Make the patch script executable and run it with an input APK file. ```bash chmod +x patch.sh ./patch.sh input.apk ``` -------------------------------- ### Rebuild Morphe CLI from Scratch Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/05-error-codes.md Commands to re-clone the Morphe CLI repository if the 'build.gradle.kts' file is missing, indicating a wrong working directory or incomplete clone. ```bash git clone -b dev https://github.com/MorpheApp/morphe-cli ``` -------------------------------- ### Patch YouTube APK with Morphe CLI Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/00-quick-start.md A simplified command to patch a YouTube APK using the Morphe CLI, applying specified patches and installing the result. ```bash java -jar morphe-cli-*-all.jar patch \ --patches patches*.mpp \ --install \ YouTube.apk ``` -------------------------------- ### Enable Gradle Daemon Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Enable the Gradle daemon to keep the build process running in the background, speeding up subsequent builds. Add this to your `gradle.properties` file. ```properties org.gradle.daemon=true ``` -------------------------------- ### Live Write to File Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Redirects ADB log output to a file in real-time. ```bash adb logcat | tee logs.txt ``` -------------------------------- ### Display All Gradle Tasks Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Lists all available tasks in the Gradle project, including custom and plugin-defined tasks, to help in understanding project structure and available commands. ```bash ./gradlew tasks --all ``` -------------------------------- ### Method Hook Example with Before Insertion Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/07-patch-management.md Demonstrates creating a method hook using the @MethodHook annotation. The hookMethod inserts a debug log statement before the target method executes. ```kotlin @MethodHook class LogHook { fun hookMethod(method: /* method */) { method.insertBefore( "Log.d(\"TAG\", \"Method called\");" ) } } ``` -------------------------------- ### Enable App Links for URLs Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Configures the device to handle specific URL patterns for a given package, enabling app link functionality. ```bash # Enable app link handling for specific URLs adb shell pm set-app-links --user 0 \ --package app.morphe.android.youtube \ true \ youtube.com ``` -------------------------------- ### Clean and Build Project (excluding tests) Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Performs a clean build of the project, skipping the test execution phase to speed up the build process. ```bash ./gradlew clean build -x test ``` -------------------------------- ### Target Specific Device for ADB Operations Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Installs an APK on a specific device using its serial number or by setting the ANDROID_SERIAL environment variable. Essential when multiple devices are connected. ```bash # For multiple devices, specify target with -s adb -s install app.apk adb -s 8XXXXXX install app.apk # Alternative: set ANDROID_SERIAL export ANDROID_SERIAL=8XXXXXX adb install app.apk ``` -------------------------------- ### Build Morphe Projects Source: https://github.com/morpheapp/morphe-documentation/blob/main/docs/morphe-development/1_setup.md Build the Morphe CLI and the Android patches using Gradle. Navigate into each project directory before running the build commands. ```bash cd morphe-cli ./gradlew build cd .. cd morphe-patches-template ./gradlew buildAndroid cd .. ``` -------------------------------- ### Enable Wireless ADB Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Configure ADB to connect to devices over the network. Requires Android 11+. ```bash adb tcpip 5555 adb connect :5555 ``` -------------------------------- ### Check Build Environment Script Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/05-error-codes.md This bash script checks the versions and configurations of essential build tools including Java, Gradle, Android SDK, Git, ADB, and Gradle properties. Run this script to diagnose environment-related issues. ```bash #!/bin/bash echo "=== Java ===" java -version echo "JAVA_HOME: $JAVA_HOME" echo -e "\n=== Gradle ===" ./gradlew --version echo -e "\n=== Android SDK ===" ls -la $ANDROID_HOME/platforms/ echo -e "\n=== Git ===" git --version echo -e "\n=== ADB ===" 燬 version 燬 devices echo -e "\n=== Gradle Properties ===" cat ~/.gradle/gradle.properties ``` -------------------------------- ### Troubleshoot Connection Timeout Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Provides guidance for resolving ADB connection timeouts, including network checks and retrying connections. ```bash # Check network connection adb connect :5555 # Increase timeout # For wireless debugging, may need to retry ``` -------------------------------- ### Take Screenshot Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Captures a screenshot of the device screen and pulls it to the local computer. ```bash adb shell screencap -p /sdcard/screenshot.png adb pull /sdcard/screenshot.png ./local-screenshot.png ``` -------------------------------- ### Enable Gradle Daemon Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Enables the Gradle daemon to speed up build times by keeping a background process running. Includes an idle timeout setting. ```properties org.gradle.daemon=true org.gradle.daemon.idletimeout=1800000 ``` -------------------------------- ### Logcat with Process ID and Priority Format Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Displays log messages including the process ID and priority. ```bash adb logcat -v process ``` -------------------------------- ### Connect to Android Emulator via ADB Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/11-android-requirements.md Connect to the Android emulator using ADB. The emulator is typically auto-detected by ADB. ```bash adb devices adb shell # Access emulator ``` -------------------------------- ### Run Morphe CLI Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Execute the Morphe CLI JAR file with a specified command and options. A minimum heap size of 152MB is recommended. ```bash java -Xms152m -jar morphe-cli--all.jar [options] ``` -------------------------------- ### Check Gradle Dependency Tree Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/02-development-setup.md Command to display the dependency tree for the Gradle project. Helps in identifying transitive dependencies and conflicts. ```bash ./gradlew dependencies ``` -------------------------------- ### Troubleshoot Device Not Found Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Provides steps to diagnose and resolve 'device not found' errors, including checking connections and restarting the ADB server. ```bash # Check if device is connected adb devices # If not listed: # 1. Verify USB cable is connected # 2. Enable USB debugging on device # 3. Authorize connection when prompted # 4. Restart ADB server adb kill-server adb start-server adb devices ``` -------------------------------- ### Press Key Events Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Simulates key presses on the device, such as Enter, Back, Home, Menu, or Power. ```bash adb shell input keyevent 66 # Enter key adb shell input keyevent 4 # Back button adb shell input keyevent 3 # Home button adb shell input keyevent 82 # Menu button adb shell input keyevent 26 # Power button ``` -------------------------------- ### Configure Maven Repositories Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Defines repositories for fetching dependencies, including Maven Central, a GitHub Packages repository with credentials, and Google's Maven repository. ```kotlin repositories { mavenCentral() maven("https://maven.pkg.github.com/MorpheApp/morphe-patcher") { credentials { username = project.findProperty("gpr.user").toString() password = project.findProperty("gpr.key").toString() } } google() } ``` -------------------------------- ### Build Custom Patches Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/00-quick-start.md Instructions for forking the Morphe patches template, defining patches in Kotlin, and building them using Gradle. ```bash 1. Fork: https://github.com/MorpheApp/morphe-patches-template 2. Define patches in Kotlin 3. Build: "./gradlew buildAndroid" 4. Use with Morphe CLI Documentation: [Patch Management Guide](07-patch-management.md) ``` -------------------------------- ### Configure Task Inputs and Outputs Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Registers a 'Copy' task named 'copyArtifacts' that copies files from 'build/outputs' to 'dist', defining the task's inputs and outputs for incremental build optimization. ```kotlin tasks.register("copyArtifacts") { from("build/outputs") into("dist") inputs.dir("build/outputs") outputs.dir("dist") } ``` -------------------------------- ### Verify Patch File Output Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/07-patch-management.md List the compiled patch files in the build output directory to confirm successful building. ```bash ls patches/build/libs/patches*.mpp ``` -------------------------------- ### Module build.gradle.kts Configuration Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Module-specific `build.gradle.kts` files configure individual components. They declare plugins, dependencies, and module-specific settings like publishing. ```kotlin plugins { kotlin("jvm") `maven-publish` } dependencies { // Module dependencies } publishing { // Publication configuration } ``` -------------------------------- ### Root build.gradle.kts Configuration Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md The root `build.gradle.kts` file configures multi-module builds. It typically defines plugins and applies common configurations to all subprojects. ```kotlin plugins { id("com.android.application") version "8.x.x" apply false kotlin("android") version "1.9.x" apply false } subprojects { // Configuration applied to all subprojects } ``` -------------------------------- ### Morphe CLI Run Configuration Arguments Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/02-development-setup.md Arguments for running the morphe-cli with a patch file. Ensure to replace `` with the current patch version. ```bash patch --patches morphe-patches-template/patches/build/libs/patches-.mpp binaries/some.apk --install ``` -------------------------------- ### Reinstall APK Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Overwrite an existing application with a new version of the APK. ```bash adb install -r patched.apk ``` -------------------------------- ### Check Gradle Wrapper Version Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Displays the current version of the Gradle wrapper being used by the project. ```bash ./gradlew --version ``` -------------------------------- ### IntelliJ IDEA Run Configuration Arguments Source: https://github.com/morpheapp/morphe-documentation/blob/main/docs/morphe-development/1_setup.md Configure program arguments for the Morphe CLI run configuration in IntelliJ IDEA. Ensure the path to the patches MPP file is updated as it changes with releases. ```sh patch --patches morphe-patches-template\patches\build\libs\patches-.mpp binaries\some.apk --install # Install the patched APK to a device connected via ADB after patching ``` -------------------------------- ### Record Screen Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Records the device screen activity and allows pulling the video file to the computer. ```bash # Record to device adb shell screenrecord /sdcard/video.mp4 # Stop with Ctrl+C # Pull to computer adb pull /sdcard/video.mp4 ./local-video.mp4 ``` -------------------------------- ### Profile Gradle Build Performance Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Executes a Gradle build and generates a performance profile report to identify build time bottlenecks. The report is saved in the build/reports/profile directory. ```bash ./gradlew build --profile ``` -------------------------------- ### Enable Parallel Builds Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Allow Gradle to execute independent tasks in parallel to utilize multi-core processors more effectively. Configure this in your `gradle.properties`. ```properties org.gradle.parallel=true ``` -------------------------------- ### Clean Project and Gradle Cache Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Performs a clean build of the project and manually removes the Gradle cache directory to ensure a fresh build environment. ```bash ./gradlew clean rm -rf ~/.gradle/caches/ ``` -------------------------------- ### Logcat with System Time Format Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Displays log messages with system timestamps. ```bash adb logcat -v time ``` -------------------------------- ### Manual Patch Update and Rebuild Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/07-patch-management.md Use this command to manually download new patches, rebuild them from source, and then apply them using the CLI. Ensure you are in the correct directory for these operations. ```bash # Download new patches manually # Rebuild from source: cd morphe-patches-template git pull origin dev ./gradlew buildAndroid # Use new patches with CLI: java -jar morphe-cli-all.jar patch \ --patches patches/build/libs/patches-*.mpp \ input.apk ``` -------------------------------- ### Reinstall microG and Patched App Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/09-troubleshooting-guide.md If experiencing 'No internet connection' errors, reinstall microG and the Morphe app. This ensures proper integration and connectivity. ```bash adb uninstall com.google.android.gms # Then install fresh microG ``` ```bash adb uninstall app.morphe.android.youtube # Reinstall patched version ``` -------------------------------- ### Configure R8/Proguard for Release Optimization Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Enables code shrinking, obfuscation, and optimization for release builds using R8 (or Proguard) and specifies the configuration files to use. ```kotlin android { buildTypes { release { minifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) } } } ``` -------------------------------- ### Basic APK Patching Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/03-cli-reference.md Patch an APK file using a specified patch file and output to a new APK file. Ensure the input APK and patch file exist. ```bash java -jar morphe-cli-all.jar patch \ --patches patches.mpp \ --out patched.apk \ input.apk ``` -------------------------------- ### Enable Debug Logging for Build Tools Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/05-error-codes.md This snippet shows how to enable debug logging for Gradle, Java applications, and ADB. Use these commands to gather more detailed information when troubleshooting issues. ```bash # Gradle debug ./gradlew --debug build # Java debug java -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG \ -jar morphe-cli-all.jar patch --patches patches.mpp input.apk # ADB verbose 燬 logcat | grep -i "morphe\|error\|exception" ``` -------------------------------- ### Send Text Input Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Simulates text input on the device's current focused field. ```bash adb shell input text "Hello World" ``` -------------------------------- ### Enable or Disable Application Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Enables or disables a specific application package on the device. Can be done for all users or a specific user ID. ```bash adb shell pm disable app.morphe.android.youtube ``` ```bash adb shell pm enable app.morphe.android.youtube ``` ```bash adb shell pm disable --user app.morphe.android.youtube ``` ```bash adb shell pm enable --user app.morphe.android.youtube ``` -------------------------------- ### Force Dependency Refresh and Build Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Refreshes all dependencies from their repositories and then performs a clean build, useful for resolving issues with outdated or corrupted dependencies. ```bash # Force dependency refresh ./gradlew --refresh-dependencies clean build ``` -------------------------------- ### Configure Custom Source Set Directories Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Customizes the source directories for the 'main' source set in an Android project, explicitly mapping Kotlin and Java source directories. ```kotlin android { sourceSets { getByName("main") { kotlin.srcDir("src/main/kotlin") java.srcDir("src/main/java") } } } ``` -------------------------------- ### Clone and Navigate Template Repository Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/07-patch-management.md Fork the Morphe patch template repository on GitHub, then clone your fork and navigate into the repository directory. ```bash # Fork on GitHub, then clone git clone https://github.com/YOUR_ACCOUNT/morphe-patches-template cd morphe-patches-template ``` -------------------------------- ### Morphe System Components Diagram Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/01-overview.md Illustrates the layered architecture of the Morphe system, from the user interface to patch definitions and the final output. ```text User Interface Layer ├── Morphe Manager (Android App) └── Morphe CLI (Command Line) Core Patching Engine ├── Morphe Patcher (Bytecode Manipulation) └── Morphe Library (Utilities & Framework) Patch Definitions ├── Morphe Patches (Official Patches) └── Custom Patches (User-defined) Output └── Patched APK (Modified Application) ``` -------------------------------- ### Force Dependency Refresh and Build Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/02-development-setup.md Command to force a refresh of Gradle dependencies and then clean and build the project. Useful for resolving dependency issues. ```bash ./gradlew --refresh-dependencies clean build ``` -------------------------------- ### Troubleshoot Task Not Found Errors Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Provides commands to list all available tasks and search for specific tasks, helping to diagnose and resolve 'task not found' errors. ```bash # List available tasks ./gradlew tasks --all # Search for specific task ./gradlew tasks --all | grep buildAndroid ``` -------------------------------- ### Enter Interactive Shell Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/08-adb-commands.md Opens an interactive shell session on the Android device for executing multiple commands. ```bash adb shell # Then execute commands directly ``` -------------------------------- ### Android Plugin Configuration Source: https://github.com/morpheapp/morphe-documentation/blob/main/_autodocs/12-gradle-configuration.md Configure Android application or library builds. Set essential properties like `compileSdk`, `minSdk`, and `targetSdk` within the `android` block. ```kotlin plugins { id("com.android.application") id("com.android.library") } android { compileSdk = 35 defaultConfig { minSdk = 26 targetSdk = 35 } } ```