728x90

MAC에서 flutter로 앱을 개발하기 위해서 셋팅하는 과정을 정리함.
일단 flutter를 설치하고 나면 flutter doctor 명령으로 추가적인 필요 사항을 체크할 수 있음.
크게 android studio, xcode, cocoapods를 추가로 설치하면 되는데, 중간중간 삽질이 필요함.

  1. flutter 설치
    1. 다운로드 및 설치
    2. SDK PATH 설정 (shell에 따라 구분)
  2. android Studio 설치
  3. Xcode 설치
  4. cocoapods 설치

1. flutter 설치

  1) 다운로드 및 설치
- flutter 사이트에서 (https://docs.flutter.dev/get-started/install) macOs용으로 다운로드 받음.
- MAC 프로세서에 따라 설치 가능한 버전을 다운로드함. (
Intel Processor or Apple Silicon )
- 다운 받은 압축 파일을 ~/development/ 폴더에 압축 해제하면 되는데, development 폴더 없으면 새로 생성하면 됨.

unzip ~/Downloads/flutter_macos_arm64_3.29.0-stable.zip \ -d ~/development/

또는
mkdir ~/development
cp flutter_macos_arm64_3.29.0-stable.zip ~/development/
unzip ~/development/flutter_macos_arm64_3.29.0-stable.zip

- 이렇게 하면, flutter/Dart의 SDK가 설치 완료되고, 아래의 두 패스를 사용하게 됨.

flutter SDK 패스 : /Users/유저명/development/flutter/bin
Dart SDK 패스 : /Users/유저명/development/flutter/bin/cache/dart-sdk (이건 android-studio에서 사용할 예정)

 

   2) PATH 설정 (shell에 따라 구분)

- 터미널에서 flutter 명령어를 바로 사용할 수 없기 때문에 PATH를 추가해야 함.

- 어떤 shell을 사용하는지에 따라 구분됨.

echo $SHELL   // 쉘 확인

// (1) zsh 쉘이면
vim ~/.zshrc   

    #Flutter PATH 설정 추가
    export PATH="플러터폴더경로/bin:$PATH"

source ~/.zshrc

// (2) bash 쉘이면 .zshrc 대신 .bash_profile 편집하고 적용

- 만약, 쉘이 꼬여서 해당 파일이 없는 경우에는 아래의 방법으로 쉘을 초기화하여 새로 생성하고, flutter 패스 입력함.

touch ~/.zshrc		// .zshrc 파일 생성
echo "export PATH=$PATH" > ~/.zshrc		// PATH 내용 초기화
source ~/.zshrc		// 서버에 적용

- flutter PATH 설정 후 버전 확인

- flutter doctor로 추가로 필요한 목록 확인
- android studio, xcode 설치 필요.



2. android Studio 설치

- https://developer.android.com/studio?hl=ko 에서 MAC용 android Studio 다운로드하여 설치

- android Studio 열어서 Dart, Flutter 패키지 설치.

- android Studio를 설치하였으나 licenses에 동의가 필요함.

flutter doctor --android-licenses

- adroid studio 설정에서 SDK Tools 중 Android SDK Command-line Tools 설치.

- android studio 설치 완료.

 


3. Xcode 설치

- https://developer.apple.com/download/all/  애플 사이트에서 xcode를 설치해야 함.
- MAC 프로세서와 버전에 따라 설치할 수 있는 xcode 버전이 있으므로 주의하여 찾아서 설치함 ( https://developer.apple.com/support/xcode/ )


4. cocoapods 설치

- Xcode를 설치하고서 cocoapods를 추가로 설치해야 함.

- homebrew가 설치되어 있지 않아, 오류 발생
- https://brew.sh/ko/ 사이트에서 설치함

- 여기까지 설치하면 flutter를 실행할 수 있는 준비가 완료됨.

 

[참고] https://docs.flutter.dev/get-started/install/macos/desktop#configure-xcode

[참고] https://wildeveloperetrain.tistory.com/358

[참고] https://semin1127.tistory.com/entry/MACFlutter-%ED%94%8C%EB%9F%AC%ED%84%B0-%EC%B4%88%EA%B8%B0-%EA%B0%9C%EB%B0%9C-%ED%99%98%EA%B2%BD-%EA%B5%AC%EC%B6%95-%EB%B0%A9%EB%B2%95

반응형
728x90

flutter 학습을 위해 기록함.
앱을 시작할때 첫 화면, 즉 스플래시를 만들기 위해 flutter_native_splash 패키지를 사용함.

1) 패키지 설치

 

 flutter pub add flutter_native_splash

2) 환경설정 파일 생성
루트 프로젝트 디렉토리에 flutter_native_splash.yaml 파일 생성하여, 아래 내용을 추가함.
- color 값과 image 경로를 원하는대로 설정

flutter_native_splash:
  # This package generates native code to customize Flutter's default white native splash screen
  # with background color and splash image.
  # Customize the parameters below, and run the following command in the terminal:
  # dart run flutter_native_splash:create
  # To restore Flutter's default white splash screen, run the following command in the terminal:
  # dart run flutter_native_splash:remove

  # IMPORTANT NOTE: These parameter do not affect the configuration of Android 12 and later, which
  # handle splash screens differently that prior versions of Android.  Android 12 and later must be
  # configured specifically in the android_12 section below.

  # color or background_image is the only required parameter.  Use color to set the background
  # of your splash screen to a solid color.  Use background_image to set the background of your
  # splash screen to a png image.  This is useful for gradients. The image will be stretch to the
  # size of the app. Only one parameter can be used, color and background_image cannot both be set.
  color: "#42a5f5" // 배경색깔
  #background_image: "assets/background.png"

  # Optional parameters are listed below.  To enable a parameter, uncomment the line by removing
  # the leading # character.

  # The image parameter allows you to specify an image used in the splash screen.  It must be a
  # png file and should be sized for 4x pixel density.
  image: assets/img/splash_768.png   // 스플래시 이미지를 사용할 경우, 주석 풀고 이미지 경로

  # The branding property allows you to specify an image used as branding in the splash screen.
  # It must be a png file. It is supported for Android, iOS and the Web.  For Android 12,
  # see the Android 12 section below.
  #branding: assets/dart.png

  # To position the branding image at the bottom of the screen you can use bottom, bottomRight,
  # and bottomLeft. The default values is bottom if not specified or specified something else.
  #branding_mode: bottom
  
  # Set the branding padding from the bottom of the screen.  The default value is 0
  # (Not supported on web yet)
  # branding_bottom_padding: 24

  # The color_dark, background_image_dark, image_dark, branding_dark are parameters that set the background
  # and image when the device is in dark mode. If they are not specified, the app will use the
  # parameters from above.  If there is no parameter above, the app will use the light mode values.
  # If the image_dark parameter is specified, color_dark or background_image_dark must be specified.  
  # color_dark and background_image_dark cannot both be set.
  #color_dark: "#042a49"
  #background_image_dark: "assets/dark-background.png"
  #image_dark: assets/splash-invert.png
  #branding_dark: assets/dart_dark.png

  # From Android 12 onwards, the splash screen is handled differently than in previous versions.
  # Please visit https://developer.android.com/guide/topics/ui/splash-screen
  # Following are specific parameters for Android 12+.
  android_12:
    # The image parameter sets the splash screen icon image.  If this parameter is not specified,
    # the app's launcher icon will be used instead.
    # Please note that the splash screen will be clipped to a circle on the center of the screen.
    # App icon with an icon background: This should be 960×960 pixels, and fit within a circle
    # 640 pixels in diameter.
    # App icon without an icon background: This should be 1152×1152 pixels, and fit within a circle
    # 768 pixels in diameter.  To fit a 1152x1152 image within a circle with a 768 diameter, simply 
    # ensure that the most important design elements of your image are placed within a circular area
    # with a 768 diameter at the center of the 1152x1152 canvas.
    image: assets/img/splash_1152.png  // 스플래시 이미지를 사용할 경우, 주석 풀고 이미지 경로

    # Splash screen background color.
    color: "#42a5f5" // 배경색깔

    # App icon background color.
    #icon_background_color: "#111111"

    # The branding property allows you to specify an image used as branding in the splash screen.
    #branding: assets/dart.png

    # The image_dark, color_dark, icon_background_color_dark, and branding_dark set values that
    # apply when the device is in dark mode. If they are not specified, the app will use the
    # parameters from above.  If there is no parameter above, the app will use the light mode values.
    #image_dark: assets/android12splash-invert.png
    #color_dark: "#042a49"
    #icon_background_color_dark: "#eeeeee"

  # The android, ios and web parameters can be used to disable generating a splash screen on a given
  # platform.
  #android: false
  #ios: false
  #web: false

  # Platform specific images can be specified with the following parameters, which will override
  # the respective parameter.  You may specify all, selected, or none of these parameters:
  #color_android: "#42a5f5"
  #color_dark_android: "#042a49"
  #color_ios: "#42a5f5"
  #color_dark_ios: "#042a49"
  #color_web: "#42a5f5"
  #color_dark_web: "#042a49"
  #image_android: assets/splash-android.png
  #image_dark_android: assets/splash-invert-android.png
  #image_ios: assets/splash-ios.png
  #image_dark_ios: assets/splash-invert-ios.png
  #image_web: assets/splash-web.gif
  #image_dark_web: assets/splash-invert-web.gif
  #background_image_android: "assets/background-android.png"
  #background_image_dark_android: "assets/dark-background-android.png"
  #background_image_ios: "assets/background-ios.png"
  #background_image_dark_ios: "assets/dark-background-ios.png"
  #background_image_web: "assets/background-web.png"
  #background_image_dark_web: "assets/dark-background-web.png"
  #branding_android: assets/brand-android.png
  #branding_bottom_padding_android: 24
  #branding_dark_android: assets/dart_dark-android.png
  #branding_ios: assets/brand-ios.png
  #branding_bottom_padding_ios: 24
  #branding_dark_ios: assets/dart_dark-ios.png
  #branding_web: assets/brand-web.gif
  #branding_dark_web: assets/dart_dark-web.gif

  # The position of the splash image can be set with android_gravity, ios_content_mode, and
  # web_image_mode parameters.  All default to center.
  #
  # android_gravity can be one of the following Android Gravity (see
  # https://developer.android.com/reference/android/view/Gravity): bottom, center,
  # center_horizontal, center_vertical, clip_horizontal, clip_vertical, end, fill, fill_horizontal,
  # fill_vertical, left, right, start, or top. android_gravity can be combined using the | operator to achieve multiple effects. 
  # For example:
  # `android_gravity: fill|clip_vertical` - This will fill the width while maintaining the image's vertical aspect ratio
  #android_gravity: center
  #
  # ios_content_mode can be one of the following iOS UIView.ContentMode (see
  # https://developer.apple.com/documentation/uikit/uiview/contentmode): scaleToFill,
  # scaleAspectFit, scaleAspectFill, center, top, bottom, left, right, topLeft, topRight,
  # bottomLeft, or bottomRight.
  #ios_content_mode: center
  #
  # web_image_mode can be one of the following modes: center, contain, stretch, and cover.
  #web_image_mode: center

  # The screen orientation can be set in Android with the android_screen_orientation parameter.
  # Valid parameters can be found here:
  # https://developer.android.com/guide/topics/manifest/activity-element#screen
  #android_screen_orientation: sensorLandscape

  # To hide the notification bar, use the fullscreen parameter.  Has no effect in web since web
  # has no notification bar.  Defaults to false.
  # NOTE: Unlike Android, iOS will not automatically show the notification bar when the app loads.
  #       To show the notification bar, add the following code to your Flutter app:
  #       WidgetsFlutterBinding.ensureInitialized();
  #       SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top], );
  #fullscreen: true

  # If you have changed the name(s) of your info.plist file(s), you can specify the filename(s)
  # with the info_plist_files parameter.  Remove only the # characters in the three lines below,
  # do not remove any spaces:
  #info_plist_files:
  #  - 'ios/Runner/Info-Debug.plist'
  #  - 'ios/Runner/Info-Release.plist'

3) 패키지를 실행

dart run flutter_native_splash:create

* 단, 파일명이 기본 flutter_native_splash.yaml이 아니면, 아래와 같이 파일명으로 패키지를 실행

dart run flutter_native_splash:create --path=path/my/myfile.yaml

 

*참조 : [공식]https://pub.dev/packages/flutter_native_splash

반응형
728x90

flutter로 개발된 앱일 경우 apk 파일을 추출하여
안드로이드 폰에 직접 설치하고, 테스트를 진행하기 위해 apk 파일을 추출함.

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

...
√ Built build\app\outputs\flutter-apk\app-release.apk (*.*MB)

프로젝트 폴더로 이동 후에 해당 명령어를 실행하면
해당 폴더 아래에 build\app\outputs\flutter-apk 폴더가 생성되고 apk 파일이 저장됨.

[참조] https://blog.dglee.co.kr/37


테스트를 완료하고 안드로이드 앱을 구글 플레이스토어에 올려서 배포하기 위해서는 다른 형식의 파일이 필요함
aab 파일을 생성해야 함.

반응형
728x90

flutter 학습을 위해 기록함.
안드로이드 앱에서 restful API를 연동하여 데이터 값을 처리하기 위해 필요한 AES-256 암호화 및 복호화 코드


1) flutter 패키지 encrypt 설치

pub global activate encrypt

2) 코드 작성

import 'package:encrypt/encrypt.dart' as encrypt;

class MyCrypt {

  // 암호화
  static String AES_encrypt(String normalData) {
    final key = encrypt.Key.fromUtf8('암호화키로 사용될 32byte 길이의 문자열');
    final iv = encrypt.IV.fromUtf8('IV값으로 사용될 16byte 길이의 문자열');

    final encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));
    final encrypted = encrypter.encrypt(normalData, iv: iv);
    
    return encrypted.base64;
  }

  // 복호화
  static String AES_decrypt(String encryptedData) {
    final key = encrypt.Key.fromUtf8('암호화키로 사용될 32byte 길이의 문자열');
    final iv = encrypt.IV.fromUtf8('IV값으로 사용될 16byte 길이의 문자열');

    final encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));
    final decrypted = encrypter.decrypt(encrypt.Encrypted.from64(encryptedData), iv: iv);

    return decrypted;
  }
  
}


// 사용
var encodeData = MyCrypt.AES_encrypt('암호화할 문자열');
var decodeData = MyCrypt.AES_decrypt(encodeData); // 암호화된 문자열

 

3) 팁

iv값의 길이는 암호화키보다 짧으므로, 암호화키 문자열에서 추출하여 사용하는 것도 가능함.
단, 암/복호화에 사용되는 key와 iv값은 동일해야 정상적인 복호화가 됨.

var keyString = '32byte길이의 암호화키 문자열';

final key = encrypt.Key.fromUtf8(keyString);
final iv = encrypt.IV.fromUtf8(keyString.toLowerCase().substring(0, 16));

 

참조
[공식] https://pub.dev/packages/encrypt
https://link2me.tistory.com/2215

 

4) 오류 및 디버깅

Invalid or corrupted pad block using encrypt package

sol.> 암호화키 문자열의 길이에 따라 AES 암호화 방식이 구분됨.
        16byte -> AES-128, 24byte  ->  AES-192, 32byte  ->  AES-256
        키 문자열 길이가 16, 24, 32byte 이중에 하나도 아니면, 에러가 발생함.

* 참조 https://kkh0977.tistory.com/6307

flutter/runtime/dart_vm_initializer.cc(41)] unhandled exception: invalid argument(s): input buffer too short

sol> 서버와 연동을 하려다보니 복호화부터 진행해야 했고, 다시 암호화하려니 위와 같은 에러가 발생함. 이에 대한 원인은 키값의 길이가 맞지 않아서 라고 이미 stackoverflow에서 언급되고 있음.
( https://stackoverflow.com/questions/70817666/invalid-arguments-input-buffer-too-short-and-invalid-or-corrupted-pad-block)
        그런데 암호화 키값, iv값 길이 모두 확인해봐도 이상이 없음.
        결국 찾아낸 원인은 암호화 처리 할때, padding 옵션과 평문의 길이가 매칭되지 않아서 오류가 발생되었음.

final encrypter = encrypt.Encrypter(encrypt.AES(
    encrypt.Key.fromUtf8(encryptKey),
    mode: encrypt.AESMode.cbc,
    padding: null,
));  // 오류가 발생된 코드

      padding: null은 평문의 길이가 16바이트의 배수가 아니면 encrypt 메서드에서 오류가 발생할 수 있다고 함. 해결책은 제거하거나 옵션을 Pkcs7Padding()를 사용하면 됨. 난 제거 했음.

반응형

+ Recent posts