Apktool icon indicating copy to clipboard operation
Apktool copied to clipboard

[BUG] Path quotes are broken, kinda?

Open ariccio opened this issue 3 years ago • 4 comments

Information

  1. Apktool Version (apktool -version) - 2.6.1
  2. Operating System (Mac, Linux, Windows) - Windows

Stacktrace/Logcat

>apktool
'""C:' is not recognized as an internal or external command,
operable program or batch file.

Steps to Reproduce

  1. set %JAVA_HOME% to a path with a space, which needs quotes to work with most software. E.g.: "C:/Program Files/Java/jdk-15.0.2"
  2. comment out @echo off (to show actual commands)
  3. Run apktool.
  4. apktool crashes when the batch file tries to invoke the jar with:
""C:/Program Files/Java/jdk-15.0.2"\bin\java.exe" -jar -Duser.language=en -Dfile.encoding=UTF8 "C:\apktool\apktool.jar"
'""C:' is not recognized as an internal or external command,
operable program or batch file.

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? N/A, but yes.
  2. If you are trying to install a modified apk, did you resign it? N/A
  3. Are you using the latest apktool version? yes

Fix for my system

By adding quotes around %java_exe% - "%java_exe%", it invokes the jar correctly. It produces this monstrosity of a command line:

"""C:/Program Files/Java/jdk-15.0.2"\bin\java.exe"" -jar -Duser.language=en -Dfile.encoding=UTF8 "C:\apktool\apktool.jar"

and that works! There's no way that's the right solution. But string manipulation in batch scripts is painful & cruel, so I'm not gonna try writing a proper patch.

...I'm still hoping that filing this bug report might help someone!

ariccio avatar Jul 27 '22 19:07 ariccio

Not sure of any solution myself, but if thats what Gradle does - https://github.com/iBotPeaches/Apktool/blob/master/gradlew.bat#L74

That works for me. If you'd like to PR that - I'd accept it. Otherwise I'll get to it in a day or so.

iBotPeaches avatar Jul 27 '22 19:07 iBotPeaches

as long you have at least one result in where java.exe (errorlevel will return 0), I.E. it exists in PATH, you are perfectly fine just to run call java -jar ..., you don't need to actually build the target path to the java execute, that's an unneeded overkill mess.

don't use that batch file,
write your own or use something like that:
https://github.com/eladkarako/android/blob/master/bin/apktool/apktool.cmd


eladkarako avatar Jul 31 '22 23:07 eladkarako

I think batch scripts are an abomination, so I don't generally submit PRs about them :)

ariccio avatar Aug 02 '22 21:08 ariccio

I think batch scripts are an abomination

you are more than welcome to use NodeJS js
with child_processes and spawn, to skip the shell middleman
and launch your application directly with whatever arguments you want. will work the same for any OS.

eladkarako avatar Aug 02 '22 22:08 eladkarako