srawlins / timezone

Time zone database and time zone aware DateTime object for Dart.
BSD 2-Clause "Simplified" License
102 stars 54 forks source link

ProcessException: The system cannot find the file specified during `tool/get` #60

Closed D-Elyes closed 1 year ago

D-Elyes commented 4 years ago

Hello, i encounter this error when running flutter pub run tool/get -s 2019c

INFO: 2020-03-30 11:48:40.367549: Creating temp directory INFO: 2020-03-30 11:48:40.386498: Temp directory created: C:\Users\edoudech\AppData\Local\Temp\1\tzdata-a107c7fb-726b-11ea-97e5-48f17f21bc99 INFO: 2020-03-30 11:48:40.386498: Downloading timezone data INFO: 2020-03-30 11:48:41.181374: Unpacking timezone data: C:\Users\edoudech\AppData\Local\Temp\1\tzdata-a107c7fb-726b-11ea-97e5-48f17f21bc99\tzdata2019c.tar.gz INFO: 2020-03-30 11:48:41.360893: Creating zic directory INFO: 2020-03-30 11:48:41.362886: Compiling timezone data with zic compiler INFO: 2020-03-30 11:48:41.362886: - africa CreateProcessW failed 2 INFO: 2020-03-30 11:48:41.368871: Cleaning up temporary directories Unhandled exception: ProcessException: The system cannot find the file specified.

Command: zic -d C:\Users\edoudech\AppData\Local\Temp\1\tzdata-a107c7fb-726b-11ea-97e5-48f17f21bc99\zic C:\Users\edoudech\AppData\Local\Temp\1\tzdata-a107c7fb-726b-11ea-97e5 -48f17f21bc99\africa

0 zic (file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/timezone-0.5.6/tool/get.dart:80:18)

#1 main (file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/timezone-0.5.6/tool/get.dart:122:13) #2 _startIsolate. (dart:isolate-patch/isolate_patch.dart:299:32) #3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12) pub finished with exit code 255
jamesncl commented 4 years ago

This is because the tool which builds the timezone database relies on an application called zic, which is not included in Windows. So, as far as I know, this is a Windows only issue.

Here's what I did to work around the issue. On Windows 10, install / fire up Ubuntu on Windows Subsystem for Linux (WSL). Then in the ubuntu shell window:

Install Dart and add to PATH

sudo apt-get update
sudo apt-get install apt-transport-https
sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
sudo apt-get update
sudo apt-get install dart
echo 'export PATH="$PATH:/usr/lib/dart/bin"' >> ~/.profile

Close the Ubuntu / WSL window, and open it up again, so the PATH changes are applied.

Clone the timezone repo and run the tool

git clone https://github.com/srawlins/timezone.git
cd timezone
pub run tool/get -s 2020a

Copy files to Windows file system

The timezone databases are generated and stored in lib/data in the timezone folder on WSL, so copy them from the WSL filesystem to your flutter project on your Windows file system. I chose to put them in a folder called assets in the root of my project:

mv lib/data/2020a* /mnt/d/code/my-flutter-project/assets/timezone/

Include the database as an asset

Add the database asset in pubsepc.yaml:

  assets:
    - assets/timezone/2020a.tzf

Initialise the database

The rest should work as per the instructions for the timezone package. For example, initialise the library:

var byteData = await rootBundle.load('assets/timezone/2020a.tzf');
initializeDatabase(byteData.buffer.asUint8List());
dJani97 commented 3 years ago

A link to this guide should be totally added to the documentation.