Reputation: 21
I have a flutter app with two flavors and I want to add home screen widget for iOS deployment for only one flavor of app.
Each flavor of my app is corresponding to a unique bundle ID (my.domain.app1
and my.domain.app2
).
I set scheme in Xcode following flutter tutorial.
I created home screen widget in iOS using this tutorial.
I give bundle ID for my home screen widget my.domain.app2.homeWidget
as I want home widget for only app2. I do not need home widget for app1.
I try running app2 and it has no issue.
However, I try debugging my app1, it causes this error.
Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier
I tried removing homeWidget
from Build Phases > Embed Foundation Extensions
but it removes my home widget from both app1 and app2. I cannot keep home widget for only one app scheme.
How can I assign home widget in iOS to only my.domain.app2
but not my.domain.app1
?
Upvotes: 1
Views: 507
Reputation: 1
Simply You need 'Active Compilation Conditions' for each Environment.
Steps:
Go to Runner in 'Navigator' on the left side of Xcode Runner
Select Project 'Runner' and select 'Build Settings' Runner Project & Build Settings
Search for 'Active Compilation Conditions' Active Compilation Conditions
Now you will see your different schemes for every scheme add your Active compilation key like this Adding Active compilation keys
Go to @main (WidgetBundle) WidgetBundle
Add preprocess if-condition like this Main with preprocess if-condition
@main
struct WidgetTestBundle: WidgetBundle {
var body: some Widget {
#if PROD
WidgetTest()
#endif
}
}
Done 🫡
Additional:
For Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier
that you mentioned
The solution is:
1- Select your widget target
2- For every scheme prod/dev/stg change their bundle identifier to match your app bundle identifier for every flavor + ".widgetName" for example:
You have two flavors dev and prod
Your app bundle ID in prod flavor is com.example.AppName
your widget bundle ID in this scheme should be com.example.AppName.WidgetName
And For the second flavor:
Your app bundle ID in dve flavor is com.example.AppName.dev
your widget bundle ID in this scheme should be com.example.AppName.dev.WidgetName
I hope that was useful ☺️
Upvotes: 0