[Flutter] 배포용 APK 빌드

Noah·2024년 3월 23일
0

Flutter

목록 보기
3/11

1. 런처 아이콘 생성

2. 앱 서명하기

  • 업로드 키 생성
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

3. keystore 참조하기

  • 배포용 앱을 빌드할 때 참조하기 위해 프로젝트의 android/key.properties 파일을 생성한 후 다음과 같이 작성한다.
storePassword=<키생성시 입력한 암호>
keyPassword=<키생성시 입력한 암호>
keyAlias=key
storeFile=key.jks

4. Gradle에서 서명 구성하기

  • Gradle 빌드시 key.properties 파일을 참조하도록 android 블럭 상단에 아래의 내용을 추가한다.
// start of Gradle 서명 구성
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
// end of Gradle 서명 구성

android {
...
}

5. Proguard 사용

  • Proguard는 배포할 앱의 소스코드를 난독화하는 설정이다. APK 파일의 크기를 줄이고 코드를 디컴파일하여도 소스코드의 내용을 이해할 수 없도록 난독화할 수 있다.

  • Proguard Rule을 구성하기 위해 android/app/proguard-rules.pro 파일을 생성하고 다음과 규칙을 추가한다.

## Flutter wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-dontwarn io.flutter.embedding.**
  • Gradle 빌드시 proguard-rules.pro 파일을 참조하여 코드 난독화와 사이즈를 축소할 수 있도록 /android/app/build.gradle 파일의 buildTypes 블럭안에 다음의 내용을 추가한다.
android {
    ...
    
    buildTypes {
        release {
            // release 속성으로 변경
            signingConfig signingConfigs.release

			// start of 코드난독화 및 사이즈 축소
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            // end of 코드난독화 및 사이즈 축소
        }
    }
}

6. 앱 번들 빌드

flutter build appbundle

7. APK 빌드

flutter build apk --split-per-abi

참고
https://here4you.tistory.com/198

profile
Flutter Specialist

0개의 댓글