flutter build apk --releaseのときだけ、以下のエラーが出てapkが作れない問題でハマりました。
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':generateReleaseRFile'.
> Could not resolve all files for configuration ':releaseRuntimeClasspath'.
> Could not find com.google.firebase:firebase-bom:25.12.0.
Searched in the following locations:
- https://storage.googleapis.com/download.flutter.io/com/google/firebase/firebase-bom/25.12.0/firebase-bom-25.12.0.pom
- https://storage.googleapis.com/download.flutter.io/com/google/firebase/firebase-bom/25.12.0/firebase-bom-25.12.0.jar
Required by:
project :
> Could not find com.google.firebase:firebase-core:.
Required by:
project :
> Could not find androidx.annotation:annotation:1.1.0.
Searched in the following locations:
- https://storage.googleapis.com/download.flutter.io/androidx/annotation/annotation/1.1.0/annotation-1.1.0.pom
- https://storage.googleapis.com/download.flutter.io/androidx/annotation/annotation/1.1.0/annotation-1.1.0.jar
Required by:
project :
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':javaPreCompileRelease'.
> Could not resolve all files for configuration ':releaseCompileClasspath'.
> Could not find com.google.firebase:firebase-bom:25.12.0.
Required by:
project :
> Could not find com.google.firebase:firebase-core:.
Required by:
project :
> Could not find androidx.annotation:annotation:1.1.0.
Required by:
project :
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
The plugin firebase_core could not be built due to the issue above.
解決方法
Stackoverflowを参考に、flutter build apk --profile
を一度実行すると、 --release
でもビルドできるようになりました。
謎い
追記:本当の解決方法
gradleを4.1.0から3.5.0にしたら解決しました。
使っていたFlutter 1.22.2 で新規プロジェクトを作成したら3.5.0だったので、どうやら安易に変更してはいけないようです。
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}