본문 바로가기
Flutter

Flutter 앱 배포 [Flutter 배포용 APK 생성]

by 보니스 2023. 9. 12.
반응형

Flutter 앱 배포 [Flutter 배포용 APK 생성]

 

(1) 키스토어 (KeyStore) 만들기

윈도우 안드로이드 스튜디오 Treminal 에서 {프로젝트 Home 디렉토리}에서 아래의 명령을 실행한다. 

 keytool -genkey -v -keystore c:/Users/bsh0484/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

-비번입력

-firstNm, lastNm 만 이력후 SKIP

-yes 하면 지정된 폴더에 key.jks 파일이 생성된다.

 

(2) key.jks .파일 프로젝트 폴더에 복사 및  key.properties 파일 생성

1) Android > app 폴더 아래에 key.jks 파일을 복사한다.

2) Android > app 폴더 아래에 key.properties 파일을 생성한다.   

storePassword=<키생성시 입력한 암호>
keyPassword=<키생성시 입력한 암호>
keyAlias=key
storeFile=./key.jks
주의: 윈도우 탐색창에서 생성한 경우 key.properties.txt 파일로 생성 될 수 있다.
         반드시 key.properties 파일로 생성 하도록 하자.

 

(3) build.gradle 파일 수정

1) Android > app 폴더 아래에 있는 build.gradle 파일을 수정한다.

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('app/key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

 

(4) build

윈도우 안드로이드 스튜디오 Treminal 에서 {프로젝트 Home 디렉토리}에서 아래의 명령을 실행한다. 

flutter build apk --release --target-platform=android-arm64

 

build 실행 결과