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

The Flutter SDK is not available. #19049

Closed
CryptUser opened this issue Jul 3, 2018 · 38 comments
Closed

The Flutter SDK is not available. #19049

CryptUser opened this issue Jul 3, 2018 · 38 comments

Comments

@CryptUser
Copy link

With a new installation of Flutter, following the reflectable tutorial on https://github.com/dart-lang/reflectable I get to the point were the command "pub run build_runner build lib" results in the error: "The Flutter SDK is not available".

For the reproduction as follows I removed my flutter path, and installed it fresh (but still have the plugins for IntelliJ IDEA and Android Studio). Note: Installation is working fine for other purposes as compiling sample app, etc.

How to reproduce:

  1. Install Flutter as usual for Mac:
    a) cd ~/development
    b) git clone -b beta https://github.com/flutter/flutter.git
    c) export PATH=/Users/myname/development/flutter/bin:$PATH
    d) flutter doctor

[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.5 17F77, locale en-SE)
[!] Android toolchain - develop for Android devices (Android SDK 27.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 9.2)
✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
brew install --HEAD libimobiledevice
brew install ideviceinstaller
✗ ios-deploy not installed. To install:
brew install ios-deploy
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
For more info, see https://flutter.io/platform-plugins
To install:
brew install cocoapods
pod setup
[✓] Android Studio (version 3.0)
[✓] IntelliJ IDEA Community Edition (version 2017.3)
[!] VS Code (version 1.24.1)
[✓] Connected devices (2 available)

  1. New Flutter project in IntelliJ Idea
    a) Choose SDK path: /Users/myname/development/flutter
    b) Choose project location: ~/gitroot/PlayGround/reflectable_test

  2. Follow reflectable tutorial (from https://github.com/dart-lang/reflectable):
    a) Replace lib/main.dart with the main.dart from https://github.com/dart-lang/reflectable
    b) Add "reflectable: any" to pubspec.yaml under dependencies
    c) In main.dart, click on the now appearing "get dependencies"
    (import 'main.reflectable.dart'; still shows an error)
    d) On the command line:
    cd /Users/myname/gitroot/PlayGround/reflectable_test/
    pub run build_runner build lib

Result: shows "The Flutter SDK is not available."

@zoechi
Copy link
Contributor

zoechi commented Jul 3, 2018

In a Flutter project you need

flutter packages pub run build_runner build lib

@zoechi zoechi closed this as completed Jul 3, 2018
@CryptUser
Copy link
Author

Thank you! This, and adding "build_runner: any" to the dependencies made the program run. Strangely, however, it did not create the file "main.reflectable.dart" which I expected. Did I miss something here?

@zoechi
Copy link
Contributor

zoechi commented Jul 4, 2018

It's better to add it to dev_dependencies: because it's not imported from code in lib/.
I haven't used reglectable myself yet. Perhaps better to ask there ot on StackOverflow.

@CryptUser
Copy link
Author

Thanks for your comment. I did as you said. Additionally, I had found somewhere else that one shouldn't use lib as the entry point, so I moved main.dart to a parallel directory entry_point and ran "flutter packages pub run build_runner build entry_point". It didn't complain, but resulted in "Succeeded ... with 0 outputs". Deleting the .dart_tool/ directory didn't help. I'll put the question on StackOverflow as you suggested.

@zoechi
Copy link
Contributor

zoechi commented Jul 4, 2018

Where did you read that about the entry_point?
Can you please also post a link to the SO question?

@zoechi
Copy link
Contributor

zoechi commented Jul 4, 2018

See also google/reflectable.dart#117

@CryptUser
Copy link
Author

I read about the entry points in another issue, but unfortunately do not seem to find it again. Anyway, it said that lib is only for libraries, and one should use another directory as entry point (the reflectable tutorial uses "web", by the way). I'll put a link to the SO question, once it's published.

@zoechi
Copy link
Contributor

zoechi commented Jul 4, 2018

Command line apps use bin/, browser apps use web/, and Flutter apps use lib/.
Entrypoint files in lib/ cause some problems because they weren't anticipated there, but so far there were only troubles if lib/main.dart contained relative imports or was imported by another file.
Flutter expects the entry-point file in lib, so there is no point in moving it somewhere else.

@CryptUser
Copy link
Author

Thanks for the explanation. Meanwhile I got the SO question published: https://stackoverflow.com/questions/51169706/flutter-reflection-with-reflectable-working-example-needed

@eernstg
Copy link
Contributor

eernstg commented Jul 4, 2018

Doing the things that you describe, @CryptUser, I do get the following:

tmprepos/reflectable_flutter/flutter19049/flutter_app$ flutter packages pub run build_runner build test/reflectable_test.dart
[INFO] Generating build script...
[INFO] Generating build script completed, took 430ms

[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 520ms

[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 2ms

[INFO] Running build...
[INFO] 1.0s elapsed, 0/2 actions completed.
[INFO] 2.1s elapsed, 0/2 actions completed.
[SEVERE] reflectable on test/widget_test.dart:
Unable to resolve asset ID for "dart:ui"
[INFO] reflectable on test/widget_test.dart:Ignoring entry point flutter_app|test/widget_test.dart that does not include the library 'package:reflectable/reflectable.dart'
[INFO] Running build completed, took 12.8s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 35ms

[INFO] Succeeded after 12.9s with 1 outputs

Not sure where our experiments diverge, but it "should work" as far as I can see... ;-)

@zoechi
Copy link
Contributor

zoechi commented Jul 4, 2018

@eernstg could you make the example project available on GitHub somewhere?

@eernstg
Copy link
Contributor

eernstg commented Jul 4, 2018

Sure. I'd expect android and ios to be omitted because they are created/downloaded. The rest is here: https://github.com/eernstg/reflectable-flutter.

@CryptUser
Copy link
Author

Thanks for the example project, this works for me as well :-)
It's strange that when you did the same you got a different result, but with your example project at hand I may be able to find out where the difference was. Thanks again!

@eernstg
Copy link
Contributor

eernstg commented Jul 4, 2018

Thank you! I've fixed it up a bit more such that it actually uses Flutter, and a build.yaml.

@eernstg
Copy link
Contributor

eernstg commented Jul 4, 2018

It's strange that when you did the same you got a different result

No, it's always like that. ;)

@CryptUser
Copy link
Author

CryptUser commented Jul 4, 2018

Trying a bit further, I realised, that when moving main.dart to the test folder, and running flutter packages pub run build_runner build test, the file main.reflectable.dart IS created. However, when I move main.dart to the lib folder, and run flutter packages pub run build_runner build lib, this file IS NOT created. This behaviour appears to be repeatable. Note that I used the project as described at the top for this, without a build.yaml file. Any ideas why this is? Is this special for a file name main.dart?

@eernstg
Copy link
Contributor

eernstg commented Jul 5, 2018

moving main.dart to the test folder .. main.reflectable.dart IS created

@CryptUser, I have considered this behavior to be a built-in property of the build package, in the sense that it does not handle code generation for libraries under lib (reflectable does take such libraries into account, and also libraries from other packages, but it doesn't output any files under lib).

However, you mentioned the following here and here:

I had found somewhere else that one shouldn't use lib as the entry point

.. but unfortunately do not seem to find it again.

I had the same experience, I can't find it today. I've asked the main creator of the build package about this issue, will return later when I know more.

@CryptUser
Copy link
Author

I should say that I also tested to move main.dart to other directories (entry_point, other) and performed the respective flutter packages pub run build_runner build entry_point or flutter packages pub run build_runner build other, respectively. The file main.reflectable.dart is only created when I use the directory test, not in any of the other directories. In other words, it's not lib which appears to be special, but test.

@zoechi
Copy link
Contributor

zoechi commented Jul 5, 2018

I gues build.yaml should then also include - lib/**.dart in generate_for:?

@CryptUser
Copy link
Author

I didn't use build.yaml at all, since the tutorial at https://github.com/dart-lang/reflectable does not mention it's use. I'll try if I get it working with this file.

@eernstg
Copy link
Contributor

eernstg commented Jul 5, 2018

.. the tutorial at https://github.com/dart-lang/reflectable does not mention [build.yaml]

Right, I discovered that as well. I'll add something about that, but it's all 'package build' related so you should be able to learn whatever there is to learn about build.yaml over there.

@eernstg
Copy link
Contributor

eernstg commented Jul 5, 2018

[should] include - lib/**.dart in generate_for:?

That's exactly what I've asked about when I got in touch with the main creator of the build package (@jakemac53), but that clause came from him, so I assumed that it was needed.

@CryptUser
Copy link
Author

Adding the build.yaml from https://github.com/eernstg/reflectable-flutter to my project, the file main.reflectable.dart is still not created, when I use folders "other" or "entry_point" (for both the build.yaml and the flutter command, of course). Probably it's better to start from the working repo, and see what it takes to break it ;-)

@eernstg
Copy link
Contributor

eernstg commented Jul 5, 2018

Would be great, and do tell us about it!

@CryptUser
Copy link
Author

Shouldn't the following work?

Again, I get 0 output when doing this.

@eernstg
Copy link
Contributor

eernstg commented Jul 5, 2018

Maybe it's because you're not specifying what to build: flutter packages pub run build_runner build other. (Perhaps test is being built by default, but build_runner has no default settings for other or anything else that it hasn't heard about.)

@CryptUser
Copy link
Author

I tried flutter packages pub run build_runner build other and flutter packages pub run build_runner build other/main.dart as well, with the same result. Does it work for you?

@eernstg
Copy link
Contributor

eernstg commented Jul 5, 2018

Does it work for you?

Trying it now.

Also, we have this sentence here:

generate_for: List of String or Map, Optional:. The subset of files within
the target's sources which should have this Builder applied.

which seems to confirm that 'generate_for' is about filtering something which has already been selected as a target, not about getting a target in the first place.

@eernstg
Copy link
Contributor

eernstg commented Jul 5, 2018

(.. there is no web/main.dart in https://github.com/dart-lang/reflectable, and there isn't even a web directory ..)
(Ah, it's from the README text; got it)

@CryptUser
Copy link
Author

I mean the one inside the readme text (scroll down the page), under the headline Usage.

@eernstg
Copy link
Contributor

eernstg commented Jul 5, 2018

I get the same behavior: Build will not generate code for anything in other, but it does happen for entry points in test and example. It seems like there are some directories which are on a positive list, and all others are ignored. Maybe it's just something I should have seen in a config file, but I hope @jakemac53 will clarify this.

@eernstg
Copy link
Contributor

eernstg commented Jul 5, 2018

By the way, here's the "not in lib" rule: https://www.dartlang.org/tools/pub/package-layout#public-libraries. And here's the whitelist: https://www.dartlang.org/tools/pub/glossary#entrypoint-directory, so you could try to see if it works for you to stick to one of those.

Apart from that I'm sure that there will be more conflicts than this one concerned with the treatment of lib by Flutter (here's the rule: https://flutter.io/flutter-for-react-native/#project-structure-and-resources, that the Flutter entry point is lib/main.dart, period).

@CryptUser
Copy link
Author

Thanks for these links, they helped a lot. While the first one says

Entrypoints—Dart scripts with a main() function—cannot go in lib.

the third one says

In Flutter, the entry point file is ’projectname’/lib/main.dart

No wonder is the lib folder somewhat special for Reflactable with Flutter. Thanks to your second link I could figure out that putting main.dart in the 'bin' folder works - even without the build.yaml file. In the lib folder I did not get it to work without the build.yaml file, but with it even the lib folder produced the main.reflectable.dart file. With that, I think I should get Reflectable to work in a real project. Thanks for your time!

@eernstg
Copy link
Contributor

eernstg commented Jul 5, 2018

Cool, thank you!

@nareshdb
Copy link

In my case, I was always getting The Flutter SDK is not available with 'pub run '
When I followed @zoechi 's suggestion flutter packages pub run <bla bla>, I got no output for a long time so I killed the process.
Then without doing anything else, I ran pub run <bla bla> and it worked. 😆 🙌

@JPinkstonSaatva
Copy link

JPinkstonSaatva commented Aug 1, 2019

@nareshdb What test library do you have in your dev_dependencies? In order for flutter pub run <bla bla> to work, you need to be using flutter_test. If pub run <bla bla> is working you are most likely using test and not flutter_test. Hope this helps.

Screen Shot 2019-08-01 at 2 42 50 PM

@Bozayi
Copy link

Bozayi commented Mar 5, 2021

Your project is probably showing on your global dart installation, not on [path-your-flutter-SDK]/flutter/bin/dart. Check your flutter dart path.
$ which flutter dart
if it's looking like this,

  [/path-to-flutter-sdk]/bin/flutter
  /usr/local/bin/dart

make sure that your flutter and dart SDK show on the same path like this.

[/path-to-flutter-sdk]/bin/flutter
 [/path-to-flutter-sdk]/bin/dart

@github-actions
Copy link

github-actions bot commented Aug 4, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants