一、工具介绍

Infer 是 Facebook 开源的静态程序分析工具,用于在发布移动应用之前对代码进行分析,找出潜在的问题。目前 Facebook 使用该工具来分析 Facebook 的 App,包括 Android 、iOS、Facebook Messenger 和 Instagram 等等。

Facebook 称该工具帮助其每个月检查出数百个应用中潜在的 Bug,例如一些空指针访问、资源和内存泄漏等等。支持 Android 的 Java 和 iOS 的 C 和 Objective-C 代码。

Infer官网地址

二、安装

关于Infer的安装可以参考:https://github.com/facebook/infer/blob/master/INSTALL.md#install-infer-from-source

对于华为内部进行使用的情况来看,一般在linux机器上使用

要求环境如下:

opam >= 2.0.0
pkg-config
Java (only needed for the Java analysis)
gcc >= 5.X or clang >= 3.4 (only needed for the C/Objective-C analysis)
autoconf >= 2.63 and automake >= 1.11.1 (if building from git)
CMake (only needed for the C/Objective-C analysis)
Ninja (optional, if you wish to use sequential linking when building the C/Objective-C analysis)
See also the distro-specific instructions for Ubuntu and Debian below.

先找到一台合适的linux机器,从https://github.com/facebook/infer下载源文件。

# Checkout Infer
git clone https://github.com/facebook/infer.git
cd infer
# Compile Infer
./build-infer.sh java
# install Infer system-wide...
sudo make install
# ...or, alternatively, install Infer into your PATH
export PATH=`pwd`/infer/bin:$PATH

执行如上步骤后,通过

infer

查看infer是否安装成功
可能会报如下错误:

/lib64/libm.so.6: version `GLIBC_2.23`not found

那么此时可以参考此链接
注!!!: 更改libm.so.6的版本需要变更linux库文件,请小心操作,否则linux机器变砖,建议先找台没重要东西的机器试试。

执行完上述步骤后,运行下infer,出现如下字样,说明安装成功了

[xxxx@xxxxx xxxxxxx]# infer
Nothing to compile. Have you run `infer capture`? Try cleaning the build first.
There was nothing to analyze.

  No issues found

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐