0

After ApkTool executes the !name! variable no longer expands as expected. I'm not sure what's going on here nor how to fix it.

if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit @echo off setlocal ENABLEDELAYEDEXPANSION cd /d "%~dp0" for %%I in ("%~1") do ( set name="..\Compiled_apk\%%~nxI" apktool b "%%~I" -f -o "!name!.apk" zipalign -f 4 "!name!.apk" "!name!.temp" del "!name!.apk" ren "!name!.temp" "!name!.apk" apksigner sign -v --key "..\Program_Files\testkey.pk8" --cert "..\Program_Files\testkey.x509.pem" "!name!.apk" ) exit 
4
  • 4
    The only thing I can think of is that apktool is a script and since you're not using call, control never comes back to the main script after that point. If apktool is a regular exe file, I've never heard of this happening and I don't understand how it's even possible. Commented Oct 15, 2018 at 19:08
  • @SomethingDark, it is a batch file. Your comment is correct. Commented Oct 15, 2018 at 19:31
  • You wouldn't need to use delayed expansion if you just used the FOR variable by itself. Regardless, that was not the problem with your script. Commented Oct 15, 2018 at 19:34
  • Thanks, please post that as an answer. I've never tried to call another batch with delayed expansion enabled so I had no idea that could happen. Squashman, I agree, but this is only one of several scripts - it's just a test. Commented Oct 15, 2018 at 21:10

1 Answer 1

1

When you start a second batch script without using call, the original script stops and control is transferred to the second script. Once the second script finishes, control does not return to the original script (since it is stopped).

However, if you use call to start the second script, the original script pauses and control is only temporarily handed to the second script. Once the second script finishes, control returns to the original script and it picks up where it left off.

apktool b "%%~I" -f -o "!name!.apk" 

Google suggests that zipalign and apksigner are actual executables, so you don't need to call those.

Sign up to request clarification or add additional context in comments.

Comments