PostHog / posthog-flutter

PostHog Flutter SDK
https://posthog.com/docs/libraries/flutter
MIT License
55 stars 37 forks source link

How to build Flutter flavors #100

Closed adrianvintu closed 7 months ago

adrianvintu commented 7 months ago

Version

4.4.1

Steps to Reproduce

It seems the configuration is not hardcoded into the AppManifest and Info.plist.

How can we build flavors? https://docs.flutter.dev/deployment/flavors

Expected Result

ApiKey is not hardcoded into AppManifest and Info.plist. ApiKey is hardcoded into a dart file belonging to a flavor.

JS verson has an init() method - can we have the same in Flutter?

Actual Result

ApiKey is hardcoded into AppManifest and Info.plist.

marandaneto commented 7 months ago

Its a dupe of https://github.com/PostHog/posthog-flutter/issues/22 You can have a manifest per flavor and build type https://developer.android.com/build/manage-manifests (with each API key) Then Android merges all the manifests Same for iOS I think, see example https://stackoverflow.com/questions/37615405/use-different-googleservice-info-plist-for-different-build-schemes

adrianvintu commented 6 months ago

@marandaneto Thank you!

adrianvintu commented 6 months ago

@marandaneto the ios version does not work

The link you sent me has Swift code that loads the google setting file.

How to do the same for Posthog?

marandaneto commented 6 months ago

@marandaneto the ios version does not work

The link you sent me has Swift code that loads the google setting file.

How to do the same for Posthog?

@adrianvintu the idea is the same, you can have a plist file per flavor or something similar, I don't have an example but I know it's possible, you can just inspire from that. As I mentioned, this is a dupe of https://github.com/PostHog/posthog-flutter/issues/22 to make this easier without this workaround but it's not a high priority yet.

adrianvintu commented 6 months ago

Thank you @marandaneto

In the end I have done like this: https://www.marcosantadev.com/manage-plist-files-plistbuddy/

INFO_PLIST="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
FLAVOR_PLIST="$PROJECT_DIR/Plist/Info-$PRODUCT_BUNDLE_IDENTIFIER.plist"

/usr/libexec/PlistBuddy -c "Merge $FLAVOR_PLIST" "$INFO_PLIST"
adrianvintu commented 5 months ago

This is also required for release, inside proguard-rules.pro

# posthog
-keep class com.posthog.** { *; }
-keep interface com.posthog.** { *; }