[Flutter]
편하게 minSdkVersion, targetSdkVersion 관리하는 방법
(How to easily manage minSdkVersion and targetSdkVersion)
기존의 flutter 자동 생성 변수 (Existing flutter auto-generated variables)
flutter 프로젝트를 생성하면
IDE에서 자체적으로 초기화해주면서 flutterTargetSdkVersion, flutterMinSdkVersion 등의
자체 변수를 관리하며 build.gradle에서 빌드를 진행하게 만든다.
이는 편리해보이지만
개발자가 sdk버전 등을 관리할 때 꽤나 불편하게 만드는 요소 중 하나다.
(When you create a flutter project
The IDE initializes itself, flutterTargetSdkVersion, flutterMinSdkVersion, etc.
It manages its own variables and makes the build progress in build.gradle.
This seems convenient, but This is one of the factors that makes it quite inconvenient for developers when managing SDK versions, etc.)
개발자가 쉽게 관리하는 방법은 아래와 같다.
1. android/app/build.gradle 수정 : 최초에만 해주면 OK (Edit android/app/build.gradle: OK if you do it only the first time)
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterCompileSdkVersion = localProperties.getProperty('flutter.flutterCompileSdkVersion')
if (flutterCompileSdkVersion == null) {
flutterCompileSdkVersion = '33'
}
def flutterMinSdkVersion = localProperties.getProperty('flutter.flutterMinSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = '21'
}
def flutterTargetSdkVersion = localProperties.getProperty('flutter.flutterTargetSdkVersion')
if (flutterTargetSdkVersion == null) {
flutterTargetSdkVersion = '33'
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0.0'
}
위처럼 각종 sdk버전, 이름, 코드를 사용하도록 수정하고,
defaultConfig 내에서 접근하도록 한다.
(Modify it to use various SDK versions, names, and codes as above, Access it within defaultConfig.)
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.studioodoc.easy_welfare_membership"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutterMinSdkVersion.toInteger()
targetSdkVersion flutterTargetSdkVersion.toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
2. android/local.properties만 수정하여 관리 편의성 증대 (Increased management convenience by modifying only android/local.properties)
이제부턴 아래와 같이 local.properties만 관리하면
관련 코드들이 이 값에 맞추어 변하기 때문에 매우 편리해진다.
(From now on, you only need to manage local.properties as shown below.
This becomes very convenient because the related codes change according to this value.)
. . .
flutter.buildMode=debug
flutter.versionName=0.1.0
flutter.flutterCompileSdkVersion=33
flutter.flutterMinSdkVersion=21
flutter.flutterTargetSdkVersion=33