Flutter build.gradle compileSdkVersion 환경변수 설정

Flutter build.gradle compileSdkVersion 환경변수 설정

카테고리
Flutter
작성자
상태
완료
최하위 정렬
작성일
Mar 10, 2025 01:37 PM
설명
build.gradle 환경변수 설정
태그
💡
아래와 같은 경고가 출력된다.
One or more plugins require a higher Android SDK version. Fix this issue by adding the following to C:\Users\devshow\Documents\projects\flutter\flutter_application_1\android\app\build.gradle: android { compileSdkVersion 34 ... }
 
build.gradle 파일에 보면 flutter.compileSdkVersion 이름의 환경변수로로 설정되어 있다.
android { namespace "com.example.flutter_application_1" compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion
 
이 환경변수는 플러터를 설치한 폴더에서 확인할 수 있다.
나는 D드라이브에 설치했기에 경로는 아래와 같다.
D:\flutter\packages\flutter_tools\gradle
notion image
 
여기서 설정값을 변경해도 되지만 프로젝트마다 환경이 달라질 수 있으므로 작업중인 프로젝트에서 수정하도록 하자.
notion image
 
project > android > app > build.gradle에 들어가보면 예시가 잘 나와있다.
notion image
 
기존 내용을 참고해 아래와 같이 더 추가해줬다.
def flutterCompileSdkVersion = localProperties.getProperty('flutter.compileSdkVersion') if (flutterCompileSdkVersion == null) { flutterCompileSdkVersion = '34' } def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion') if (flutterMinSdkVersion == null) { flutterMinSdkVersion = '29' } def flutterTargetSdkVersion = localProperties.getProperty('flutter.targetSdkVersion') if (flutterTargetSdkVersion == null) { flutterTargetSdkVersion = '34' }
 
추가한 변수를 아래와 같이 사용했다.
android { compileSdkVersion flutterCompileSdkVersion ... 생략 ... defaultConfig { minSdkVersion flutterMinSdkVersion targetSdkVersion flutterTargetSdkVersion ... 생략 ...
 
project > android > local.properties 에 변수를 추가해보자
추가하지 않는다면 위에서 설정한 기본값으로 적용된다.
sdk.dir=C:\\Users\\user\\AppData\\Local\\Android\\sdk flutter.sdk=D:\\flutter flutter.buildMode=debug flutter.versionName=1.0.0 flutter.versionCode=1 flutter.compileSdkVersion=34 flutter.minSdkVersion=29 flutter.targetSdkVersion=34
 
실행하니 아래와 같이 오류가 발생되었다.
FAILURE: Build failed with an exception. * Where: Build file 'C:\.....\flutter_application_1\android\app\build.gradle' line: 43 * What went wrong: A problem occurred evaluating project ':app'. > Unsupported value: 34. Format must be one of: - android-31 - android-31-ext2 - android-T - vendorName:addonName:31 * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org
 
문자열로 할당되어 문제가 생겼다.
아래와 같이 변경하고 다시 실행하니 이제 정상이다.
compileSdkVersion flutterCompileSdkVersion.toInteger() minSdkVersion flutterMinSdkVersion.toInteger() targetSdkVersion flutterTargetSdkVersion.toInteger()