Fixing sign_in_with_apple-5.0.0/android/build.gradle' line: 27 > No signature of method: build_64irqtdfzeigcmyeqnd8owt8u.android() is applicable for argument types
This morning I upgraded my packages and my Android build started failing. Here's the error:
sign_in_with_apple-5.0.0/android/build.gradle' line: 27
* What went wrong:
A problem occurred evaluating project ':sign_in_with_apple'.
> No signature of method: build_64irqtdfzeigcmyeqnd8owt8u.android() is applicable for argument types: (build_64irqtdfzeigcmyeqnd8owt8u$_run_closure2) values: [build_64irqtdfzeigcmyeqnd8owt8u$_run_closure2@230b5009]
Googling it does not give any meaningful result but looking at the Issues on the GitHub project does: https://github.com/aboutyou/dart_packages/issues/378.
Apparently I have to upgrade Gradle. Here we go again. I am currently using:
- android/build.gradle:
classpath 'com.android.tools.build:gradle:4.1.0'
- android/gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
The post suggests 'com.android.tools.build:gradle:7.3.0' and gradle-7.5-all.zip. Let's see what's around:
Plugin version | Minimum required Gradle version |
---|---|
8.3 | 8.4 |
8.2 | 8.2 |
8.1 | 8.0 |
8.0 | 8.0 |
7.4 | 7.5 |
Let's use the latest to be done with it for a while. Also looking at https://services.gradle.org/distributions/ I can see that the file name is gradle-8.4-bin.zip.
I used:
- android/build.gradle:
classpath 'com.android.tools.build:gradle:8.3.0'
- android/gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
But I get this error:
> Could not resolve all files for configuration ':classpath'.
> Could not find com.android.tools.build:gradle:8.3.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/8.3.0/gradle-8.3.0.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/8.3.0/gradle-8.3.0.pom
Required by:
project :
Is 8.3.0 not available? Looking at https://mvnrepository.com/artifact/com.android.tools.build/gradle, it looks like 8.3 is only available in beta. Not sure if it's an official source but still, the error makes sense. The Android Developers page mentions version 8.2.0. So I switched to gradle:8.2.0 and now I am getting this error:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/anhtuan/git/flashcards/android/app/build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
Your current JDK is located in /Applications/Android Studio.app/Contents/jre/Contents/Home
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
Looking at https://developer.android.com/build/jdks and my settings in Android Studio, I don't see a way to set it up. Let's update Android Studio and see if it ships with a newer version of JRE. Here's what the Android Studio update popup states:
After the update, I run the compilation again. It seems to have fixed it and now I am getting the next error:
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
You are applying Flutter's main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/anhtuan/git/flashcards/android/build.gradle' line: 27
* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
> Could not create an instance of type com.android.build.api.variant.impl.ApplicationVariantImpl.
> Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.
* 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 767ms
Error: Gradle task assembleDebug failed with exit code 1
Exited (1).
Looks like there are multiple issues. The first one is about how Gradle is being set up. The second one is about updating some namespace configuration.
After I did everything they had asked in https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply, I ran the project and got this error:
% flutter run
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/anhtuan/git/flashcards/android/app/build.gradle' line: 71
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not get unknown property 'kotlin_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* 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 824ms
Running Gradle task 'assembleDebug'... 1,319ms
Error: Gradle task assembleDebug failed with exit code 1
So what I did instead was to rename the android folder to android_old, then run flutter create .
to recreate the android folder from scratch. Then I moved over my key files for Firestore and ran flutter run
. It worked!
On to the next error:
% flutter run
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
Checking the license for package Android SDK Platform 34 in /Users/anhtuan/Library/Android/sdk/licenses
License for package Android SDK Platform 34 accepted.
Preparing "Install Android SDK Platform 34 (revision: 3)".
"Install Android SDK Platform 34 (revision: 3)" ready.
Installing Android SDK Platform 34 in /Users/anhtuan/Library/Android/sdk/platforms/android-34
"Install Android SDK Platform 34 (revision: 3)" complete.
"Install Android SDK Platform 34 (revision: 3)" finished.
/Users/anhtuan/git/flashcards/android/app/src/debug/AndroidManifest.xml Error:
uses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in library [:fluttertoast] /Users/anhtuan/git/flashcards/build/fluttertoast/intermediates/merged_manifest/debug/AndroidManifest.xml as the library might be using APIs not available in 19
Suggestion: use a compatible library with a minSdk of at most 19,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="io.github.ponnamkarthik.toast.fluttertoast" to force usage (may lead to runtime failures)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in library [:fluttertoast] /Users/anhtuan/git/flashcards/build/fluttertoast/intermediates/merged_manifest/debug/AndroidManifest.xml as the library might be using APIs not available in 19
Suggestion: use a compatible library with a minSdk of at most 19,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="io.github.ponnamkarthik.toast.fluttertoast" to force usage (may lead to runtime failures)
* 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 5m 56s
Running Gradle task 'assembleDebug'... 357.2s
┌─ Flutter Fix ───────────────────────────────────────────────────────────────────────────────────────────────────┐
│ The plugin fluttertoast requires a higher Android SDK version. │
│ Fix this issue by adding the following to the file /Users/anhtuan/git/flashcards/android/app/build.gradle: │
│ android { │
│ defaultConfig { │
│ minSdkVersion 21 │
│ } │
│ } │
│ │
│ │
│ Following this change, your app will not be available to users running Android SDKs below 21. │
│ Consider searching for a version of this plugin that supports these lower versions of the Android SDK instead. │
│ For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1
Looks like in android/app/build.gradle, I have to replace minSdkVersion flutter.minSdkVersion
by 21 or higher. Indeed, mine used to be set to 23.
The next two errors are:
/Users/anhtuan/git/flashcards/android/app/src/debug/AndroidManifest.xml Error:
uses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in library [:fluttertoast] /Users/anhtuan/git/flashcards/build/fluttertoast/intermediates/merged_manifest/debug/AndroidManifest.xml as the library might be using APIs not available in 19
Suggestion: use a compatible library with a minSdk of at most 19,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="io.github.ponnamkarthik.toast.fluttertoast" to force usage (may lead to runtime failures)
FAILURE: Build failed with an exception.
and
The class is loaded from /Users/anhtuan/.gradle/caches/transforms-3/2ece6433a8ec3065ee1b823ef5a57766/transformed/jetified-kotlin-stdlib-1.9.10.jar!/kotlin/Unit.class
e: /Users/anhtuan/.pub-cache/hosted/pub.dev/file_saver-0.2.12/android/src/main/kotlin/com/incrediblezayed/file_saver/FileUtils.kt: (323, 21): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
The class is loaded from /Users/anhtuan/.gradle/caches/transforms-3/2ece6433a8ec3065ee1b823ef5a57766/transformed/jetified-kotlin-stdlib-1.9.10.jar!/kotlin/Unit.class
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':file_saver:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
> Compilation error. See log for more details
* 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 41s
Running Gradle task 'assembleDebug'... 42.2s
┌─ Flutter Fix ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin. │
│ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then update /Users/anhtuan/git/flashcards/android/build.gradle: │
│ ext.kotlin_version = '<latest-version>' │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1
But it is kind of odd that in android/bin, I see outdated copies of android/src. Even after running flutter clean
, android/bin does not get deleted:
% flutter clean
Cleaning Xcode workspace... 9.6s
Deleting build... 3.2s
Deleting .dart_tool... 1,835ms
Deleting Generated.xcconfig... 0ms
Deleting flutter_export_environment.sh... 0ms
Deleting Flutter.podspec... 0ms
Deleting .flutter-plugins-dependencies... 0ms
Deleting .flutter-plugins... 0ms
So I rename bin into bin_old and run flutter run
again. This time, it only complains about the Kotlin version.
In android/settings.gradle, I have id "org.jetbrains.kotlin.android" version "1.7.10" apply false
. On https://kotlinlang.org/docs/releases.html#release-details, it looks like the latest version is 1.9.23. Let's try that version.
And finally... it ran. It is a miracle!
When it was finally time to publish the app, I got this error from the Play Store:
Google Api Error: Invalid request - The Android App Bundle was signed with the wrong key. Found: SHA1: 50:..., expected: SHA1: 11:....
It turns out I had forgotten to restore the signing settings into android/app/build.gradle. It had been reverted back to:
android {
namespace "com.wafrat.flashcards"
...
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
I changed it to look like this:
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
namespace "com.wafrat.flashcards"
...
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}