Android jar / dex方法依赖于windows

我已经看到了一些用于计算Linux和MacOS上的方法的链接,但是我还没有看到任何有关Windows的方法。 如何计算.dex或.jar文件中的多个方法?

Solutions Collecting From Web of "Android jar / dex方法依赖于windows"

在搜索解决方案失败之后,我编写了两个简单的批处理/ shell脚本。

第一个方法methodcount.bat检查文件是.dex还是.jar,如果是.jar文件,则用dx将它处理成dex文件,然后调用第二个文件printhex.ps1,在dex文件中的方法数量 – 它从88(小端)开始读取2个字节并将它们转换成十进制数字。

要使用这个,你需要在你的路径(在android SDK build-tools / xx.xx文件夹中)有dx,并安装了PowerShell(它应该已经安装在Windows 7/8上)。

用法非常简单: methodcount.bat filename.dex | filename.jar

这里是脚本,但你也可以找到他们的要点: https : //gist.github.com/mrsasha/9f24e129ced1b1db791b 。

methodcount.bat

@ECHO OFF IF "%1"=="" GOTO MissingFileNameError IF EXIST "%1" (GOTO ContinueProcessing) ELSE (GOTO FileDoesntExist) :ContinueProcessing set FileNameToProcess=%1 set FileNameForDx=%~n1.dex IF "%~x1"==".dex" GOTO ProcessWithPowerShell REM preprocess Jar with dx IF "%~x1"==".jar" ( ECHO Processing Jar %FileNameToProcess% with DX! CALL dx --dex --output=%FileNameForDx% %FileNameToProcess% set FileNameToProcess=%FileNameForDx% IF ERRORLEVEL 1 GOTO DxProcessingError ) :ProcessWithPowerShell ECHO Counting methods in DEX file %FileNameToProcess% CALL powershell -noexit -executionpolicy bypass "& ".\printhex.ps1" %FileNameToProcess% GOTO End :MissingFileNameError @ECHO Missing filename for processing GOTO End :DxProcessingError @ECHO Error processing file %1% with dx! GOTO End :FileDoesntExist @ECHO File %1% doesn't exist! GOTO End :End 

printhex.ps1

 <# .SYNOPSIS Outputs the number of methods in a dex file. .PARAMETER Path Specifies the path to a file. Wildcards are not permitted. #> param( [parameter(Position=0,Mandatory=$TRUE)] [String] $Path ) if ( -not (test-path -literalpath $Path) ) { write-error "Path '$Path' not found." -category ObjectNotFound exit } $item = get-item -literalpath $Path -force if ( -not ($? -and ($item -is [System.IO.FileInfo])) ) { write-error "'$Path' is not a file in the file system." -category InvalidType exit } if ( $item.Length -gt [UInt32]::MaxValue ) { write-error "'$Path' is too large." -category OpenError exit } $stream = [System.IO.File]::OpenRead($item.FullName) $buffer = new-object Byte[] 2 $stream.Position = 88 $bytesread = $stream.Read($buffer, 0, 2) $output = $buffer[0..1] #("{1:X2} {0:X2}") -f $output $outputdec = $buffer[1]*256 + $buffer[0] "Number of methods is " + $outputdec $stream.Close() 

我看到这个问题是旧的,但有一个将在Windows上工作的Gradle插件,它将在每个构建的APK上报告方法引用计数: https : //github.com/KeepSafe/dexcount-gradle-plugin 。