【问题标题】:How to fix ERROR: No signature of method: build_754ga1wplg93aizkkd14wn52w.android()如何修复错误:没有方法签名:build_754ga1wplg93aizkkd14wn52w.android()
【发布时间】:2021-09-13 02:38:17
【问题描述】:

Gradle 同步失败:没有方法签名:build_754ga1wplg93aizkkd14wn52w.android() 适用于参数类型:(build_754ga1wplg93aizkkd14wn52w$_run_closure2) 值:[build_754ga1wplg93aizkkd14wn52w$_run_closure2@4657e4e8]

构建等级是:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '2'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0.2'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"


android {
    defaultConfig {
        minSdkVersion(15)
        targetSdkversion(29)
        multiDexEnabled = true
    }
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.flutter_blog"
        minSdkVersion 16
        compileSdkversion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
    buildToolsVersion '30.0.3'
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:28.1.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation("androidx.multidex:multidex:2.0.1")
    implementation 'com.google.android.material:material:1.4.0-rc01'
}

Android Studio 4.2.1 构建 #AI-202.7660.26.42.7351085,构建于 2021 年 5 月 10 日 运行时版本:11.0.8+10-b944.6842174 amd64 虚拟机:OpenJDK 64 位服务器虚拟机(不适用) 视窗 10 10.0 GC:G1年轻代,G1老年代 内存:1280M 核心数:12 注册表:external.system.auto.import.disabled=true 非捆绑插件:Dart、org.jetbrains.kotlin、io.flutter

【问题讨论】:

    标签: android flutter android-studio


    【解决方案1】:

    当您在 :app build gradle 中写入不必要的详细信息时,通常会发生此错误。

    您在android{ ... } 中添加了两个defaultconfig。您必须删除第一个 defaultConfig。

    这就是你的android{ ... } 现在的样子:

    android {
        defaultConfig {
            minSdkVersion(15)
            targetSdkversion(29)
            multiDexEnabled = true
        }
        compileSdkVersion 30
    
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.example.flutter_blog"
            minSdkVersion 16
            compileSdkversion 30
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
        }
    
        buildTypes {
            release {
                // TODO: Add your own signing config for the release build.
                // Signing with the debug keys for now, so `flutter run --release` works.
                signingConfig signingConfigs.debug
            }
        }
        buildToolsVersion '30.0.3'
    }
    

    相对于它的外观:

    android {
        
        compileSdkVersion 30
    
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.example.flutter_blog"
            minSdkVersion 16
            compileSdkversion 30
            multiDexEnabled true // Since you wanted to use multiDex this is where you put it
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
        }
    
        buildTypes {
            release {
                // TODO: Add your own signing config for the release build.
                // Signing with the debug keys for now, so `flutter run --release` works.
                signingConfig signingConfigs.debug
            }
        }
        buildToolsVersion '30.0.3'
    }
    
    

    同样在dependencies{} 中将implementation("androidx.multidex:multidex:2.0.1") 更改为implementation "androidx.multidex:multidex:2.0.1" 这应该可以解决您的问题。

    对于遇到此问题的其他人,请彻底检查您的 :app build gradle 是否存在不必要的缩进和错误的命名约定。

    【讨论】:

      猜你喜欢
      • 2020-08-31
      • 2022-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-31
      • 2019-08-08
      • 2015-07-20
      相关资源
      最近更新 更多