美文网首页
Android查看Apk方法总数

Android查看Apk方法总数

作者: Zach_C | 来源:发表于2016-08-19 10:01 被阅读546次

我们都知道Android应用的dex文件有64k方法数的限制,但具体怎么来查看我们现在的应用中到底有多少多少方法数了呢,常用的方法有两种:

1.<u> dexcount-gradle-plugin计算apk方法数</u>

2. <u>dex-method-count计算单个dex方法数</u>

方法1详细步骤访问dexcount-gradle-plugin

dexcount-plugin.png

方法2则使用
<u>printhex.ps1文件</u>

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

<u>dex-method-count.bat文件</u>

@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

将上面两个文件放到一个文件夹中,文件名和后缀都不变,然后把需要检测的dex文件也放在同一级目录,(dex文件通过打包的解压apk文件可以得到,如果压缩文件不识别apk文件,可以把apk文件改成zip或rar等文件再进行解压),使用命令行进入该目录,使用

dex-method-count classes.dex

就可以得到方法数。

dexcount.png methods.png

可知上面apk的方法数是49763。

相关文章

  • Android查看Apk方法总数

    我们都知道Android应用的dex文件有64k方法数的限制,但具体怎么来查看我们现在的应用中到底有多少多少方法数...

  • 查看 Apk方法方法总数

    参考:直接把apk导入,就可以查看apk的放法数http://inloop.github.io/apk-metho...

  • 查看apk签名信息和第三方应用的签名信息

    Android如何查看应用签名信息 介绍Android如何查看自己的应用签名及三方APK或系统APK签名信息,包含...

  • 如何查看Android App的方法总数

    大家都知道Android有65535方法数的问题,也就是说App的Java代码Method总数、Field总数都不...

  • Android APK签名原理及方法

    Android Apk签名原理及方法 来源:Android 开发中文站

  • 多渠道打包

    # android多渠道打包 # ## 1.如何查看apk的签名信息## 1将apk解压; 2.找到META-IN...

  • Android优化

    压缩APK文件 优化UI 内存优化 优化代码查看代码逻辑,提取通用代码设计模式 压缩APK文件 Android s...

  • 查看apk方法数

    Android开发中有对APK的方法数量做限制,不能超过65536.如果超过了该数目,会遇到如下异常: 之所以出现...

  • 使用Android Studio查看apk信息

    一、查看apk的方法 将apk文件直接拖到studio编辑窗口 切换到Project视图,并且双击APK文件 在菜...

  • APK打包流程

    1.APK文件内容 .apk文件是一个Android应用程序压缩包,可以将apk文件转换成.zip文件并解压查看,...

网友评论

      本文标题:Android查看Apk方法总数

      本文链接:https://www.haomeiwen.com/subject/zvkbsttx.html