firebaseAppDistribution - 没有方法签名:build.android() 适用于参数类型:(build_run_closure1) 值:[build_run_closure1@x

firebaseAppDistribution - No signature of method: build.android() is applicable for argument types: (build_run_closure1) values: [build_run_closure1@x

我有一个电容器应用程序,我正在尝试使用 Gradle (https://firebase.google.com/docs/app-distribution/android/distribute-gradle?authuser=1&apptype=aab) 实现 Firebase Distribution,但我遇到了这个错误:

No signature of method: build_clqfykx9rkn9m9ygw4eh6w1bu.android() is applicable for argument types: (build_clqfykx9rkn9m9ygw4eh6w1bu$_run_closure1) values: [build_clqfykx9rkn9m9ygw4eh6w1bu$_run_closure1@60526ded]

我已经完成了该过程的所有步骤,我的 build.gradle 文件如下所示:

build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath 'com.google.gms:google-services:4.3.5'

        // Add the App Distribution Gradle plugin
        classpath 'com.google.firebase:firebase-appdistribution-gradle:2.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

apply from: "variables.gradle"

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app/build.gradle:

apply plugin: 'com.android.application'

// Apply the App Distribution Gradle plugin
apply plugin: 'com.google.firebase.appdistribution'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    defaultConfig {
        applicationId "com.some.app"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName project.hasProperty('version') ? version : '1.0.0'
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        aaptOptions {
             // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
             // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
            ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
        }
    }
    flavorDimensions "environment"
    productFlavors {
        appA {
            dimension "environment"
            manifestPlaceholders = [displayName:"App A"]
        }
        appB {
            dimension "environment"
            applicationIdSuffix ".amigdala"
            manifestPlaceholders = [displayName:"App B"]
        }
    }
    signingConfigs {
        release {
            storeFile file("app-keystore.jks")
            storePassword System.getenv("KSTOREPWD")
            keyAlias "mykey"
            keyPassword System.getenv("KEYPWD")
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            // https://firebase.google.com/docs/app-distribution/android/distribute-gradle?authuser=1&apptype=aab
            firebaseAppDistribution {
                serviceCredentialsFile "./service-account-key-distribution.json"
                artifactType "AAB"
                archivePath System.getenv("ARCHIVE_PATH")
                releaseNotes "Change this before releasing in production!"
            }
        }
    }
}

repositories {
    flatDir{
        dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    implementation project(':capacitor-android')
    testImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
    implementation project(':capacitor-cordova-android-plugins')
}

apply from: 'capacitor.build.gradle'

try {
    def servicesJSON = file('google-services.json')
    if (servicesJSON.text) {
        apply plugin: 'com.google.gms.google-services'
    }
} catch(Exception e) {
    logger.warn("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}

当然,在我添加这部分之前一切正常:

 // https://firebase.google.com/docs/app-distribution/android/distribute-gradle?authuser=1&apptype=aab
            firebaseAppDistribution {
                serviceCredentialsFile "./service-account-key-distribution.json"
                artifactType "AAB"
                archivePath System.getenv("ARCHIVE_PATH")
                releaseNotes "Change this before releasing in production!"
            }

我在修改 build.gradle 文件方面还很陌生,所以我猜这与语法有关,但我无法弄明白。即使我做了像 artifactType "AAB" -> artifactType="AAB" 这样的小改动,我也会从这个错误跳到这个错误:Task 'appDistributionUploadRelease' not found in root project 'android'.

任何帮助或线索将不胜感激,谢谢。

方法没有签名:build.android...当您的 Gradle 配置有问题时会出现接缝,例如 firebaseAppDistribution 属性 中缺少属性或文件路径错误。一旦我解决了我的任务 'appDistributionUploadRelease' not found in root project 'android' 问题,我解决了(纯靠运气)更改 appDistributionUploadAppARelease 的 appDistributionUploadRelease 命令。该任务似乎没有通用命令,必须指定风格。