android - 使用 tasks.getByName 找不到名称的任务

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

我想按任务顺序创建任务

task fabricUploadDebug(type: Exec) {
dependsOn 'clean'
dependsOn 'compileDebugSources'
dependsOn 'assembleDebug'
dependsOn 'installDebug'
dependsOn 'crashlyticsUploadDistributionDebug'
tasks.getByName('compileDebugSources').mustRunAfter('clean')
tasks.getByName('assembleDebug').mustRunAfter('compileDebugSources')
tasks.getByName('installDebug').mustRunAfter('assembleDebug')
tasks.getByName('crashlyticsUploadDistributionDebug').mustRunAfter('installDebug')}

我正在尝试从右侧面板“Gradle”运行任务,但错误是

Gradle sync failed: Task with name 'compileDebugSources' not found in project ':app'. // // Consult IDE log for more details (Help | Show Log) (2s 87ms) (moments ago)

这里是关于 https://stackoverflow.com/a/32909428/2425851

更新 我尝试输出我所拥有的所有任务:

 for(item in tasks){
        println "group= "+item.group+" ,path= "+item.path
    }

但我只有这个:为什么我无法访问其他任务?

group= build ,path= :app:assemble
group= build ,path= :app:assembleAndroidTest
group= build ,path= :app:buildDependents
group= build ,path= :app:buildNeeded
group= verification ,path= :app:check
group= build ,path= :app:cleanBuildCache
group= null ,path= :app:compileLint
group= verification ,path= :app:connectedCheck
group= null ,path= :app:consumeConfigAttr
group= verification ,path= :app:deviceCheck
group= null ,path= :app:extractProguardFiles
group= null ,path= :app:fabricUploadDebug
group= null ,path= :app:lint
group= null ,path= :app:preBuild
group= null ,path= :app:resolveConfigAttr
group= Android ,path= :app:sourceSets
group= Install ,path= :app:uninstallAll

enter image description here

最佳答案

这应该适合你:

task fabricUploadDebug(type: Exec), dependsOn : ['clean',
                                                 'compileDebugSources',
                                                 'assembleDebug',
                                                 'installDebug',
                                                 'crashlyticsUploadDistributionDebug'] {

    compileDebugSources.dependsOn clean
    assembleDebug.dependsOn compileDebugSources
    installDebug.dependsOn assembleDebug
    crashlyticsUploadDistributionDebug.dependsOn installDebug
}

关于android - 使用 tasks.getByName 找不到名称的任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48439464/

相关文章:

android - 试图让 Android jabber 应用程序检查新消息中的字符串并返回 toast 消息

android - 为属性 'inputFile' 指定的 app-debug-unaligned.apk 不存在

android - 如何在项目 gradle.properties 中设置 org.gradle.jvmargs=-Xmx5120M?

java - 时间广场日历app的实现方法

android - 如何将 RealmResults<Object> 转换为 List<Object>

android - Meteor Android 应用程序无法安装在 4.1.1 上

android - JavaFXPorts构建的apk自动删除

android-gradle-插件 1.2.2 : Flag ignoreFailures causes error in task connectedAndroidTest

build - 构建 AndEngine 示例的 NDK 时出错

android - 在 Android Studio 0.5.1 上导入 Facebook SDK