怎么查看APK的方法数

网上找的一个脚本,电脑系统为windows 亲测 好用。
将下面两个文件printhex.ps1、dex-method-count.bat拷贝到一个文件夹下,文件名字和后缀都不要变,然后将需要检测的classes.dex文件也放在这个文件夹下

打开命令行并切到当前目录下,运行命令

dex-method-count.bat classes.dex

会输出结果
Counting methods in DEX file classes.dex
Number of methods is 63952

方法数没有超过65535个就可以啦,不然就要分包了

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()

dex-method-count.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

如果是计算一个开源库的方法数,可以访问下面这个网站
http://www.methodscount.com/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值