You are not logged in.
Pages: 1
Hello... Renamer is such an awesome tool and I would like to thank you for your effort in developing a tool that comes in handy every day!
Could you add the ability to read the "meta data" (i'm not sure of the correct term) of android APK files in order to rename them with possibilities of the of the following fields: Package / Application / VersionName
There is an application called APKSpy (http://forum.xda-developers.com/showthr … ?t=1115021), that does allow renaming, but its options are very limited.
Thanx in advance!
Offline
It's possible, but requires a lot of development. Instead, I will suggest finding a command line tool which is able to extract the necessary meta information form APK files, which you then could use inside ReNamer with the help of PascalScript rule.
Guys here could defiantly give you a hand with the script for integrating a command line tool into ReNamer.
Offline
I was investigating how to effectively rename apk collection so I came to this customizable Pascal Script which is able to extract most of apk meta data and fix newline errors in ReNamer files panel using regex function:
var
AaptPath, NewNamePattern, Command: WideString;
AppName, PackageName, VersionName, VersionCode: WideString;
MinSdkVersion, TargetSdkVersion, CompileSdkVersion: WideString;
Densities, NativeCode, Locales, ScreenSizes, Permissions: WideString;
Output: String;
ExitCode: Cardinal;
Matches, PermissionLines: TWideStringArray; SinglePermission: WideString;
DebugMode: Boolean;
I: Integer;
// Function that maps the SDK number to the requested text format
function GetAndroidVersionName(ApiStr: WideString): WideString;
var
ApiNum: Integer;
VerText: WideString;
begin
if ApiStr = '' then
begin
Result := '';
Exit;
end;
ApiNum := StrToIntDef(ApiStr, 0);
case ApiNum of
1: VerText := 'Android 1.0';
2: VerText := 'Android 1.1 (Petit Four)';
3: VerText := 'Android 1.5 (Cupcake)';
4: VerText := 'Android 1.6 (Donut)';
5: VerText := 'Android 2.0 (Eclair)';
6: VerText := 'Android 2.0.1 (Eclair)';
7: VerText := 'Android 2.1 (Eclair)';
8: VerText := 'Android 2.2 (Froyo)';
9: VerText := 'Android 2.3 (Gingerbread)';
10: VerText := 'Android 2.3.3 (Gingerbread)';
11: VerText := 'Android 3.0 (Honeycomb)';
12: VerText := 'Android 3.1 (Honeycomb)';
13: VerText := 'Android 3.2 (Honeycomb)';
14: VerText := 'Android 4.0 (Ice Cream Sandwich)';
15: VerText := 'Android 4.0.3 (Ice Cream Sandwich)';
16: VerText := 'Android 4.1 (Jelly Bean)';
17: VerText := 'Android 4.2 (Jelly Bean)';
18: VerText := 'Android 4.3 (Jelly Bean)';
19: VerText := 'Android 4.4 (KitKat)';
20: VerText := 'Android 4.4W (KitKat Wear)';
21: VerText := 'Android 5.0 (Lollipop)';
22: VerText := 'Android 5.1 (Lollipop MR1)';
23: VerText := 'Android 6.0 (Marshmallow)';
24: VerText := 'Android 7.0 (Nougat)';
25: VerText := 'Android 7.1 (Nougat)';
26: VerText := 'Android 8.0 (Oreo)';
27: VerText := 'Android 8.1 (Oreo)';
28: VerText := 'Android 9.0 (Pie)';
29: VerText := 'Android 10 (Quince Tart)';
30: VerText := 'Android 11 (Red Velvet Cake)';
31: VerText := 'Android 12 (Snow Cone)';
32: VerText := 'Android 12L (Snow Cone v2)';
33: VerText := 'Android 13 (Tiramisu)';
34: VerText := 'Android 14 (Upside Down Cake)';
35: VerText := 'Android 15 (Vanilla Ice Cream)';
36: VerText := 'Android 16 (Baklava)';
37: VerText := 'Android 17 (Cinnamon Bun)';
else VerText := 'Android Unknown';
end;
// Format SDK number
Result := VerText + ' (API ' + ApiStr + ')';
end;
begin
// ==================== CONFIGURATION ====================
// 1. Enter the EXACT path to the aapt2.exe tool on your system - download from https://aaptdownload.com/aapt-windows.zip:
AaptPath := 'C:\Users\UserName\Desktop\aapt2.exe';
// 2. Declare the pattern for the new file name.
// Available tags:
// [NAME], [PACKAGE], [VERSION], [CODE], [PERMISSIONS]
// [MIN_SDKVERSION], [TARGET_SDKVERSION], [COMPILE_SDKVERSION]
// [DENSITIES], [NATIVE_CODE], [LOCALES], [SCREEN_SIZES]
NewNamePattern := '[NAME] [VERSION].[CODE]';
// 3. DEBUG MODE: Set to True to see the raw output from aapt2.exe
// Set to False for normal renaming operation using the pattern above.
DebugMode := False;
// =======================================================
// Execute only if the file extension is APK
if WideLowerCase(WideExtractFileExt(FileName)) = '.apk' then
begin
// Prepare the command line for ExecConsoleApp to extract badging metadata
Command := '"' + AaptPath + '" dump badging "' + FilePath + '"';
// Execute the console application and capture its standard output
ExitCode := ExecConsoleApp(Command, Output);
// If the tool executed successfully and returned data
if (ExitCode = 0) and (Output <> '') then
begin
// If DebugMode is enabled, bypass renaming and output the raw text
if DebugMode then
begin
FileName := Output + '.apk';
Exit;
end;
// --- 1. CORE METADATA EXTRACTION ---
// Isolate the Package Name
Matches := SubMatchesRegEx(Output, 'package: name=''([^'']*)''', False);
if Length(Matches) > 0 then PackageName := Matches[0];
// Isolate the Version Code
Matches := SubMatchesRegEx(Output, 'versionCode=''([^'']*)''', False);
if Length(Matches) > 0 then VersionCode := Matches[0];
// Isolate the Version Name
Matches := SubMatchesRegEx(Output, 'versionName=''([^'']*)''', False);
if Length(Matches) > 0 then VersionName := Matches[0];
// Isolate the Compile SDK Version
Matches := SubMatchesRegEx(Output, 'compileSdkVersion=''([^'']*)''', False);
if Length(Matches) > 0 then CompileSdkVersion := Matches[0];
// Isolate the Minimum SDK Version
Matches := SubMatchesRegEx(Output, 'sdkVersion:''([^'']*)''', False);
if Length(Matches) > 0 then MinSdkVersion := Matches[0];
// Isolate the Target SDK Version
Matches := SubMatchesRegEx(Output, 'targetSdkVersion:''([^'']*)''', False);
if Length(Matches) > 0 then TargetSdkVersion := Matches[0];
// Pass extracted values through the version mapping function
MinSdkVersion := GetAndroidVersionName(MinSdkVersion);
TargetSdkVersion := GetAndroidVersionName(TargetSdkVersion);
CompileSdkVersion := GetAndroidVersionName(CompileSdkVersion);
// --- 2. LIST METADATA EXTRACTION ---
Matches := SubMatchesRegEx(Output, 'densities:\s*([^\r]*)', False);
if Length(Matches) > 0 then
begin
Densities := WideReplaceStr(Matches[0], ''' ''', ', ');
Densities := WideReplaceStr(Densities, '''', '');
end;
Matches := SubMatchesRegEx(Output, 'native-code:\s*([^\r]*)', False);
if Length(Matches) > 0 then
begin
NativeCode := WideReplaceStr(Matches[0], ''' ''', ', ');
NativeCode := WideReplaceStr(NativeCode, '''', '');
end;
Matches := SubMatchesRegEx(Output, 'locales:\s*([^\r]*)', False);
if Length(Matches) > 0 then
begin
Locales := WideReplaceStr(Matches[0], ''' ''', ', ');
Locales := WideReplaceStr(Locales, '''', '');
end;
Matches := SubMatchesRegEx(Output, 'supports-screens:\s*([^\r]*)', False);
if Length(Matches) > 0 then
begin
ScreenSizes := WideReplaceStr(Matches[0], ''' ''', ', ');
ScreenSizes := WideReplaceStr(ScreenSizes, '''', '');
end;
// --- 3. GLOBAL PERMISSIONS EXTRACTION ---
PermissionLines := MatchesRegEx(Output, 'uses-permission: name=''[^'']+''', False);
if Length(PermissionLines) > 0 then
begin
Permissions := '';
for I := 0 to Length(PermissionLines) - 1 do
begin
SinglePermission := ReplaceRegEx(PermissionLines[I], 'uses-permission: name=''([^'']+)''', '$1', False, True);
if SinglePermission <> '' then
begin
if Permissions <> '' then Permissions := Permissions + ', ';
Permissions := Permissions + SinglePermission;
end;
end;
end;
// --- 4. APPLICATION NAME EXTRACTION ---
Matches := SubMatchesRegEx(Output, '\bapplication-label:''([^'']*)''', False);
if Length(Matches) > 0 then AppName := Matches[0];
if AppName = '' then
begin
Matches := SubMatchesRegEx(Output, '\bapplication: label=''([^'']*)''', False);
if Length(Matches) > 0 then AppName := Matches[0];
end;
if AppName = '' then AppName := PackageName;
// --- 5. PATTERN REPLACEMENT ---
if (AppName <> '') or (PackageName <> '') then
begin
NewNamePattern := WideReplaceStr(NewNamePattern, '[NAME]', AppName);
NewNamePattern := WideReplaceStr(NewNamePattern, '[PACKAGE]', PackageName);
NewNamePattern := WideReplaceStr(NewNamePattern, '[VERSION]', VersionName);
NewNamePattern := WideReplaceStr(NewNamePattern, '[CODE]', VersionCode);
NewNamePattern := WideReplaceStr(NewNamePattern, '[MIN_SDKVERSION]', MinSdkVersion);
NewNamePattern := WideReplaceStr(NewNamePattern, '[TARGET_SDKVERSION]', TargetSdkVersion);
NewNamePattern := WideReplaceStr(NewNamePattern, '[COMPILE_SDKVERSION]', CompileSdkVersion);
NewNamePattern := WideReplaceStr(NewNamePattern, '[DENSITIES]', Densities);
NewNamePattern := WideReplaceStr(NewNamePattern, '[NATIVE_CODE]', NativeCode);
NewNamePattern := WideReplaceStr(NewNamePattern, '[LOCALES]', Locales);
NewNamePattern := WideReplaceStr(NewNamePattern, '[SCREEN_SIZES]', ScreenSizes);
NewNamePattern := WideReplaceStr(NewNamePattern, '[PERMISSIONS]', Permissions);
// Sanitize the filename by replacing or removing illegal OS characters (\ / : * ? " < > |)
NewNamePattern := WideReplaceStr(NewNamePattern, '/', '-');
NewNamePattern := WideReplaceStr(NewNamePattern, '\', '-');
NewNamePattern := WideReplaceStr(NewNamePattern, ':', '-');
NewNamePattern := WideReplaceStr(NewNamePattern, '*', '');
NewNamePattern := WideReplaceStr(NewNamePattern, '?', '');
NewNamePattern := WideReplaceStr(NewNamePattern, '"', '');
NewNamePattern := WideReplaceStr(NewNamePattern, '<', '');
NewNamePattern := WideReplaceStr(NewNamePattern, '>', '');
NewNamePattern := WideReplaceStr(NewNamePattern, '|', '');
// Assign the final formatted name with the extension
FileName := NewNamePattern + '.apk';
end;
end;
end;
end.Requirements:
To use this script, you must point AaptPath to a valid aapt2.exe file. You can download a standalone Windows build directly from this mirror link: aapt-windows.zip.
Script Analysis & Key Features:
GetAndroidVersionName function: It contains a lookup list of all Android versions and their official codenames. It automatically translates API level numbers (like 23) into clean, human-readable tags like "Android 6.0 (Marshmallow) (API 23)".
CONFIGURATION: You can define path of aapt2.exe file (Android Asset Packaging Tool) and NewNamePattern using tags: NAME, PACKAGE, VERSION, CODE, PERMISSIONS, MIN_SDKVERSION, TARGET_SDKVERSION, COMPILE_SDKVERSION, DENSITIES, NATIVE_CODE, LOCALES, SCREEN_SIZES. This is an example pattern: '[NAME] [VERSION] [PACKAGE]'
The Newline Fix (Using [^\r]* RegEx): Fetching multi-value metadata like densities, native-code, or supports-screens caused severe formatting bugs. The raw console output from aapt2 ends these lines with carriage returns. ReNamer's files panel interpreted those raw line breaks literally, corrupting the filename grid visualization. By switching the pattern to ([^\r]*), the script explicitly halts extraction right before the carriage return, completely resolving the visual newline glitch.
Global Permission Aggregation: Instead of grabbing just the first encountered permission, MatchesRegEx(Output, 'uses-permission: name=''[^'']+''', False) loops globally through the entire dump. It collects all permissions, strips the boilerplate syntax via ReplaceRegEx, and merges them into a comma-separated single line tag [PERMISSIONS].
Filename Sanitization: At the very end, the script acts as a safety net by explicitly swapping or deleting illegal OS filesystem characters (\ / : * ? " < > |), ensuring Windows doesn't reject the final output string.
Note: Adding larger list/size apks to ReNamer will take some time to process. Test the output with few smaller apks before deciding to add all of them.
Hopefully, this script helps anyone managing large offline Android application archives! If you have any suggestions or optimizations feel free to share!
P.S. Денис, using 3rd party tool within Pascal sript rule seems to cause Analyze dialog to ignore New name string in Text after applying rules box. I checked some other Pascal script examples and they work fine. If this is an issue, let me know to open separate topic if required.
Offline
Pages: 1