I’m encountering an error when trying to build my Flutter iOS app for the simulator. The build fails with the following error message:
Error (Xcode): Undefined symbol: __swift_FORCE_LOAD_$_swiftCompatibility56
Could not build the application for the simulator.
Environment:
-
Flutter Version: 3.22.2
-
Xcode Version: 14.2.0
-
CocoaPods Version: 1.15.2
-
iOS Deployment Target: 15.0
-
Swift Version: 5.0
dependencies: cupertino_icons: ^1.0.6 firebase_core: ^3.1.1 firebase_auth: ^5.1.1 google_sign_in: ^6.2.1 another_flutter_splash_screen: ^1.2.0 google_nav_bar: ^5.0.6 provider: ^6.1.2 flutter_splash_screen: ^3.0.0 sign_in_button: ^3.2.0 cloud_firestore: ^5.0.2 intl: ^0.19.0 image_picker: ^1.1.2 permission_handler: ^11.3.1 http: ^1.2.1 device_preview: ^1.2.0 firebase_messaging: ^15.0.2 location: ^7.0.0 url_launcher: ^6.0.20 google_maps_flutter: ^2.7.0
void main() async {
WidgetsFlutterBinding.ensureInitialized();
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
try {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
} catch (e) {
print("Error initializing Firebase: $e");
return;
}
runApp(MyApp());
}
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
print("Handling a background message: ${message.messageId}");
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
Future<String> getCurrentUserId() async {
final user = FirebaseAuth.instance.currentUser;
if (user == null) {
return '';
}
return user.uid;
}
@override
Widget build(BuildContext context) {
return FutureBuilder<String>(
future: getCurrentUserId(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
),
);
} else if (snapshot.hasError) {
print("Error getting user ID: ${snapshot.error}");
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Text('Failed to get user ID'),
),
),
);
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
print("No user ID available");
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: AuthPage(),
);
} else {
final userId = snapshot.data!;
return MultiProvider(
providers: [
ChangeNotifierProvider<BalanceNotifier>(
create: (context) => BalanceNotifier(userId),
),
ChangeNotifierProvider<Cart>(
create: (context) => Cart(),
),
ChangeNotifierProvider<ThemeNotifier>(
create: (context) => ThemeNotifier(),
),
],
child: Consumer<ThemeNotifier>(
builder: (context, themeNotifier, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: lightMode,
darkTheme: darkMode,
themeMode: themeNotifier.currentTheme,
initialRoute: '/',
routes: {
'/': (context) => const SplashScreen(),
'/ProfilePage': (context) => ProfilePage(),
},
onGenerateRoute: (settings) {
if (settings.name == '/TransfertPage') {
final args = settings.arguments as Map<String, dynamic>;
return MaterialPageRoute(
builder: (context) => TransfertPage(
total: args['total'],
userId: args['userId'],
pinController: args['pinController'],
),
);
}
return null;
},
);
},
),
);
}
},
);
}
}
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
class AuthService {
// Google Sign In
Future<UserCredential> signInWithGoogle() async {
// Trigger the authentication flow
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
// Obtain the auth details from the request
final GoogleSignInAuthentication googleAuth =
await googleUser!.authentication;
// Create a new credential
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
// Once signed in, return the UserCredential
return await FirebaseAuth.instance.signInWithCredential(credential);
}
}
Future<void> _updateDeviceToken(String userId) async {
String? deviceToken = await FirebaseMessaging.instance.getToken();
if (deviceToken != null) {
await FirebaseFirestore.instance.collection('users').doc(userId).update({
'deviceToken': deviceToken,
});
}
}
Steps Taken to Resolve the Issue:
-
Updated iOS Deployment Target to 15.0:
-
Modified
Podfile
to setplatform :ios, '15.0'
. -
Updated Xcode project settings to set
iOS Deployment Target
to 15.0.
-
-
Cleaned and Reinstalled Dependencies:
-
Ran
flutter clean
. -
Deleted
Pods
andPodfile.lock
. -
Ran
pod install
.
-
-
Verified Compatibility of Dependencies:
- Checked all dependencies to ensure they are compatible with Swift 5 and iOS 15.0.
-
Modified Build Settings in Xcode:
-
Ensured
Swift Language Version
is set to5.0
. -
Added
$(inherited)
toFramework Search Paths
andOther Linker Flags
.
-
Despite these steps, the issue persists. Any help or suggestions would be greatly appreciated.
Error (Xcode): Undefined symbol: __swift_FORCE_LOAD_$_swiftCompatibility56 Could not build the application for the simulator.
Thank you for your assistance!