android代码分析,及Terminal使用

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值