Skip to content

Logs not printed on iOS devices on build #44718

Description

@stx

Logs are not printed on first build on iOS devices. Works in simulator.

Related: #41133

Reproduce:

void main() {
  print("here's a message");
  print("here's a second message");
  runApp(MyApp());
}
➜  testproject flutter run       
Launching lib/main.dart on Virgo in debug mode...
Running Xcode build...                                                  
 ├─Assembling Flutter resources...                           7.3s
 └─Compiling, linking and signing...                         7.2s
Xcode build done.                                           15.9s
Installing and launching...                                        24.7s
Syncing files to device Virgo...                                        
 4,509ms (!)                                       

🔥  To hot reload changes while running, press "r". To hot restart (and rebuild state), press "R".
An Observatory debugger and profiler on Virgo is available at: http://127.0.0.1:1033/uK9tw0PQzw8=/
For a more detailed help message, press "h". To detach, press "d"; to quit, press "q".

Performing hot restart...                                              ⣻
flutter: here's a message
flutter: here's a second message
        
Restarted application in 966ms.
[✓] Flutter (Channel master, v1.10.16-pre.98, on Mac OS X 10.15.1 19B88, locale en-US)
    • Flutter version 1.10.16-pre.98 at /Users/james/Development/flutter
    • Framework revision 03ac37af08 (2 hours ago), 2019-11-08 12:47:26 -0800
    • Engine revision 5f5713e339
    • Dart version 2.7.0

 
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/james/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

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

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 38.2.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[✓] VS Code (version 1.40.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.6.0

[✓] Connected device (1 available)
    • Virgo • 00008030-000848D11EF0802E • ios • iOS 13.2.2

! Doctor found issues in 1 category.

Activity

  1. changed the title [-]Logs not printed on iOS devices on first build[/-] [+]Logs not printed on iOS devices on build[/+] on Nov 12, 2019
  2. jmagman commented on Nov 12, 2019

    @jmagman
    Member

    Exceptions and logs are being printed via the same log reader. I'm going to duplicate this to your other issue #44718.

  3. jmagman commented on Nov 12, 2019

    @jmagman
    Member

    #44717 (comment)

    Exceptions pre-runApp never get printed as far as I can tell.

    Logs pre-runApp do get printed on hot restart, but never on first build. May apply to exceptions also, but can't test it due to the above.

  4. christopherfujino commented on Nov 13, 2019

    @christopherfujino
    Contributor

    My guess is that we're losing logs from the beginning of the first time main() runs because these get logged before the tool makes the connection to the observatory.

  5. jonahwilliams commented on Nov 13, 2019

    @jonahwilliams
    Contributor

    A potential solution here is to always start the isolate in a paused state, and then resume after connecting to the vmservice

  6. jmagman commented on Nov 13, 2019

    @jmagman
    Member

    A potential solution here is to always start the isolate in a paused state, and then resume after connecting to the vmservice

    That's an interesting idea, I like that.

  7. added
    a: debuggingDebugging, breakpoints, expression evaluation
    toolAffects the "flutter" command-line tool. See also t: labels.
    platform-iosiOS applications specifically
    on Nov 13, 2019
  8. j0nscalet commented on Dec 20, 2019

    @j0nscalet

    @stx I've noticed that the issue seems to occur, not just pre runApp(), but before there's a connection to the observatory, like @christopherfujino mentioned. Have you run into this?

  9. stx commented on Dec 20, 2019

    @stx
    Author

    @j0nscalet Correct. This is an issue prior to the connection to the VM service. That's why it only happens on first build and not restart.

  10. jmagman commented on Mar 18, 2020

    @jmagman
    Member

    Some notes:
    I was able to read the observatory port log line with ios-deploy by attaching to lldb with --debug instead of --justlaunch

    ios-deploy --id <device-id> --bundle build/ios/iphoneos/Runner.app --debug  
    ...
    (lldb)     connect
    (lldb)     run
    success
    2020-03-17 17:32:39.410811-0700 Runner[633:132633] flutter: Observatory listening on http://127.0.0.1:55084/kiP-Z29onwQ=/
    

    Or install and launch just the debugserver with --nolldb and store that port somewhere:

    ios-deploy --id <device-id> --bundle build/ios/iphoneos/Runner.app --nolldb
    ...
    -------------------------
    debugserver port: 57168
    App path: /private/var/containers/Bundle/Application/666A4C8D-C54D-4C55-8594-1E1FE56406CD/Runner.app
    

    Then later attach to that port with --noinstall (which launches if it's not already running):

    ios-deploy --id <device-id> --bundle build/ios/iphoneos/Runner.app --noinstall --port 57168 
    ...
    (lldb)     connect
    (lldb)     run
    success
    2020-03-17 17:35:05.399716-0700 Runner[636:133192] flutter: Observatory listening on http://127.0.0.1:55427/ifXCFq2E91c=/
    

    And even when it's running, I was able to print the observatory port for a standard app (the FlutterController wouldn't necessarily be the rootViewController for add-to-app) after interrupting the process (app would be briefly locked until resumed).

    (lldb) process interrupt
    Process 639 stopped
    * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
        frame #0: 0x00000001aa144198 libsystem_kernel.dylib`mach_msg_trap + 8
    libsystem_kernel.dylib`mach_msg_trap:
    ->  0x1aa144198 <+8>: ret    
    
    libsystem_kernel.dylib`mach_msg_overwrite_trap:
        0x1aa14419c <+0>: mov    x16, #-0x20
        0x1aa1441a0 <+4>: svc    #0x80
        0x1aa1441a4 <+8>: ret    
    Target 0: (Runner) stopped.
    (lldb)  po ((FlutterEngine *)[UIApplication.sharedApplication.keyWindow.rootViewController engine]).observatoryUrl.port
    56889
    
    (lldb) process continue
    Process 639 resuming
    
  11. added
    P2Important issues not at the top of the work list
    on Aug 18, 2020
  12. 6 remaining items

  13. hossam-zaki commented on Sep 21, 2020

    @hossam-zaki

    How do we get this new build of flutter?

  14. jmagman commented on Sep 22, 2020

    @jmagman
    Member

    I'm going to reopen this one. #66092 fixed the original issue filed in November 2019, but this issue also became confused with a 1.20 regression where stdout logs aren't being passed along the VM "Stdout" service (which even on #66092 is important for attach flows)

    According to my bisect, this regressed with #54132.

  15. jmagman commented on Sep 22, 2020

    @jmagman
    Member

    Actually, changed my mind. Let's use #65519 to track that regression, so we don't confuse cherry-pickers.

  16. added
    P2Important issues not at the top of the work list
    and removed
    P2Important issues not at the top of the work list
    on Sep 22, 2020
  17. github-actions commented on Aug 12, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  18. locked as resolved and limited conversation to collaborators on Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: debuggingDebugging, breakpoints, expression evaluationfound in release: 1.22Found to occur in 1.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallytoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions