1@echo off 2REM Copyright (C) 2024 The Android Open Source Project 3REM 4REM Licensed under the Apache License, Version 2.0 (the "License"); 5REM you may not use this file except in compliance with the License. 6REM You may obtain a copy of the License at 7REM 8REM http://www.apache.org/licenses/LICENSE-2.0 9REM 10REM Unless required by applicable law or agreed to in writing, software 11REM distributed under the License is distributed on an "AS IS" BASIS, 12REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13REM See the License for the specific language governing permissions and 14REM limitations under the License. 15 16REM don't modify the caller's environment 17setlocal 18 19REM Locate apksigner.jar in the directory where apksigner.bat was found and start it. 20 21REM Set up prog to be the path of this script, including following symlinks, 22REM and set up progdir to be the fully-qualified pathname of its directory. 23set prog=%~f0 24 25@rem Find java.exe 26if defined JAVA_HOME goto findJavaFromJavaHome 27 28set JAVA_EXE=java.exe 29%JAVA_EXE% -version >NUL 2>&1 30if "%ERRORLEVEL%" == "0" goto init 31 32echo. 33echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 34echo. 35echo Please set the JAVA_HOME variable in your environment to match the 36echo location of your Java installation. 37exit /b 1 38 39:findJavaFromJavaHome 40set JAVA_HOME=%JAVA_HOME:"=% 41set JAVA_EXE=%JAVA_HOME%/bin/java.exe 42 43if exist "%JAVA_EXE%" goto init 44 45echo. 46echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 47echo. 48echo Please set the JAVA_HOME variable in your environment to match the 49echo location of your Java installation. 50exit /b 1 51 52:init 53REM TODO(b/329887683): reuse existing apksigner.bat script (this is the only difference) 54set jarfile=apksigner-kms.jar 55set "frameworkdir=%~dp0" 56rem frameworkdir must not end with a dir sep. 57set "frameworkdir=%frameworkdir:~0,-1%" 58 59if exist "%frameworkdir%\%jarfile%" goto JarFileOk 60 set "frameworkdir=%~dp0lib" 61 62if exist "%frameworkdir%\%jarfile%" goto JarFileOk 63 set "frameworkdir=%~dp0..\framework" 64 65:JarFileOk 66 67set "jarpath=%frameworkdir%\%jarfile%" 68 69set javaOpts= 70set args= 71 72REM By default, give apksigner a max heap size of 1 gig and a stack size of 1meg. 73rem This can be overridden by using "-JXmx..." and "-JXss..." options below. 74set defaultXmx=-Xmx1024M 75set defaultXss=-Xss1m 76 77REM Capture all arguments that are not -J options. 78REM Note that when reading the input arguments with %1, the cmd.exe 79REM automagically converts --name=value arguments into 2 arguments "--name" 80REM followed by "value". apksigner has been changed to know how to deal with that. 81set params= 82 83:firstArg 84if [%1]==[] goto endArgs 85set "a=%~1" 86 87 if [%defaultXmx%]==[] goto notXmx 88 if "%a:~0,5%" NEQ "-JXmx" goto notXmx 89 set defaultXmx= 90 :notXmx 91 92 if [%defaultXss%]==[] goto notXss 93 if "%a:~0,5%" NEQ "-JXss" goto notXss 94 set defaultXss= 95 :notXss 96 97 if "%a:~0,2%" NEQ "-J" goto notJ 98 set javaOpts=%javaOpts% -%a:~2% 99 shift /1 100 goto firstArg 101 102 :notJ 103 set params=%params% %1 104 shift /1 105 goto firstArg 106 107:endArgs 108 109set javaOpts=%javaOpts% %defaultXmx% %defaultXss% 110call "%java_exe%" %javaOpts% -jar "%jarpath%" %params% 111 112