【问题标题】:How can I generate a lint-results.xml file when building my project in Android studio?在 Android Studio 中构建项目时如何生成 lint-results.xml 文件?
【发布时间】:2015-08-05 21:59:51
【问题描述】:

我想在 Android Studio 中构建我的项目时生成一个 lint-results.xml 文件。我需要能够这样做才能使用以下内容:https://github.com/KeepSafe/android-resource-remover

我也尝试从命令行构建项目,但出现以下错误:

FAILURE:构建失败并出现异常。

  • 出了什么问题: 在根项目“client-android”中找不到任务“lint”。一些候选者是:'init'。

  • 尝试: 运行 gradlew tasks 以获取可用任务的列表。使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。

这是我的 gradle 文件:

apply plugin: 'com.android.application'
apply plugin: 'robolectric'
apply plugin: 'idea'
apply plugin: 'bugsnag'

android {
packagingOptions {
    exclude 'LICENSE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE'
}

lintOptions {
    // set to true to turn off analysis progress reporting by lint
    quiet true
    // if true, stop the gradle build if errors are found
    abortOnError false
    // if true, only report errors
    ignoreWarnings true
}

compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.mango.android"
    minSdkVersion 14
    targetSdkVersion 21
    testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}

buildTypes {
    release {
        minifyEnabled false
        shrinkResources false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

sourceSets {
    androidTest {
        setRoot('src/test')
    }
}
}

 robolectric {
   include '**/*Test.class'
 }

dependencies {
     repositories {
         mavenCentral()
     }

compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.bugsnag:bugsnag-android:+'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:+'
compile files('libs/android-sqlite-asset-helper.jar')
compile('com.google.inject:guice:4.0-beta:no_aop') { exclude module: 'asm' }
compile('org.roboguice:roboguice:2.0') { exclude module: 'asm' }
compile 'com.github.nirhart:parallaxscroll:1.0' // For parallax views
androidTestCompile 'junit:junit:4.11'
androidTestCompile files('libs/android-sqlite-asset-helper.jar')
androidTestCompile('org.robolectric:robolectric:2.4') {
    exclude module: 'classworlds'
    exclude module: 'commons-logging'
    exclude module: 'httpclient'
    exclude module: 'maven-artifact'
    exclude module: 'maven-artifact-manager'
    exclude module: 'maven-error-diagnostics'
    exclude module: 'maven-model'
    exclude module: 'maven-project'
    exclude module: 'maven-settings'
    exclude module: 'plexus-container-default'
    exclude module: 'plexus-interpolation'
    exclude module: 'plexus-utils'
    exclude module: 'wagon-file'
    exclude module: 'wagon-http-lightweight'
    exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.google.android:android:4.1.1.4'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
compile 'com.google.android.gms:play-services:6.5.87'
}

idea {
     module {
        testOutputDir = file('build/test-classes')
    }
}

buildscript {
    repositories {
        mavenCentral()
    }
dependencies {
    classpath 'com.bugsnag:bugsnag-android-gradle-plugin:+'
}
}


// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
    jcenter()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.0.0'
    classpath 'org.robolectric:robolectric-gradle-plugin:0.14.0'
}
}

allprojects {
repositories {
    jcenter()
    mavenCentral()
}
}

【问题讨论】:

    标签: android xml android-gradle-plugin build.gradle


    【解决方案1】:

    这是在 Android Studio 1.3 中导出 Lint XML 的方法:

    1. 在顶部,点击“分析”
    2. 选择“检查代码”
    3. 点击确定。
    4. 检查面板应该会在底部打开(如果没有,您应该可以点击左下角的“检查”来打开它)。
    5. 从列表中选择“Android Lint”使其突出显示。
    6. 单击带有绿色向上箭头的图标(左下数第二个)以导出。
    7. 选择 XML 格式,然后选择要将结果保存到的文件夹。

    我不确定 Android Studio 是否一直包含 Lint,或者 Android Studio 是否在以后开始包含 Lint。您可能希望转到帮助 -> 关于以检查您正在运行的版本。如果您运行的是旧版本,请转到帮助 -> “检查更新”以更新 Android Studio。

    【讨论】:

    • 但是有没有办法从终端生成它?我想要一份未使用资源的 xml 报告。
    • 还没有完成,但是是的,您可以从终端生成 Lint XML。我认为您只需使用命令“Lint”+要检查的目录即可。在此处查看说明和示例:tools.android.com/tips/lint
    猜你喜欢
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多