LoginSignup
6
1

More than 5 years have passed since last update.

もしもFlutterアプリが古くてビルドが通らなかったら

Posted at

Flutterは進展著しいので、せっかくGithubで参考になりそうなアプリを見つけたのにビルドが通らなくて残念!といった状況がしばらくありそうです。ちょっと手直しすれば動くかも、というのをまとめておきます。

現バージョンはFlutter v0.2.8 ( Beta 2)です。

gradleのバージョンが古い

2017年12月頃までに作成されたプロジェクトは、古いバージョンのGradleを使用することになっていて、以下のエラーメッセージを表示しビルドに失敗します。

* Error running Gradle:
Exit code 1 from: /path_to/your_project/android/gradlew app:properties:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
Finished with error: Please review your Gradle project setup in the android/ folder.
   > com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 25s

以下のURLにある手順に従ってbuild.gradleなどを修正します。
https://github.com/flutter/flutter/wiki/Updating-Flutter-projects-to-Gradle-4.1-and-Android-Studio-Gradle-plugin-3.0.1

そもそもgradleを使ってない

2017年2月頃までに作成されたプロジェクトは、Androidのビルドにgradleを使用しておらず、以下のエラーメッセージを表示しビルドに失敗します。

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Finished with error: The build process for Android has changed, and the current project configuration
is no longer valid. Please consult

  https://github.com/flutter/flutter/wiki/Upgrading-Flutter-projects-to-build-with-gradle

for details on how to upgrade the project.

メッセージのURLにある手順に従ってプロジェクトを更新します。
https://github.com/flutter/flutter/wiki/Upgrading-Flutter-projects-to-build-with-gradle

flutter.yamlがある

2017年1月頃までに作成されたプロジェクトには、直下にflutter.yamlがあり、flutter packages getを実行すると、以下のようなエラーを出力して失敗します。

Please merge your flutter.yaml into your pubspec.yaml.

We have changed from having separate flutter.yaml and pubspec.yaml
files to having just one pubspec.yaml file. Transitioning is simple:
add a line that just says "flutter:" to your pubspec.yaml file, and
move everything from your current flutter.yaml file into the
pubspec.yaml file, below that line, with everything indented by two
extra spaces compared to how it was in the flutter.yaml file. Then, if
you had a "name:" line, move that to the top of your "pubspec.yaml"
file (you may already have one there), so that there is only one
"name:" line. Finally, delete the flutter.yaml file.

For an example of what a new-style pubspec.yaml file might look like,
check out the Flutter Gallery pubspec.yaml:
https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/pubspec.yaml

Process finished with exit code 1
flutter.yaml
name: yourapp
uses-material-design: true

pubspec.yamlにマージしてflutter.yamlを削除します。

pubspec.yaml
name: yourapp
flutter:
  uses-material-design: true

プロパティやメソッドがない

改名されている場合がほとんどじゃないかと思います。JetBrains系IDEならCommand(Ctrl)+クリックでソースにとんでみて、まずは似たような名前(意図)のものを探してみるのが手っ取り早そう。

例)

以前 現在
State#config State#widget

クラスがない

これも改名されているパターンかな?APIドキュメントで、それらしいクラスを探してrenameしてみたら、案外すんなり通っちゃうかも。

例)

以前 現在
ScrollableList ListView

型があいまい

Dart 2への移行によるものですが、型チェックが厳格になって、いままで通っていた箇所でエラーが起きてる場合があります。

例)

E/flutter (23032): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (23032): type 'List<dynamic>' is not a subtype of type 'List<Map<String, dynamic>>' where
E/flutter (23032):   List is from dart:core
E/flutter (23032):   List is from dart:core
E/flutter (23032):   Map is from dart:core
E/flutter (23032):   String is from dart:core

Dart's Type System (Don’t use a dynamic list as a typed list)

指摘に従って型宣言したりして回避します。

deprecated

ビルドも通るのでとりあえず放置で問題ないとは思いますが、JetBrains系IDEならCommand(Ctrl)+クリックでソースにとべば、簡単に代替方法が確認できます。

例)

json.dat
const JsonCodec json = const JsonCodec();
@Deprecated("Use json instead")
const JsonCodec JSON = json;
6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1