Skip to content

Instantly share code, notes, and snippets.

@vavrecan
Last active March 9, 2025 09:01
Show Gist options
  • Select an option

  • Save vavrecan/8596303 to your computer and use it in GitHub Desktop.

Select an option

Save vavrecan/8596303 to your computer and use it in GitHub Desktop.

Revisions

  1. vavrecan revised this gist Jan 24, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions rename-apk-namespace
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    #!/bin/bash
    # author Marek Vavrecan (vavrecan@gmail.com)

    # show usage
    [ $# -eq 0 ] && { echo "Usage: $0 [apk path] [source namespace] [target namespace]"; exit 1; }
  2. vavrecan created this gist Jan 24, 2014.
    44 changes: 44 additions & 0 deletions rename-apk-namespace
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #!/bin/bash

    # show usage
    [ $# -eq 0 ] && { echo "Usage: $0 [apk path] [source namespace] [target namespace]"; exit 1; }

    APK_PATH="$1"
    NAMESPACE_FROM="$2"
    NAMESPACE_TO="$3"

    # escape .
    NAMESPACE_REPLACE=$(echo "s/$NAMESPACE_FROM/$NAMESPACE_TO/g" | sed -e 's/\./\\\./g')

    # change to smalli support com.namespace to com/namespace
    NAMESPACE_SLASHES_REPLACE=$(echo "s/$NAMESPACE_FROM/$NAMESPACE_TO/g" | sed -e 's/\./\\\//g')

    if [ -f "apktool.jar" ];
    then
    else
    echo "Please get apktool from http://code.google.com/p/android-apktool/ to continue"
    exit 1;
    fi

    java -jar apktool.jar d -o out -f $APK_PATH

    # replace tricks
    find ./out -type f -exec sed -i $NAMESPACE_REPLACE {} \;
    find ./out -type f -exec sed -i $NAMESPACE_SLASHES_REPLACE {} \;
    find ./out -type f -exec sed -i 's/<string name="app_name">\(.*\)<\/string>/<string name="app_name">\1 Beta<\/string>/g' {} \;

    mv out/smali/com/youcognize out/smali/com/youcognizebeta

    # compile
    java -jar apktool.jar b -o ./debug.apk -f ./out

    # sign it again
    jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore key.keystore ./debug.apk "password" -storepass "password" -keypass "password"

    # cleanup
    rm -R ./out

    # to get key
    # keytool -genkey -v -keystore key.keystore -alias password -keyalg RSA -keysize 2048 -validity 10000
    # this might be needed to fix align, but was not needed so far
    # zipalign -v 4 debug.apk debug2.apk