From 1ef2ba9037b0a3403570b393bb6e416e2b493b99 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 17 Oct 2024 16:05:19 +0200 Subject: [PATCH] update --- .github/workflows/e2e_flutter.yml | 9 ++- .../samples/flutter_e2e/LaunchArgPlugin.kt | 73 +++++++++++++++++++ .../samples/flutter_e2e/MainActivity.kt | 8 +- .../gradle/wrapper/gradle-wrapper.properties | 3 +- e2e_test/flutter/android/settings.gradle | 2 +- e2e_test/flutter/flow.yaml | 4 +- e2e_test/flutter/lib/launch_args.dart | 24 ++++++ e2e_test/flutter/lib/main.dart | 19 +++-- e2e_test/flutter/pubspec.yaml | 1 + 9 files changed, 130 insertions(+), 13 deletions(-) create mode 100644 e2e_test/flutter/android/app/src/main/kotlin/io/sentry/samples/flutter_e2e/LaunchArgPlugin.kt create mode 100644 e2e_test/flutter/lib/launch_args.dart diff --git a/.github/workflows/e2e_flutter.yml b/.github/workflows/e2e_flutter.yml index 8b838429e..98027d861 100644 --- a/.github/workflows/e2e_flutter.yml +++ b/.github/workflows/e2e_flutter.yml @@ -54,13 +54,18 @@ jobs: - name: Build App if: env.SENTRY_AUTH_TOKEN_E2E != null run: | - flutter build ios --debug --simulator --obfuscate --split-debug-info=./ --dart-define=SENTRY_AUTH_TOKEN_E2E=$SENTRY_AUTH_TOKEN_E2E + flutter build ios --debug --simulator xcrun simctl install Booted build/ios/iphonesimulator/Runner.app - name: Run Maestro env: MAESTRO_DRIVER_STARTUP_TIMEOUT: 1500000 # 25 min, CI can be slow at times run: maestro test flow.yaml - + - name: Store Maestro Logs + uses: actions/upload-artifact@v4 + if: failure() + with: + name: maestro-logs-test + path: MaestroLogs # analyze: # uses: ./.github/workflows/analyze.yml # with: diff --git a/e2e_test/flutter/android/app/src/main/kotlin/io/sentry/samples/flutter_e2e/LaunchArgPlugin.kt b/e2e_test/flutter/android/app/src/main/kotlin/io/sentry/samples/flutter_e2e/LaunchArgPlugin.kt new file mode 100644 index 000000000..019752dbe --- /dev/null +++ b/e2e_test/flutter/android/app/src/main/kotlin/io/sentry/samples/flutter_e2e/LaunchArgPlugin.kt @@ -0,0 +1,73 @@ +package io.sentry.samples.flutter_e2e + +import android.os.Build +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding +import io.flutter.embedding.engine.plugins.activity.ActivityAware +import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.plugin.common.MethodChannel.Result + +class LaunchArgPlugin: ActivityAware, FlutterPlugin, MethodCallHandler { + private var channel: MethodChannel? = null + + private val args: MutableList = ArrayList() + + override fun onAttachedToEngine(flutterPluginBinding: FlutterPluginBinding) { + channel = MethodChannel(flutterPluginBinding.binaryMessenger, "launchargs") + channel!!.setMethodCallHandler(this) + } + + override fun onAttachedToActivity(binding: ActivityPluginBinding) { + args.clear() + + val activity = binding.activity + val intent = activity.intent + if (intent != null) { + val bundle = intent.extras + if (bundle != null) { + val keys = bundle.keySet() + + for (key in keys) { + args.add("--$key") + args.add(bundle[key].toString()) + } + } + } + } + + override fun onDetachedFromActivityForConfigChanges() { + args.clear() + } + + override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { + val bundle = binding.activity.intent.extras + val keys = bundle!!.keySet() + + args.clear() + for (key in keys) { + args.add("--$key") + args.add(bundle[key].toString()) + } + } + + override fun onDetachedFromActivity() { + args.clear() + } + + override fun onMethodCall(call: MethodCall, result: Result) { + if (call.method == "getPlatformVersion") { + result.success("Android " + Build.VERSION.RELEASE) + } else if (call.method == "args") { + result.success(args) + } else { + result.notImplemented() + } + } + + override fun onDetachedFromEngine(binding: FlutterPluginBinding) { + channel!!.setMethodCallHandler(null) + } +} \ No newline at end of file diff --git a/e2e_test/flutter/android/app/src/main/kotlin/io/sentry/samples/flutter_e2e/MainActivity.kt b/e2e_test/flutter/android/app/src/main/kotlin/io/sentry/samples/flutter_e2e/MainActivity.kt index 8a8c53445..d66cf2d93 100644 --- a/e2e_test/flutter/android/app/src/main/kotlin/io/sentry/samples/flutter_e2e/MainActivity.kt +++ b/e2e_test/flutter/android/app/src/main/kotlin/io/sentry/samples/flutter_e2e/MainActivity.kt @@ -1,5 +1,11 @@ package io.sentry.samples.flutter_e2e import io.flutter.embedding.android.FlutterActivity +import io.flutter.embedding.engine.FlutterEngine -class MainActivity: FlutterActivity() +class MainActivity: FlutterActivity() { + override fun configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + flutterEngine.plugins.add(LaunchArgPlugin()) + } +} \ No newline at end of file diff --git a/e2e_test/flutter/android/gradle/wrapper/gradle-wrapper.properties b/e2e_test/flutter/android/gradle/wrapper/gradle-wrapper.properties index 7bb2df6ba..a2d9afad3 100644 --- a/e2e_test/flutter/android/gradle/wrapper/gradle-wrapper.properties +++ b/e2e_test/flutter/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Thu Oct 17 15:08:53 CEST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip diff --git a/e2e_test/flutter/android/settings.gradle b/e2e_test/flutter/android/settings.gradle index b9e43bd37..5c5836635 100644 --- a/e2e_test/flutter/android/settings.gradle +++ b/e2e_test/flutter/android/settings.gradle @@ -18,7 +18,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "8.1.0" apply false + id "com.android.application" version "8.3.2" apply false id "org.jetbrains.kotlin.android" version "1.8.22" apply false } diff --git a/e2e_test/flutter/flow.yaml b/e2e_test/flutter/flow.yaml index d48c28a4d..4b4d2f138 100644 --- a/e2e_test/flutter/flow.yaml +++ b/e2e_test/flutter/flow.yaml @@ -1,6 +1,8 @@ appId: io.sentry.samples.flutter_e2e --- -- launchApp +- launchApp: + arguments: + sentryAuthToken: "test" - assertVisible: 'Capture exception' - tapOn: "Capture exception" - assertVisible: "Sending exception to Sentry..." diff --git a/e2e_test/flutter/lib/launch_args.dart b/e2e_test/flutter/lib/launch_args.dart new file mode 100644 index 000000000..301490fc5 --- /dev/null +++ b/e2e_test/flutter/lib/launch_args.dart @@ -0,0 +1,24 @@ +import 'dart:async'; +import 'dart:io'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +class LaunchArgs { + static const MethodChannel _channel = MethodChannel('launchargs'); + + /// Returns the list of command line arguments that were passed to the + /// application at start. This only supports Android and iOS currently. All + /// other platforms will result in an empty list being returned. + static Future> get args async { + var args = []; + + if (!kIsWeb) { + if (Platform.isAndroid || Platform.isIOS) { + args = List.from(await _channel.invokeMethod('args')); + } + } + + return args; + } +} \ No newline at end of file diff --git a/e2e_test/flutter/lib/main.dart b/e2e_test/flutter/lib/main.dart index 71e620ebc..cca4d36c8 100644 --- a/e2e_test/flutter/lib/main.dart +++ b/e2e_test/flutter/lib/main.dart @@ -1,19 +1,24 @@ -import 'package:flutter/material.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; -import 'package:http/http.dart'; import 'dart:convert'; import 'dart:io'; +import 'package:flutter/material.dart'; +import 'package:flutter_e2e/launch_args.dart'; +import 'package:http/http.dart'; +import 'package:sentry_flutter/sentry_flutter.dart'; +// import 'package:launch_args/launch_args.dart'; + const _org = 'sentry-sdks'; const _projectSlug = 'sentry-flutter'; const _exampleDsn = 'https://e85b375ffb9f43cf8bdf9787768149e0@o447951.ingest.sentry.io/5428562'; -const _token = - String.fromEnvironment('SENTRY_AUTH_TOKEN_E2E', defaultValue: ''); -// flutter build apk --dart-define=SENTRY_AUTH_TOKEN_E2E=$SENTRY_AUTH_TOKEN_E2E works +String? _token; Future main() async { - if (_token.trim().isEmpty) { + WidgetsFlutterBinding.ensureInitialized(); + + final args = await LaunchArgs.args; + _token = args[1]; + if (_token!.trim().isEmpty) { print('AUTH TOKEN is not set'); exit(1); } diff --git a/e2e_test/flutter/pubspec.yaml b/e2e_test/flutter/pubspec.yaml index ebe5d95af..3776ccc29 100644 --- a/e2e_test/flutter/pubspec.yaml +++ b/e2e_test/flutter/pubspec.yaml @@ -13,6 +13,7 @@ dependencies: sentry: sentry_flutter: cupertino_icons: ^1.0.8 +# launch_args: ^2.0.5+1 dev_dependencies: flutter_test: