为什么 gradlew :app:dependencyInsight 失败?

lok*_*oki 9 android gradle gradlew build.gradle android-gradle-plugin

我尝试运行此命令以列出 firebase-messaging 库的所有依赖项:

gradlew :app:dependencyInsight --configuration compile --dependency firebase-messaging
Run Code Online (Sandbox Code Playgroud)

但它返回给我:

:app:dependencyInsight 在配置“:app:compile”中找不到与给定输入匹配的依赖项

BUILD SUCCESSFUL in 0s 1 个可操作的任务:1 个执行

这是我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.test.myapplication"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.google.firebase:firebase-messaging:12.0.1'
}
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

Jon*_*nik 9

在 Android 项目上使用dependencyInsightwithcompileClasspath效果很好(与接受的答案似乎声称不同)。您只需要在它前面加上完整的构建变体名称即可!

例如,如果您的项目仅使用构建类型,则使用debugCompileClasspathreleaseCompileClasspath作为配置参数。

如果还使用了产品风味,则表格为flavorDebugCompileClasspath(插入您自己的风味名称)。

我的项目中的一个工作示例(产品风味full,构建类型debug):

./gradlew app:dependencyInsight --configuration fullDebugCompileClasspath --dependency gson
Run Code Online (Sandbox Code Playgroud)


ToY*_*nos 5

那是因为firebase-messagingimplementation配置中声明了。compileClasspath 应该使用

尝试 :

gradlew :app:dependencyInsight --configuration compileClasspath --dependency firebase-messaging
Run Code Online (Sandbox Code Playgroud)

编辑:使用compileClasspath不适用于此处所述的 Android

使用gradle :app:dependencies来获取所有依赖项似乎是获取所有依赖项的更简洁的方法firebase-messaging