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

flutter: init 1.12.13+hotfix.8 #76420

Merged
merged 2 commits into from Mar 29, 2020
Merged

flutter: init 1.12.13+hotfix.8 #76420

merged 2 commits into from Mar 29, 2020

Conversation

babariviere
Copy link
Member

@babariviere babariviere commented Dec 24, 2019

Motivation for this change

Fix issue #36759.

There is still some changes to do. I will note them as comments.

For now, it's using dart from the source, maybe I need to use dart from nixpkgs ?

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Copy link
Member

@ericdallo ericdallo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I tried both on nixos-rebuild and nix-env

@babariviere
Copy link
Member Author

image

I tried both on nixos-rebuild and nix-env

Sorry I will fix that, does it work after running:

mkdir -p ~/.cache/flutter

@ericdallo
Copy link
Member

Yeah, it works after the mkdir -p ~/.cache/flutter!

Maybe a patch somewhere to change this cache dir?

@babariviere
Copy link
Member Author

I have fixed it with this new patch 🙂

Copy link
Member

@ericdallo ericdallo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works very well, congratulations for the work @babariviere

@kolaente
Copy link
Member

Running flutter packages get on an existing project (copied from another machine) gets me this error:

$ flutter packages get      
Could not parse "1.12.13+hotfix.51.12.13+hotfix.5".                     
package:pub_semver/src/version.dart 116:7                                           new Version.parse
package:pub/src/sdk/flutter.dart 29:17                                              FlutterSdk.version
package:pub/src/solver/package_lister.dart 413:53                                   PackageLister._matchesSdkConstraint
package:pub/src/solver/package_lister.dart 200:14                                   PackageLister.incompatibilitiesFor
===== asynchronous gap ===========================                      
package:pub/src/solver/version_solver.dart 386:42                                   VersionSolver._choosePackageVersion
===== asynchronous gap ===========================                      
package:pub/src/solver/version_solver.dart 97:22                                    VersionSolver.solve
===== asynchronous gap ===========================                      
package:pub/src/solver.dart 35:10                                                   resolveVersions.<fn>
package:pub/src/log.dart 378:18                                                     progress
package:pub/src/solver.dart 32:10                                                   resolveVersions
package:pub/src/entrypoint.dart 217:24                                              Entrypoint.acquireDependencies
package:pub/src/command/get.dart 41:23                                              GetCommand.run
package:args/command_runner.dart 197:27                                             CommandRunner.runCommand
package:pub/src/command_runner.dart 171:39                                          PubCommandRunner.runCommand.<fn>
dart:async                                                                          new Future.sync
package:pub/src/utils.dart 109:12                                                   captureErrors.<fn>
dart:async                                                                          runZoned
package:pub/src/utils.dart 126:5                                                    captureErrors
package:pub/src/command_runner.dart 171:13                                          PubCommandRunner.runCommand
===== asynchronous gap ===========================                      
package:pub/src/command_runner.dart 119:11                                          PubCommandRunner.run
/b/s/w/ir/cache/builder/src/third_party/dart/third_party/pkg/pub/bin/pub.dart 8:22  main
This is an unexpected error. Please run                                 
                                                                        
    pub --trace '--verbosity=warning' get --no-precompile               
                                                                        
and include the logs in an issue on https://github.com/dart-lang/pub/issues/new
Running "flutter pub get" in app...                                     
pub get failed (65; and include the logs in an issue on https://github.com/dart-lang/pub/issues/new)

Is this an issue with my setup or an issue with the packaged version?

I've put flutter in my configuration.nix and installed it in my user env.

@kolaente
Copy link
Member

I've checked the project clean out from git and it worked, so this seems to be an issue with my old project files.

Thanks for packaging this!

@babariviere
Copy link
Member Author

babariviere commented Dec 27, 2019

Hi, I am happy that you have a solution ! I will still look if there is an issue that I might have to patch !
If you have still your old files, can you show me your .packages in your project root ?

@kolaente
Copy link
Member

@babariviere Sure, this is my old .packages file:

# Generated by pub on 2019-03-29 17:50:33.213957.
after_layout:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/after_layout-1.0.7/lib/
analyzer:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.34.3/lib/
archive:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/archive-2.0.8/lib/
args:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.5.1/lib/
async:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib/
boolean_selector:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.4/lib/
charcode:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.2/lib/
collection:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.14.11/lib/
convert:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/convert-2.1.1/lib/
crypto:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-2.0.6/lib/
csslib:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/csslib-0.14.6/lib/
cupertino_icons:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/cupertino_icons-0.1.2/lib/
dart_config:file:///home/user/opt/flutter/.pub-cache/git/dart_config-a7ed88a4793e094a4d5d5c2d88a89e55510accde/lib/
datetime_picker_formfield:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/datetime_picker_formfield-0.1.8/lib/
flutter:file:///home/user/opt/flutter/packages/flutter/lib/
flutter_launcher_icons:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_launcher_icons-0.6.1/lib/
flutter_secure_storage:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.1.1/lib/
flutter_test:file:///home/user/opt/flutter/packages/flutter_test/lib/
flutter_typeahead:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_typeahead-1.2.1/lib/
front_end:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.9+1/lib/
glob:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/glob-1.1.7/lib/
html:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/html-0.13.4+1/lib/
http:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0/lib/
http_multi_server:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.0.5/lib/
http_parser:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.3/lib/
image:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/image-2.0.7/lib/
intl:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/intl-0.15.7/lib/
io:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/io-0.3.3/lib/
js:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.1+1/lib/
json_rpc_2:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/json_rpc_2-2.0.9/lib/
kernel:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.9+1/lib/
keyboard_visibility:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/keyboard_visibility-0.5.2/lib/
logging:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/logging-0.11.3+2/lib/
matcher:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.3+1/lib/
meta:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.1.6/lib/
mime:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/mime-0.9.6+2/lib/
multi_server_socket:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/multi_server_socket-1.0.2/lib/
node_preamble:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/node_preamble-1.4.4/lib/
package_config:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/package_config-1.0.5/lib/
package_resolver:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/package_resolver-1.0.9/lib/
path:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/path-1.6.2/lib/
pedantic:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/pedantic-1.4.0/lib/
petitparser:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/petitparser-2.1.1/lib/
plugin:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/plugin-0.2.0+3/lib/
pool:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/pool-1.4.0/lib/
pub_semver:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/pub_semver-1.4.2/lib/
quiver:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/quiver-2.0.1/lib/
shelf:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/shelf-0.7.4/lib/
shelf_packages_handler:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/shelf_packages_handler-1.0.4/lib/
shelf_static:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/shelf_static-0.2.8/lib/
shelf_web_socket:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-0.2.2+4/lib/
sky_engine:file:///home/user/opt/flutter/bin/cache/pkg/sky_engine/lib/
source_map_stack_trace:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/source_map_stack_trace-1.1.5/lib/
source_maps:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/source_maps-0.10.8/lib/
source_span:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.5.4/lib/
stack_trace:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3/lib/
stream_channel:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.8/lib/
string_scanner:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.4/lib/
term_glyph:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.1.0/lib/
test:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/test-1.5.3/lib/
test_api:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.2/lib/
test_core:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/test_core-0.2.1+1/lib/
typed_data:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.6/lib/
utf:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/utf-0.9.0+5/lib/
vector_math:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/
vm_service_client:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/vm_service_client-0.2.6/lib/
watcher:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+10/lib/
web_socket_channel:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-1.0.9/lib/
xml:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/xml-3.3.1/lib/
yaml:file:///home/user/opt/flutter/.pub-cache/hosted/pub.dartlang.org/yaml-2.1.15/lib/
vikunja_app:lib/

Some more info: I had flutter manually installed in /home/user/opt/flutter on my old machine, which probably explains why it looks there. Also, as you can probably tell by the generation date at the beginning, the file was generated back in march this year, and I did not do much flutter since then. I could very well be the case the flutter tooling/format has changed a lot since then.

@babariviere
Copy link
Member Author

Thank you ! I will look into it

@kolaente
Copy link
Member

kolaente commented Jan 1, 2020

I tried building my app, after fixing some issues related to changed library versions, the build now fails with this:

AAPT err(Facade for 1549942191): $ANDROID_HOME/build-tools/27.0.3/aapt2: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
AAPT err(Facade for 657220039): $ANDROID_HOME/build-tools/27.0.3/aapt2: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
AAPT err(Facade for 1437643150): $ANDROID_HOME/build-tools/27.0.3/aapt2: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
Slave 1437643150 failed to start                                        
java.lang.RuntimeException: AAPT slave failed to start. Please make sure the current build tools (located at $ANDROID_HOME/build-tools/27.0.3/aapt2) are not corrupted.

And when checking the aapt binary with ldd:

$ ldd $ANDROID_HOME/build-tools/27.0.3/aapt2
	linux-vdso.so.1 (0x00007fff105cf000)
	libc++.so => $ANDROID_HOME/build-tools/27.0.3/lib64/libc++.so (0x00007fa8bb336000)
	libz.so.1 => not found
	libpthread.so.0 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libpthread.so.0 (0x00007fa8bb315000)
	libm.so.6 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libm.so.6 (0x00007fa8bb17f000)
	libgcc_s.so.1 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libgcc_s.so.1 (0x00007fa8baf69000)
	libc.so.6 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libc.so.6 (0x00007fa8badb3000)
	/lib64/ld-linux-x86-64.so.2 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib64/ld-linux-x86-64.so.2 (0x00007fa8bb66d000)
	librt.so.1 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/librt.so.1 (0x00007fa8bada7000)
	libdl.so.2 => /nix/store/wx1vk75bpdr65g6xwxbj4rw0pk04v5j3-glibc-2.27/lib/libdl.so.2 (0x00007fa8bada2000)

We can see it looks like it is missing libz.so.1. I'll try to find the package for it later.

I guess this midght be fixed by patching aapt binary, but I'm not sure how to do that since it is not installed through nix.

At this point, I'm not sure if this is an issue with my setup or the flutter package. I installed the android sdk through android studio's package manager. I'm using Android Studio v3.5.3.

For the curious, the flutter project I'm trying to compile can be found here: https://kolaente.dev/vikunja/app/src/branch/fix/updated-fixes
The branch I'm using to fix it is fix/updated-fixes.

Edit: The app is building in my CI, which is running in a docker container based on ubuntu, so the app itself is definitly working.

@babariviere
Copy link
Member Author

I will try to patch your issue, thanks for your report

@babariviere
Copy link
Member Author

I have a pushed a potential fix, can you try it ?

@kolaente
Copy link
Member

kolaente commented Jan 1, 2020

I have a pushed a potential fix, can you try it ?

It seems to work with the command line now, thanks!

On an interesting side note, the aapt2 binary in the v27 api sdk directory (the one from the error message in my previous comment) did still not work. I then updated the sdk version to v28 everywhere, and this worked.

Now I just need to figure out a way to get this working within android studio...

@babariviere
Copy link
Member Author

babariviere commented Jan 1, 2020

I have a pushed a potential fix, can you try it ?

It seems to work with the command line now, thanks!

On an interesting side note, the aapt2 binary in the v27 api sdk directory (the one from the error message in my previous comment) did still not work. I then updated the sdk version to v28 everywhere, and this worked.

Now I just need to figure out a way to get this working within android studio...

What's your issue with Android Studio ?

To make it work, I go to Settings > Flutter
I then select flutter path by reading file ${which flutter} and I put it in Android Studio.

Example:

$ which flutter-beta
/run/current-system/sw/bin/flutter-beta

$ cat /run/current-system/sw/bin/flutter-beta
#!/nix/store/xb062l4b76zyhq6grqf4iyfdikkpg8fl-bash-4.4-p23/bin/bash
export PUB_CACHE=${PUB_CACHE:-"$HOME/.pub-cache"}
/nix/store/9xyasfp1841bzkkaasp4vndjigijm13r-flutter-beta-1.12.13+hotfix.6-fhs-env/bin/flutter-beta-1.12.13+hotfix.6-fhs-env /nix/store/7vnqzs94ghismhfd19vv9gg3kgwx58fp-flutter-beta-1.12.13+hotfix.6-unwrapped/bin/flutter --no-version-check "$@"

# You need to copy path /nix/store/7vnqzs94ghismhfd19vv9gg3kgwx58fp-flutter-beta-1.12.13+hotfix.6-unwrapped in this case.

I don't know if I can fix it with this package but if I find a simpler way to do it, I will share it here.

@kolaente
Copy link
Member

kolaente commented Jan 1, 2020

Yeah, I've set that path which lets me build the project, but the build finishes with

Finished with error: Gradle build failed to produce an .apk file. It's likely that this file was generated under ./build, but the tool couldn't find it.

I get an apk which I could run, but it is not installed and started on my emulator.

There is an issue at flutter about this, it seems this is not related to the nixos build of flutter: flutter/flutter#44796

@babariviere
Copy link
Member Author

flutter clean doesn't fix this ?
I didn't have this issue so far.

@kolaente
Copy link
Member

kolaente commented Jan 1, 2020

flutter clean doesn't fix this ?
I didn't have this issue so far.

flutter clean did not help, but it turned out I did not specify a build flavour in my android studio run configuration. It works now.

Thanks for your help and patience!

@babariviere
Copy link
Member Author

flutter clean doesn't fix this ?
I didn't have this issue so far.

flutter clean did not help, but it turned out I did not specify a build flavour in my android studio run configuration. It works now.

Thanks for your help and patience!

No problem ! It's a pleasure to help you

@Rizary
Copy link
Contributor

Rizary commented Jan 5, 2020

@babariviere using this package means I have to build my flutter project using android studio? Is it possible to use other IDE like emacs (with https://github.com/amake/flutter.el for example)

@babariviere
Copy link
Member Author

@Rizary You can use it to build outside of Android Studio.
They are both independent.

@jmackie
Copy link

jmackie commented Jan 7, 2020

Nice work @babariviere - so glad to see this finally coming to Nix!

I'm going to have a play around with it over the next few days, but one thing I've picked up already: flutter create relies on unzip, so you probably want to add that to the targetPkgs of the fhs env.

In fact, it might be a good idea to make sure all the required tools (listed at the top of the install docs https://flutter.dev/docs/get-started/install/linux) are available 👍

@babariviere babariviere deleted the flutter-init branch March 29, 2020 15:14
@babariviere
Copy link
Member Author

Thank you !

@GRBurst
Copy link
Contributor

GRBurst commented Mar 29, 2020

Amazing! Thank you very much @babariviere

@nioncode
Copy link
Member

nioncode commented Apr 4, 2020

@babariviere Thank you very much for this PR! I created a nix-shell based on the merge commit and flutter itself works great, but I have a problem with Android Studio: the built-in Terminal always closes immediately after opening it, so it is unusable (which also prevents me from using adb since the cmdline adb version seems to be incompatible with the studio one and they kill each other all the time, losing the adb wifi connection to the device).

Do you have a working Android Studio terminal that works with your flutter packages (flutter stable channel)? If so, please let me know the version of Android Studio (or even better the nixpkgs commit ref) you are using, since I have been fighting with this without success.

My nix-shell:

{ pkgs ? import <nixpkgs> {} }:

  # Use a pinned version of the first merged flutter release.
  let
  flutter = (import (builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/1992768157d7456748ec28e01c8952cf09b53fbf.tar.gz";
    # Hash obtained using `nix-prefetch-url --unpack <url>`
    sha256 = "1mqdgyrgi2b0z77366x0b2js1xzj2j7s4ww33p6gzgp4kvw9yzny";
    }) {}).flutterPackages.stable;
  in

  # We use the version of android studio that is in the flutter derivation, since
  # all other versions that we tried had a crashing dart analyzer.
  let
  android-studio = (import (builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/1992768157d7456748ec28e01c8952cf09b53fbf.tar.gz";
    # Hash obtained using `nix-prefetch-url --unpack <url>`
    sha256 = "1mqdgyrgi2b0z77366x0b2js1xzj2j7s4ww33p6gzgp4kvw9yzny";
    }) {}).androidStudioPackages.stable;
  in

  pkgs.stdenv.mkDerivation {
    name = "env";
    buildInputs = with pkgs; [
      flutter
      android-studio
    ];

    shellHook=''
      echo -e "Path to the Flutter SDK to enter in android-studio:"
      echo -e "\e[0;34m${flutter.unwrapped}\e[m"
      echo -e "It is advised to add \e[1;34mprograms.adb.enable = true;\e[m to your nix configuration"
      echo -e "Furthermore, add your user to the \e[1;34madbusers\e[m group."
    '';
  }

@babariviere
Copy link
Member Author

Hey @nioncode, I have tested with my Android Studio. I don't have this issue.
My version are:

  • Android Studio 3.5.3
  • adb 1.0.40
  • flutter 1.12.13+hotfix.8

Can you test if you have the same issue with this repository ? https://github.com/babariviere/flutter-nix-hello-world
I've updated it to use the version from flutter on nixpkgs master

@nioncode
Copy link
Member

nioncode commented Apr 4, 2020

@babariviere thanks for the fast response. I can reproduce the problem with your repository.

With Android Studio 3.5.3:

  • good: the built-in Terminal in Android Studio works
  • bad: the Dart Analyzer crashes on startup with Android Studio showing the following error message Flutter device daemon #1: process exited during startup. Exit code: 139, stderr:. This makes navigation the code basically unusable, since I cannot jump to definitions etc.

With Android Studio 3.6.2:

  • good: the Dart Analyzer works again
  • bad: the built-in Terminal does not work and always immediately closes when I try to open it. This seems to have nothing to do with your flutter package though, but seems to be a defect in Android Studio somehow, since it also happens without using your flutter packages.

I thought you might be using an Android Studio version > 3.5.3, since for me the dart analyzer always crashed on the older versions and I hoped this is a known issue, but apparently this only happens on my system. Do you have any idea how I could debug this?

@babariviere
Copy link
Member Author

@nioncode have you seen this comment #76420 (comment) ? It might solve your issue

@nioncode
Copy link
Member

nioncode commented Apr 4, 2020

@babariviere I don't think this applies to my issue. Android Studio v3.5.3 should work without problems with flutter stable v1.12.13+hotfix.8 (which is proven since you run exactly this version), but in my case the dart analyzer just crashes all the time.

And Android Studio v3.6.2 at least works correctly for regular usage with flutter for me (I'm using com.android.tools.build:gradle:3.5.0 in my project though, so this is probably why the mentioned bug does not affect me).

@nioncode
Copy link
Member

nioncode commented Apr 4, 2020

@babariviere ok, I think I found a few interesting things. First: on Android Studio v3.5.3, if I go into the Terminal and run flutter doctor, I immediately get a segfault. strace shows that this happens after opening /usr/lib/libc.so, so there might be some libc incompatibilities?

However, I could make Android Studio v3.6.2 successfully open the terminal by changing the Terminal settings in Settings -> Tools -> Terminal -> Shell Path from the previous value of /nix/store/rn5dmlak31vg3fjv94y8gwy1pn6vbdab-bash-interactive-4.4-p23/bin/bash to /usr/bin/bash.

Would you mind having a look what your Shell Path setting is? I don't really know what is 'right' to put there. However, when I run the shell with /usr/bin/bash, I then get a segfault when I run any command that is part of my system, but is not part of the nix-shell that I built (e.g. zsh, or even /run/current-system/sw/bin/strace). Other things like adb and flutter work fine though.

To me this looks to be some kind of incompatibilities between the binaries I have in the FHS env and the binaries I have on my system. Is this the expected behavior, because of the FHS env? I never experienced something like this before honestly.

@babariviere
Copy link
Member Author

You shouldn't change the bash path in Android Studio as it is set to the path of the bash inside the FHS env.

Can you try to install flutter globally ?

@nioncode
Copy link
Member

nioncode commented Apr 4, 2020

Hmm apparently it is not set to the path of bash of the FHS env for me, but to the global bash. That's why when i change the path to be the path in FHS env. When I follow the path for /usr/bin/bash, this is what I get:

bash-4.4$ which bash
/usr/bin/bash
bash-4.4$ ls -l /usr/bin/bash
lrwxrwxrwx 1 nobody nogroup 101 Jan  1  1970 /usr/bin/bash -> /nix/store/na57g8901p979dy8639khb0qrc1zj3aj-android-studio-stable-3.6.1.0-fhs-env-usr-target/bin/bash
bash-4.4$ ls -l /nix/store/na57g8901p979dy8639khb0qrc1zj3aj-android-studio-stable-3.6.1.0-fhs-env-usr-target/bin/bash
lrwxrwxrwx 1 nobody nogroup 77 Jan  1  1970 /nix/store/na57g8901p979dy8639khb0qrc1zj3aj-android-studio-stable-3.6.1.0-fhs-env-usr-target/bin/bash -> /nix/store/kp60cyq5iig35gzp7l2pr0ilxxa4m919-bash-interactive-4.4-p23/bin/bash

So in the end it points to kp60cyq5iig35gzp7l2pr0ilxxa4m919-bash-interactive-4.4-p23 instead of the default rn5dmlak31vg3fjv94y8gwy1pn6vbdab-bash-interactive-4.4-p23.
As soon as I use the default value, the terminal breaks, but when I use /usr/bin/bash, everything works fine (except that I cannot call programs outside the FHS, but this might be expected?).

@babariviere
Copy link
Member Author

It's weird, I can't reproduce your issue 😅 /usr/bin/bash points to the right user env bash apparently.
And yes you cannot use programs of the FHS user env.

@nioncode
Copy link
Member

nioncode commented Apr 4, 2020

At least I got a working terminal again by using /usr/bin/bash, thanks for helping me debug this probably completely unrelated problem 👍

@babariviere
Copy link
Member Author

no problem 👍

@ericdallo
Copy link
Member

Hey @babariviere, Im using this and it's working great.
To use flutter and the lsp-dart in emacs, I need to specify the path for the dart-sdk. I notified that in somewhere has the dart-sdk from flutter-sdk.

/nix/store/bxyz9r12vvlg2n37kmpk2rqjxi4s70gj-flutter-stable-1.12.13+hotfix.8-unwrapped/bin/cache/dart-sdk

But the flutter executable is in other folder than that:

/nix/store/p3c9ixrpwrwnlslnlz5hz0rbjbjml1nh-flutter-stable-1.12.13+hotfix.8/bin/flutter

Do you know how can I access this unwrapped folder dynamically to get the dart-sdk?

If some way I could access via a symlink from the flutter bin dir, it will solve this

@babariviere
Copy link
Member Author

Hey @ericdallo, you can find the "unwrapped" path just by opening the file /nix/store/p3c9ixrpwrwnlslnlz5hz0rbjbjml1nh-flutter-stable-1.12.13+hotfix.8/bin/flutter. The binary is just a wrapper that set some environment variables before call the real flutter binary.
Otherwise, I think you could use a nix-store command to get the dependency path. If you need it, I will give it you but I don't remember the command right now.

@tgunnoe
Copy link
Contributor

tgunnoe commented Apr 13, 2020

I'm still having issues with the { android_sdk.accept_license: true } option. I've tried putting it in ~/.config/nixpkgs/config.nix, also like this:

with import ../nixpkgs {
  config = {
    android_sdk.accept_license = true;
  };
};

mkShell {
  buildInputs = [
    flutterPackages.beta
    androidsdk_9_0
  ];

  shellHook=''
      echo -e "\e[0;32mWelcome to Project Development\e[m"
      echo -e "Path to the Flutter SDK to enter in android-studio:"
      echo -e "\e[0;34m${flutterPackages.beta.unwrapped}\e[m"

      echo -e "It is advised to add \e[1;34mprograms.adb.enable = true;\e[m to your nix configuration"
      echo -e "Furthermore, add your user to the \e[1;34madbusers\e[m group."
  '';
  ANDROID_HOME = "${androidsdk_9_0}/libexec/android-sdk";
  #ANDROID_SDK_ROOT = "/home/janus/Android/Sdk";
  JAVA_HOME="${pkgs.jdk.home}";
  NIX_BUILD_SHELL = "${zsh}";

}

but flutter-beta doctor still prints it as unaccepted. Any ideas? I'd prefer it to be contained within shell.nix

Error below:

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    ✗ Android license status unknown.
      Try re-installing or updating your Android SDK Manager.
      See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed instructions.

@GRBurst
Copy link
Contributor

GRBurst commented Apr 14, 2020

this is usually solved by running flutter-beta doctor --android-licenses

@GRBurst
Copy link
Contributor

GRBurst commented Apr 14, 2020

@tgunnoe
just tried your example and indeed it does not work. however, I think this is more a problem with the androidsdk, in particular with sdkmanager. Running sdkmanager --licenses returns Error: Unknown argument --licenses, which is the same error flutter-beta doctor --android-licenses gives me. So flutter is just passing the argument to the sdkmanager.

By removing the androidsdk_9_0 stuff from your example, everything seems to work as expected

@tgunnoe
Copy link
Contributor

tgunnoe commented Apr 15, 2020

ah yes, but how then do you use androidsdk the nix way? without androidsdk_9_0 as above, i have to use android-studio to download the SDK and accept licenses, because it will default to /home/[user]/Android/Sdk/tools/bin/sdkmanager. I was assuming per the instructions further up in this thread that it could be done with ANDROID_HOME = "${androidsdk_9_0}/libexec/android-sdk"; while passing android_sdk.accept_license = true; to that package

@mpfaff
Copy link

mpfaff commented Apr 15, 2020

error: Package ‘flutter-beta-1.15.17’ in /nix/store/wjgdngf3sykb16kgj57iggrinlfcghgz-nixpkgs-20.09pre221549.7e07846d99b/nixpkgs/pkgs/development/compilers/flutter/flutter.nix:113 is not supported on ‘x86_64-darwin’, refusing to evaluate.

Are there any plans to support macOS?

@babariviere
Copy link
Member Author

@tgunnoe can you show me the content of ../nixpkgs directory ? It looks like it might be the issue. Otherwise, you can take a look at my example repo here: https://github.com/babariviere/flutter-nix-hello-world. It has a working default.nix/shell.nix file.

@mpfaff I could do it, but I have no Mac to test it. If you can help me with testing, I will gladly do it.

@tgunnoe
Copy link
Contributor

tgunnoe commented Apr 15, 2020

@babariviere It was just a cloned version of github.com/nixos/nixpkgs, but i changed it back to <nixpkgs> with the same result

@mpfaff
Copy link

mpfaff commented Apr 15, 2020

@babariviere I don't have much experience with Nix yet, but I'd be happy to help.

@tgunnoe
Copy link
Contributor

tgunnoe commented Apr 16, 2020

@tgunnoe can you show me the content of ../nixpkgs directory ? It looks like it might be the issue. Otherwise, you can take a look at my example repo here: https://github.com/babariviere/flutter-nix-hello-world. It has a working default.nix/shell.nix file.

@mpfaff I could do it, but I have no Mac to test it. If you can help me with testing, I will gladly do it.

@babariviere I tried the example repository as well with the same result (flutter doctor printing ✗ Android license status unknown. the example repo you updated doesnt have android_sdk.accept_license = true; either; I was unsuccessful in my attempt to add it (status unknown again). However,

$ flutter doctor --android-licenses

produces:

A newer version of the Android SDK is required. To update, run:
/nix/store/cvmb6cmwdg5dbvyir5fj3l28j7nwgzrs-androidsdk/libexec/android-sdk/tools/bin/sdkmanager --update

which, when ran, shows the license accepting document properly, but yields:

Accept? (y/N): y
Warning: Failed to read or create install properties file.
done

Because of course, its not writable here.

I'm trying not to abandon the nix way and using android-studio to download/accept licenses.

@tgunnoe
Copy link
Contributor

tgunnoe commented Apr 17, 2020

I think i need to provide an override for the derivation androidsdk_9_0 and set android_sdk.accept_license = true; there, since i'm calling the derivation by using ANDROID_HOME = "${androidsdk_9_0}/libexec/android-sdk";

If I don't use set ANDROID_HOME as above, it finds my SDK at /home/tgunnoe/Android/Sdk.
with androidsdk_9_0 command flutter doctor --verbose shows the SDK versions as: Platform android-28, build-tools 28.0.3, and by using /home/tgunnoe/Android/Sdk the versions are shown as Platform android-29, build-tools 29.0.3

I believe there is a version mismatch with license accepting?

@tgunnoe
Copy link
Contributor

tgunnoe commented Apr 17, 2020

Ok I've reached the end of my investigation. You can't accept the license through nix configuration, so flutter doctor will always report the license status as unknown. the android_sdk.accept_license value just throws an error if false; it doesnt write as accepted in the nix store's androidsdk (like in androidsdk_9_0). Therefore, flutter will never see the license as accepted and the usual way to address the license issue flutter doctor --android-licenses does nothing as it tries to write to the nix store path, which is of course read only.

Here's the relevant check, but this does not write the license as accepted in the SDK

androidsdk = if !licenseAccepted then throw ''
You must accept the Android Software Development Kit License Agreement at
https://developer.android.com/studio/terms
by setting nixpkgs config option 'android_sdk.accept_license = true;'

Here are the relevant issues I found:
#23910 (ongoing issue)
#28348 (comment) (issue plus this comment describes the weakness of android_sdk.accept_license config option)
#75603 (Larger android nonfree licensing issue)

For now, I will use my home path to store the SDK and accept the license there, or see if i can work around flutter with license status unknown.

@matthewbauer
Copy link
Member

Ok I've reached the end of my investigation. You can't accept the license through nix configuration, so flutter doctor will always report the license status as unknown. the android_sdk.accept_license value just throws an error if false; it doesnt write as accepted in the nix store's androidsdk (like in androidsdk_9_0). Therefore, flutter will never see the license as accepted and the usual way to address the license issue flutter doctor --android-licenses does nothing as it tries to write to the nix store path, which is of course read only.

Here's the relevant check, but this does not write the license as accepted in the SDK

androidsdk = if !licenseAccepted then throw ''
You must accept the Android Software Development Kit License Agreement at
https://developer.android.com/studio/terms
by setting nixpkgs config option 'android_sdk.accept_license = true;'

Here are the relevant issues I found:
#23910 (ongoing issue)
#28348 (comment) (issue plus this comment describes the weakness of android_sdk.accept_license config option)
#75603 (Larger android nonfree licensing issue)

For now, I will use my home path to store the SDK and accept the license there, or see if i can work around flutter with license status unknown.

This probably happens because the SDK in the store is read only and the dialog wants to write to it. Do you know what format this "accepted license" thing is (output of flutter doctor --android-licenses)

@tgunnoe
Copy link
Contributor

tgunnoe commented May 26, 2020

Do you know what format this "accepted license" thing is

@matthewbauer sorry for the late reply. As I mentioned yes it's read-only and flutter does want to write to that directory. the end result of flutter doctor --android-licenses is the y/n texts of the android sdk licenses you typically get when you run sdkmanager --licenses

This comment #23910 (comment) has solved the mystery for me. android_sdk.accept_license = true; doesnt apply if you don't build your project with the nix derivation androidenv.buildApp, which makes sense to me, and it goes back to the problems with the nonfree licensing of the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet