플러터에서 apk 빌드시 에러 발생함 - 기록용
하도 이것 저것 테스트 하니까 에러가 약간씩 바뀜
일단 기록용으로 남겨둠
총 2단계로 해결한거 같다.
단계 1
최초 에러
ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in E:\work\Flutter\project1\build\flutter_inappwebview\outputs\mapping\release\missing_rules.txt.
ERROR: R8: Missing class android.window.BackEvent (referenced from: void io.flutter.view.FlutterView.startBackGesture(android.window.BackEvent) and 1 other context)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':flutter_inappwebview:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
> Compilation failed to complete
대응 1
E:\work\Flutter\project1\build\flutter_inappwebview\outputs\mapping\release\missing_rules.txt 파일을 열어서 내용을 복사후 android/app/proguard-rules.pro 파일에 붙여 넣는다. 만일 proguard-rules.pro 파일이 없다면 신규로 만들면 된다.
인터넷 다른것도 찾아보니 이것 저것 넣으라고 하던데 모두 테스트 해보니 나는 missing_rules.txt 내용만 넣어도 되었다.
다른곳의 내용을 차후에 참고하려고 내용을 남겨둠(참고만 할것)
# https://github.com/razorpay/razorpay-flutter/issues/415
-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.*
-ignorewarnings
대응 2
터미널 열고 아래 명령어를 차례로 입력한다.
flutter clean
flutter pub get
flutter --no-color build apk
단계2
다른 에러 발생함
C:\Users\jskang\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_inappwebview-5.8.0\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\InAppWebViewFlutterPlugin.java:22: error: cannot find symbol
import io.flutter.view.FlutterView;
^
symbol: class FlutterView
location: package io.flutter.view
C:\Users\jskang\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_inappwebview-5.8.0\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\InAppWebViewFlutterPlugin.java:43: error: cannot find symbol
public PluginRegistry.Registrar registrar;
^
symbol: class Registrar
location: interface PluginRegistry
C:\Users\jskang\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_inappwebview-5.8.0\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\InAppWebViewFlutterPlugin.java:51: error: cannot find symbol
public FlutterView flutterView;
^
symbol: class FlutterView
location: class InAppWebViewFlutterPlugin
C:\Users\jskang\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_inappwebview-5.8.0\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\InAppWebViewFlutterPlugin.java:56: error: cannot find symbol
public static void registerWith(PluginRegistry.Registrar registrar) {
^
symbol: class Registrar
location: interface PluginRegistry
C:\Users\jskang\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_inappwebview-5.8.0\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\InAppWebViewFlutterPlugin.java:76: error: cannot find symbol
private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger, Activity activity, PlatformViewRegistry platformViewRegistry, FlutterView flutterView) {
^
symbol: class FlutterView
location: class InAppWebViewFlutterPlugin
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors
3 warnings
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':flutter_inappwebview:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
대응 1
에러를 보니 flutter_inappwebview-5.8.0 에서 발생 한거로 나옴. 처음에는 이것도 눈에 안들어오고 모두 해결후 눈에 들어옴.
근데 나는 flutter_inappwebview 라이브러리 안쓰는데??
그래도 클로드에 물어보니 flutter_inappwebview 를 6.0.0 으로 올리라함
pubspec.yaml 에 flutter_inappwebview: ^6.0.0 넣고 pub get 하니 youtube_player_flutter: ^8.1.2 사용중인데 이것때문에 의존성 문제로 안된다고 함
youtube_player_flutter 에서 flutter_inappwebview 사용하고 있었음
그래서 youtube_player_flutter 를 최신 버젼 youtube_player_flutter: ^9.1.1 로 올림(put get 시 최신버젼을 알수있다.)
flutter --no-color build apk 실행하니 정상적으로 빌드 되었다. 하. 힘들다. 이것때문에 6시간 정도 날린거 같다.
warning은 좀 있지만 built 메세지 보려고 참 힘들었다.
결론
build 에러 발생시 문구를 본다.
missing_rules.txt 파일이 내용을 android/app/proguard-rules.pro 파일에 붙여 넣는다. (없으면 신규 생성)
pubspec.yaml 파일 에 youtube_player_flutter: ^8.1.2 대신 youtube_player_flutter: ^9.1.1 로 업그레이드
터미널에서 다음 실행
flutter clean
flutter pub get
flutter --no-color build apk
app-release.apk 파일 생성 완료
pubspec.yaml 파일의 내용 일부
pubspec.yaml 파일의 내용 일부
------------------------------------------------------------------
dependencies:
flutter:
sdk: flutter
#provider: ^6.0.5
#http: ^1.1.0
#flutter_secure_storage: ^8.0.0
#shared_preferences: ^2.2.0
provider: ^6.0.5
#provider: 6.0.5
http: ^1.1.0
flutter_secure_storage: ^8.0.0
shared_preferences: ^2.1.1 # 버전 다운그레이드
cupertino_icons: ^1.0.5 # 안정적인 버전으로 조정
#logger: ^1.4.0 #로거
logging: ^1.2.0
dio: ^5.4.0
pretty_dio_logger: ^1.3.1 # Dio 로깅을 위한 패키지
event_bus: ^2.0.0
fl_chart: ^0.66.2
#youtube_player_flutter: ^8.1.2
youtube_player_flutter: ^9.1.1
#flutter_inappwebview: ^6.0.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
#cupertino_icons: ^1.0.8
클로드 답변 - 참고용으로 남겨둠