Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failed: Swift Compiler Error (Flutter 1.12) #45

Closed
mdvandergon opened this issue Mar 15, 2020 · 5 comments
Closed

Build failed: Swift Compiler Error (Flutter 1.12) #45

mdvandergon opened this issue Mar 15, 2020 · 5 comments
Labels
documentation Improvements or additions to documentation waiting for response

Comments

@mdvandergon
Copy link

I created a new Flutter project to test the package using the pub.dev example code. I saw that other issues mentioned iOS >=10, and Swift 5, so I modified Podfile with platform :ios, '13.2' and config.build_settings['SWIFT_VERSION'] = '5'. However, I get Swift complier errors. I'm guessing that I've missed something, but perhaps there is an issue.

Any help would be appreciated. Thanks for the package!

flutter doctor output:

/Users/markvandergon/flutter/bin/flutter doctor --verbose
[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.3 19D76, locale en-US)
    • Flutter version 1.12.13+hotfix.8 at /Users/markvandergon/flutter
    • Framework revision 0b8abb4724 (5 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/markvandergon/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Users/markvandergon/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/192.6241897/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3.1, Build version 11C504
    • CocoaPods version 1.9.1

[✓] Android Studio (version 3.6)
    • Android Studio at /Users/markvandergon/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/192.6241897/Android Studio.app/Contents
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] Connected device (1 available)
    • iPhone 11 Pro Max • 3F26DBDF-B967-49F4-8BF9-1D59768BDF74 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

Error:

Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Running pod install...
Running Xcode build...
Xcode build done.                                            5.6s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    /Users/markvandergon/flutter/.pub-cache/hosted/pub.dartlang.org/speech_to_text-1.1.0/ios/Classes/SwiftSpeechToTextPlugin.swift:224:44: error: value of type 'SwiftSpeechToTextPlugin' has no member 'AVAudioSession'
                rememberedAudioCategory = self.AVAudioSession.Category
                                          ~~~~ ^~~~~~~~~~~~~~
    /Users/markvandergon/flutter/.pub-cache/hosted/pub.dartlang.org/speech_to_text-1.1.0/ios/Classes/SwiftSpeechToTextPlugin.swift:227:63: error: type 'Int' has no member 'notifyOthersOnDeactivation'
                try self.audioSession.setActive(true, withFlags: .notifyOthersOnDeactivation)
                                                                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~
    /Users/markvandergon/flutter/.pub-cache/hosted/pub.dartlang.org/speech_to_text-1.1.0/ios/Classes/SwiftSpeechToTextPlugin.swift:245:9: warning: 'catch' block is unreachable because no errors are thrown in 'do' block
            catch {
            ^
    note: Using new build system
    note: Planning build
    note: Constructing build description

Could not build the application for the simulator.
Error launching application on iPhone 11 Pro Max.

@mustakimpawle
Copy link

Same issue. Did you find the solution?

@sowens-csd
Copy link
Contributor

Sorry for the delay. I'll try a new project myself. In the meantime I'd suggest opening the project in Xcode and set the Swift version there.

@sowens-csd sowens-csd added the documentation Improvements or additions to documentation label Mar 19, 2020
@mdvandergon
Copy link
Author

Hey, thank you for looking into it. No solution yet. I have been setting the Swift version in Xcode, but it looks like I get the same issue. I might have some more time to investigate this week.

swift 5 Xcode

@sowens-csd
Copy link
Contributor

I have Flutter 1.12.13+Hotfix.8

Here's what I tried:

  1. flutter create --org com.csdcorp --ios-language swift --android-language kotlin .
  2. build and launch the resulting project for iOS, all working
  3. add speech_to_text: ^1.1.0 to pubspec.yaml dependencies
  4. rebuild and launch, all working
  5. add speech to text to main.dart and initialize it
  6. add required permission descriptions to Info.plist
  7. rebuild and launch, all working, speech recognition functional

So there doesn't appear to be a compile problem with the plugin and the latest version of Flutter. Can you tell me if I've done something differently than you're doing? Here's the full source of main.dart in case it's of help. I made only the minimal changes required to the example program to add a simple speech usage to it.

import 'package:flutter/material.dart';
import 'package:speech_to_text/speech_recognition_result.dart';
import 'package:speech_to_text/speech_to_text.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  SpeechToText _speechToText;
  bool _speechReady = false;
  String _wordsSpoken = "";
  int _counter = 0;

  @override
  void initState() {
    super.initState();
    _startSpeech();
  }

  Future<void> _startSpeech() async {
    _speechToText = SpeechToText();
    _speechReady = await _speechToText.initialize();
    if (_speechReady) {
      _speechToText.listen(onResult: _resultHandler, partialResults: true);
    }
    setState(() {});
  }

  void _resultHandler(SpeechRecognitionResult result) {
    setState(() {
      _wordsSpoken = result.recognizedWords;
    });
  }

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(_speechReady ? 'Speech is now ready' : 'Speech not ready yet'),
            Text(_wordsSpoken),
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

@mdvandergon
Copy link
Author

Hi there, sorry for the delay and thank you for sharing the example. I can confirm that there is no compile issue anymore with the latest package. I took these steps, in addition to:

  1. updating to the latest version speech_to_text: '>=2.0.1',
  2. updating to the latest version of xcode 11.4 (possibly unrelated to this working)
  3. running pod disintegrate and then pod install in my project(s).

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation waiting for response
Projects
None yet
Development

No branches or pull requests

3 participants