Android代码分析日志

Android Studio有个Terminal工具。

首先确保app/build.gradle中没有如下配置:

android {
lintOptions {
abortOnError false
}
}

在Terminal命令框内输入:gradlew build

会提示如下错误:

Ran lint on variant debug: 695 issues found
Ran lint on variant release: 695 issues found
Wrote HTML report to file:/D:/Android%20Studio%20Workspace/InvoicingSys/app/build/outputs/lint-results.html
Wrote XML report to D:\Android Studio Workspace\InvoicingSys\app\build\outputs\lint-results.xml
:app:lint FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}

...

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 24.38 secs


这时候就可以发现分析日志在:D:\Android Studio Workspace\InvoicingSys\app\build\outputs\目录下的两个文件。

这里面将会列出:所有存在warning的代码,未被用到的声明、资源文件,不合理的布局等。


Terminal的使用

开发工具当然是Android Studio.

1、在Terminal命令框内输入 gradlew -v

如果是初次使用该命令会提示下载gradle,然后显示无数个省略号,直到下载、解压完成。会出现如下结果:

------------------------------------------------------------
Gradle 2.4
------------------------------------------------------------


Build time: 2015-05-05 08:09:24 UTC
Build number: none
Revision: 5c9c3bc20ca1c281ac7972643f1e2d190f2c943c


Groovy: 2.3.10
Ant: Apache Ant(TM) version 1.9.4 compiled on April 29 2014
JVM: 1.7.0_75 (Oracle Corporation 24.75-b04)
OS: Windows 7 6.1 amd64

说明安装成功。

2、然后,执行gradlew clean

同样如果是第一次执行该命令,也会下载一些依赖包。等下载完成后,会出现如下结果:

:clean
:app:clean

BUILD SUCCESSFUL

Total time: 11.925 secs

说明清理build文件成功。

3、然后,用gradlew命令打包

执行命令:gradlew build

如果app/build.gradle中没有配置了:

android {
lintOptions {
abortOnError false
}
}

那么会出现打包失败:

Wrote HTML report to file:/D:/Android%20Studio%20Workspace/InvoicingSys/app/build/outputs/lint-results.html
Wrote XML report to D:\Android Studio Workspace\InvoicingSys\app\build\outputs\lint-results.xml
:app:lint FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}

...

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

但是,可以生成代码分析日志。可以帮助我们提高代码质量。

那么,如果想打包成功则需要如下配置:

android {
lintOptions {
abortOnError false//忽略lint警告,否则会打包失败
}

signingConfigs {
release {
storeFile file("xxxxx")//app是其根目录
storePassword "xxxxx"
keyAlias "xxxx"
keyPassword "xxxx"
}
}

buildTypes {
release {
signingConfig signingConfigs.release//如果不使用此签名,打出的包是未签名的。
minifyEnabled true//可以不混淆。混淆可以使apk文件变小。
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}


另外gradlew还有那些命令呢?

gradlew installRelease 打发布包,并安装到设备。

gradlew -h 显示常规命令列表。有些命令没有在其列表中列出。


更多相关文章

  1. android- activity,Application,activity渲染xml文件
  2. Android 文件操作大全
  3. Android常用命令总结
  4. android中加载assets中的资源文件
  5. [导入]Android代码优化

随机推荐

  1. Android学习——手把手教你实现Android热
  2. android fragment和activity的区别
  3. android中padding和 margin区别
  4. Android小项目--2048小游戏
  5. 四则运算第一次冲刺
  6. Android Studio 4.1 发布,全方位提升开发
  7. Android(安卓)Studio 改变app启动页面
  8. 3.NDK Android jni开发 C语言中打印log d
  9. android 使用 SQLiteOpenHelper 实现对SQ
  10. 解决android webkit的css postion:fixed