[Flutter 오류 모음] No signature of method: build *.android() is applicable for argument types: 해결법

몽상가·2022년 9월 25일
1

Flutter Error Collector

목록 보기
4/5
post-thumbnail

🌱 오늘 만난 문제아

No signature of method: build *.android() is applicable for argument types:

바로 이 고얀 녀석이다.
사실 오늘 만난 문제아는 아니고,
며칠 됐다..

iOS에서는 잘 돌아가는데 안드로이드 에뮬레이터로 돌리면
빌드가 되지 않아서 너무 답답했다.

아무리 구글링을 하고
스택 오버 플로우를 뒤져봐도
그렇다할 해결방법을 제시해주지 않아서
코드도 다시 짜보고 별 짓 다해보다가
간단한(?) 해결 방법을 찾아냈다.

👊 바로 해결 START

우선 내 문제는,
SDK 버전과 API, build.gradle 버전을 맞춰주지 않아서 생긴 문제였다.

나는 Android SDK 버전 33, API 33, build-gradle 7.5.1 버전이 필요했다.
나와 같은 문제를 겪는 분들은 먼저 본인의 프로젝트에 필요한 각각의 버전을 체크하기 바란다!

아래 flutter doctor는 버전을 맞춘 후 실행한 것이다.

  1. flutter doctor -v 로 현재 프로젝트 버전 확인
[✓] Flutter (Channel master, 3.4.0-19.0.pre.137, on macOS 12.6 21G115 darwin-arm64, locale ko-KR)
    • Flutter version 3.4.0-19.0.pre.137 on channel master at /Users/hibin/Desktop/YB/Coding/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 91e9c62472 (2 weeks ago), 2022-09-07 23:59:26 -0400
    • Engine revision 4096e133ef
    • Dart version 2.19.0 (build 2.19.0-177.0.dev)
    • DevTools version 2.17.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/hibin/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A309
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.70.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (4 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554             • android-arm64  • Android 13 (API 33) (emulator)
    • 하이빈 (mobile)                • 00008110-00022DD83EE1801E • ios            • iOS 16.0 20A362
    • macOS (desktop)             • macos                     • darwin-arm64   • macOS 12.6 21G115 darwin-arm64
    • Chrome (web)                • chrome                    • web-javascript • Google Chrome 105.0.5195.125

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
  1. 필요한 버전의 SDK 설치

설치가 안 되어 있다면 원하는 SDK 버전을 체크해주면 이름 옆에 설치 아이콘이 뜬다.

File -> Project Structure 에서 Edit 클릭

Build target 선택(API 33)

  1. Device Manager 에서 API 33 버전의 Virtual Device 생성

  1. gradle-wrapper.properties 확인

나에게 필요한 gradle 버전은 7.5.1 이니까
distributionURL 끝에 gradle-7.5.1-bin.zip 입력

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
  1. app/build.gradle

app -> build.gradle이다! (android level 아님)

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 = '1'
}

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

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


android {
    compileSdkVersion 33
    buildToolsVersion "33"
    ndkVersion flutter.ndkVersion


    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    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.my.bccs"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion 21
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    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
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "androidx.multidex:multidex:$multidex_version"
    implementation platform('com.google.firebase:firebase-bom:30.2.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-messaging'

}
android {
    compileSdkVersion 33
    buildToolsVersion "33"
    
    defaultConfig { 
    	minSdkVersion 21
    	targetSdkVersion 33

이부분을 주의해서 적어줘야 한다!! (버전 맞추는게 핵심)

  1. android/build.gradle

classpath 'com.android.tools.build:gradle:7.2.2'
이 부분을 7.5.1 로 하면 빌드가 안 된다. 왜 그런지는 모르겠다..!
(아시는 분 댓글 부탁드려요!!)

buildscript {
    ext.kotlin_version = '1.7.10'
    ext.multidex_version = '2.0.1'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.android.tools.build:gradle:7.2.2'
        classpath 'com.google.gms:google-services:4.3.14'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

🎉 빌드 성공~

모두의 Build Successful을 응원합니다.

profile
늘 꿈꾸는 사람

2개의 댓글

comment-user-thumbnail
2023년 3월 16일

몽상가님~ "Android SDK 버전 33, API 33, build-gradle 7.5.1 버전이 필요" 라고 하셨는데, 저의 SDK 버전에 필요한 build.gradle 버전을 알려면 어디서 알아볼수 있나요?

1개의 답글