iOS build failing in Flutter with Lexical or Preprocessor Issue

Provided following details for Flutter integration

  • SDK Version: web3auth_flutter: ^2.0.3 and web3dart: ^2.4.1

  • Screenshots of error:

  • Related to Custom Authentication? Please provide the following info too: (Optional)

    • Verifier Name: toad-test-verifier
    • Sample idToken(JWT) from TorusUserInfo class : eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IlRZT2dnXy01RU9FYmxhWS1WVlJZcVZhREFncHRuZktWNDUzNU1aUEMwdzAifQ.eyJpYXQiOjE2OTQ0OTkxMDQsImF1ZCI6IkJJLWxxcGFHWllDRW1CRkota09JQ0xDUXNidXd1U1hJcXlONUdQazhOMjdIMG5pM2E4VzA4a1dyRGF6LWRybWRhNjZpbUtPVFFwMHZPSlNmWkJFaDJnSSIsIm5vbmNlIjoiMDNkOGFjOTVjNTJkOWRjMWNhNzIxN2IwMzk2MzQ2YzVhODk1NzcxOTUxZTAzYTZiYWY4Nzc4YTFkZDliMDc4YzYxIiwiaXNzIjoiaHR0cHM6Ly9hcGktYXV0aC53ZWIzYXV0aC5pbyIsIndhbGxldHMiOlt7InB1YmxpY19rZXkiOiIwMmY1ZmY5MGFiNDM1NTQ5YzQzOWQyYTE4NTdlOGE2ZDYxNDRkNDI2OWQ5NDQ4NzRlM2JlYzQ5YWIzODE0MDgyOWEiLCJ0eXBlIjoid2ViM2F1dGhfYXBwX2tleSIsImN1cnZlIjoic2VjcDI1NmsxIn1dLCJlbWFpbCI6ImhhcmlzaGl2QHJvdmVyeC50ZWFtIiwibmFtZSI6IkhhcmlzaGl2IFNpbmdoIiwicHJvZmlsZUltYWdlIjoiaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EvQUFjSFR0ZUhHaGlFTnRyRDFNcWtJQy1GYzRhbWwwLW1FckUtZFZMdmJXVEtIUnJtPXM5Ni1jIiwidmVyaWZpZXIiOiJ0b2FkLXRlc3QtdmVyaWZpZXIiLCJ2ZXJpZmllcklkIjoiNmN3WDRMUzNFaWVldnByZEI4eDVHamY3ekdNMiIsImFnZ3JlZ2F0ZVZlcmlmaWVyIjoidG9hZC10ZXN0LXZlcmlmaWVyIiwiZXhwIjoxNjk0NTg1NTA0fQ.MQmzN-TpTeYovKs5CHa7yzAoXtigZ1R5fGpomoI_zPXZdE4i-F-B_lTt4BUQx5WisTV0xXoHaI83WctLfq0koQ

Web3Auth initialization and login code snippet below:
Initialisation:

  Future<void> _initPlatformState() async {
    final themeMap = HashMap<String, String>();
    themeMap['primary'] = "#F5820D";

    Uri redirectUrl;
    if (Platform.isAndroid) {
      redirectUrl = Uri.parse('w3a://com.example.app/auth');
    } else if (Platform.isIOS) {
      redirectUrl = Uri.parse('com.example.app://openlogin');
    } else {
      throw UnKnownException('Unknown platform');
    }

    final loginConfig = HashMap<String, LoginConfigItem>();
    loginConfig['jwt'] = LoginConfigItem(
      verifier: "toad-test-verifier", // get it from web3auth dashboard
      typeOfLogin: TypeOfLogin.jwt,
      name: "Custom JWT Login",
      clientId: dotenv.env['WEB3AUTH_CLIENT_ID'],
    );

    await Web3AuthFlutter.init(
      Web3AuthOptions(
        clientId: dotenv.env['WEB3AUTH_CLIENT_ID'] ?? '',
        network: Network.testnet,
        redirectUrl: redirectUrl,
        whiteLabel: WhiteLabelData(
          dark: true,
          name: "Toad Cash",
          theme: themeMap,
        ),
        loginConfig: loginConfig,
      ),
    );
  }

Login code:

  VoidCallback _login(Future<Web3AuthResponse> Function() method) {
    return () async {
      context.showProgressBar();
      try {
        final Web3AuthResponse response = await method();
        SharedPreference.setPrivateKey(response.privKey.toString());
        SharedPreference.setIdToken(
            response.userInfo?.idToken.toString() ?? '');
        UserDetails userDetails = UserDetails(
            name: response.userInfo?.name,
            email: response.userInfo?.email,
            profileImage: response.userInfo?.profileImage);
        _proceedToSuccessScreen(userDetails);
      } on UserCancelledException {
        context.dismissProgressBar();
        print("User cancelled.");
      } on UnKnownException {
        context.dismissProgressBar();
        print("Unknown exception occurred");
      }
    };
  }

  Future<Web3AuthResponse> _googleSignInWithJWT() async {
    var idToken = await _getFirebaseIdTokenFromGoogleSignIn();

    return Web3AuthFlutter.login(
      LoginParams(
        loginProvider: Provider.jwt,
        mfaLevel: MFALevel.NONE,
        extraLoginOptions: ExtraLoginOptions(
          id_token: idToken,
          domain: 'https://toad.cash',
        ),
      ),
    );
  }

  Future<String> _getFirebaseIdTokenFromGoogleSignIn() async {
    var idToken = "";
    try {
      final GoogleSignInAccount? result = await GoogleSignIn().signIn();
      final GoogleSignInAuthentication? googleAuth =
          await result?.authentication;
      final credential = GoogleAuthProvider.credential(
        accessToken: googleAuth?.accessToken,
        idToken: googleAuth?.idToken,
      );
      final userCredential =
          await FirebaseAuth.instance.signInWithCredential(credential);

      idToken = (await userCredential.user?.getIdToken(true)).toString();
    } on FirebaseAuthException catch (e) {
      if (e.code == 'user-not-found') {
        print('No user found for that email.');
      } else if (e.code == 'wrong-password') {
        print('Wrong password provided for that user.');
      }
    }
    return idToken;
  }

_login(_googleSignInWithJWT) method called on Login button’s onPressed.

For iOS integration I have followed the steps mentioned here: https://web3auth.io/docs/sdk/pnp/flutter/install

@harishiv Thanks for reaching out.

Your issue has been forwarded to our team and we will get back with an update.

What version of Xcode are you using?

Requirement is Xcode 11.4+ / 12.x

Can you take a look at this example

You can try these steps as well:

  • Updated Xcode to latest
  • change the minimum iOS version to 12 from Xcode/Runner/General/Deployment Info
  • then, pod deintegrate, install, update, repo update
  • flutter clean
  • flutter pub get

My XCode version is 14.2 (14C18).

I tried the above mentioned steps but still it’s giving me the same error.

I looked into the example as well that you shared, the podfile is similar to the one that I have in my project.

I have forwarded your issue to our Dev team and will get back with an update.

Our team mentioned this issue is related to the Project Configuration.

Here are a few more solutions to try:

  1. Go to Target > Build Settings> Change the framework search path to an absolute path.

For Example: Before the change was ~/Documents/FrameworkRootfolder to /Users/$(USER)/Documents/FrameworkRootfolder and set it to recursive.

  1. It is possible that your PodFile is not picking up the configs so all you need to do is just change it. An example is given below:

Changing the following code in PodFile can solve the problem

post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings[‘ENABLE_BITCODE’] = ‘NO’ config.build_settings[‘IPHONEOS_DEPLOYMENT_TARGET’] = ‘10.0’ end end end

to

post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) end end

  1. a. Remove ios/Flutter/Flutter.podspec with just one command rm ios/Flutter/Flutter.podspec

    b. After removing Flutter.podspec your flutter will be cleaned.

    c. Run your application.

  • cd ios to get into the iOS directory of your flutter project.
  • Now deintegrate the pod via pod deintegrate
  • rm Flutter/Flutter.podspec
  • rm podfile.lock
  • flutter clean
  • flutter run
  1. If your problem is still not resolved then you need to switch the channel of your app from master to stable. For switching the channel, run following commands in terminal:
  • flutter channel stable
  • flutter clean
  • flutter run
  1. First backup your ios folder and delete the ios folder. After that, run the following commands:
  • flutter create -i objc . // This is to rebuild the ios folder.
  • flutter pub get
  • cd ios
  • pod init
  • pod install
  • flutter run
  • Backup ios/Runner folder.
  • Delete the ios folder.
  • Run flutter create (your project name). in the previous folder where you have your project(cd users/user/"projects_folder") (this will recreate your ios folder).
  • Paste your Runner backup in the ios folder (into the project).
  • Open Runner.xcworkspace (into ios folder) and there, check the Version, the Bundle ID, all the info.
  • (If do you Have Firebase, you have to copy and paste again the Google Service-Info.Plist into the Runner folder (Always through Xcode) (If do you do this manually, it doesn’t work).

Finally, flutter run and should work!

If flutter run fails:

  1. cd ios
  2. pod install
  3. cd ..
  4. flutter run

And, do this in your info.plist file in ios/Runner/ folder

Changing PodFile from:

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
end
end
end

to

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = 14.0'
    end
  end
end

Hi @vjgee, I tried all the above mentioned steps but none is working for me. I sense there is some dependency conflict here because without Web3Auth the app is building perfectly. As I am using Firebase Firestore as well so does that create any conflicts with Web3Auth?

And one more thing if I am using use_modular_headers! instead of use_frameworks! then it throws this error:

Error (Xcode): module map file '/Users/graphicstone/StudioProjects/toad_cash_mobile/ios/Pods/Headers/Private/openssl_grpc/BoringSSL-GRPC.modulemap' not found

Hi @vjgee, I am able to cut down the problem a bit more. The issue is arising because of Firebase firestore and Web3Auth in the same project.

I created a new project and added Web3Auth and it was working fine, and then I added Firebase Firestore to the project and I was able to reproduce the error once again. Can you please check if there any peer dependency issues with Firestore.

And I did some digging into this and I was able to find a similar issue on Cocoapods Github repo. I have mentioned my issue there as well. Can you please look into this, and help me in any possible way.