Build error with map_view, flutter & gradle - android

I get a build error using flutter version 1.2.2 and map_view version 0.0.14.
I tried to use this code in build.gradle
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4'
I followed all the steps here https://pub.dartlang.org/packages/map_view#-readme-tab-
I have an api-key but get the following build error
Error running Gradle: ProcessException: Process “C:UsersAlmoit PCDesktopMyAppMapflutter_app2androidgradlew.bat” exited
abnormally:
Configure project :map_view
WARNING: The specified Android SDK Build Tools version (27.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove “buildToolsVersion ‘27.0.3’” from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
FAILURE: Build failed with an exception.
What went wrong: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.2.51 and higher. Project ‘android’ is using
version 1.1.2-4.
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 10s Command: C:UsersAlmoit
PCDesktopMyAppMapflutter_app2androidgradlew.bat app:properties
With flutter doctor, everything seems fine.
flutter doctor -v
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17763.437], locale en-AI)
• Flutter version 1.2.1 at C:flutter
• Framework revision 8661d8aecd (10 weeks ago), 2019-02-14 19:19:53 -0800
• Engine revision 3757390fa4
• Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = C:Sdk
• Java binary at: C:Program FilesAndroidAndroid Studiojrebinjava
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.
[√] Android Studio (version 3.3)
• Android Studio at C:Program FilesAndroidAndroid Studio
• Flutter plugin version 33.4.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
[√] Connected device (1 available)
• SPH L520 • 2d81b4cf • android-arm • Android 4.4.2 (API 19)
• No issues found!
I searched it everywhere but can't find the answer. Please help me regarding this.

In your /android/build.gradle try increasing the version of the kotlin gradle plugin like so:
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0'
I read somewhere that flutter now only support version 1.3+.
I just tried it and now I can at least build my app for android.
PS: Since you are using an older version of flutter maybe the kotlin plugin will work with an older version as mentioned in the error messages:
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51'

Related

Flutter Android build not working in existing app on fresh Linux install

I have an existing flutter app (on GitHub here) that is working fine on my Windows 11 and MacOS machines, and was previously working on my Linux machine.
I installed a new distro a few days ago (OpenSUSE Tumbleweed) and now can't get the Android build to work. It fails with various errors depending on what stage of trying out different SDK version, etc., but the current error I'm on (after deleting everything and pulling it all down fresh) is:
Execution failed for task ':app:dependencies'.
> Could not resolve all dependencies for configuration ':app:androidApis'.
> Could not create task ':app:generateDebugLintModel'.
> java.lang.NullPointerException (no error message)
and also the below error a bit further down:
* Where:
Script '/home/jackv/bin/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 157
* What went wrong:
Execution failed for task ':tasks'.
> Could not create task ':generateLockfiles'.
> Process 'command '/home/jackv/Development/ComicWrap-F/android/gradlew'' finished with non-zero exit value 1
The weird thing is that creating a new project with flutter create --platform=android test_project results in a project that can build, but even if I go line by line and make sure all the build.gradle, .properties files, etc. are all the same it still doesn't work for my existing app.
I'm at a loss because the exact project files in the git repo were working totally fine on all platforms until I tried to start fresh on OpenSUSE.
My flutter doctor -v:
[✓] Flutter (Channel stable, 3.0.2, on openSUSE Tumbleweed 5.18.4-1-default, locale en_AU.UTF-8)
• Flutter version 3.0.2 at /home/jackv/bin/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision cd41fdd495 (10 days ago), 2022-06-08 09:52:13 -0700
• Engine revision f15f824b57
• Dart version 2.17.3
• DevTools version 2.12.2
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /home/jackv/Android/Sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /home/jackv/bin/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✗] Linux toolchain - develop for Linux desktop
✗ clang++ is required for Linux development.
It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/
✗ CMake is required for Linux development.
It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
✗ ninja is required for Linux development.
It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from https://github.com/ninja-build/ninja/releases
• pkg-config version 1.8.0
✗ GTK 3.0 development libraries are required for Linux development.
They are likely available from your distribution (e.g.: apt install libgtk-3-dev)
[✓] Android Studio (version 2021.2)
• Android Studio at /home/jackv/bin/android-studio
• Flutter plugin version 68.1.2
• Dart plugin version 212.5744
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] VS Code (version 1.68.1)
• VS Code at /usr/share/code
• Flutter extension version 3.42.0
[✓] Connected device (1 available)
• Linux (desktop) • linux • linux-x64 • openSUSE Tumbleweed 5.18.4-1-default
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 2 categories.
So turns out I didn't follow my own README, my local.properties file was missing the required adMob.appId entry.
I found the error by opening the AndroidManifest.xml project in Android Studio and looking at the errors in the "Merged" tab!

Android builds twice when using flutter flavours

I recently upgraded Flutter from 2.2.x to 2.10.x.
All was working fine on 2.2.x. On the new version, iOS works properly, but Android is having issues, as it seems to be running the app build.gradle twice: a first time with the proper flavour, a second time with no flavour.
The command is flutter run --flavor dev
The error I get is:
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
lib/main.dart:1
Reading env from: .env.dev
Starting a Gradle Daemon, 1 busy and 8 stopped Daemons could not be reused, use --status for details
> Configure project :app
Reading env from: .env
**************************
*** Missing .env file ****
**************************
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.6.2/userguide/command_line_interface.html#sec:command_line_warnings
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/guillaumeferron/Sites/TendoPay-App/android/app/build.gradle' line: 26
* What went wrong:
A problem occurred evaluating project ':app'.
> Cannot invoke method split() on null object
As you can see, there is a double "Reading env from", which should not happen. The first run works fine and goes through, but gets killed by the second run that fails.
The faulty line (which is not the issue itself, but a consequence of the dual run) is:
def flutterVersionCode = Double.parseDouble(project.env.get("APP_VERSION_ANDROID").split("\\.")[0]) * 10000 + Double.parseDouble(project.env.get("APP_VERSION_ANDROID").split("\\.")[1]) * 100 + Double.parseDouble(project.env.get("APP_VERSION_ANDROID").split("\\.")[2])
My flutter doctor is:
[✓] Flutter (Channel stable, 2.10.3, on macOS 12.2.1 21D62 darwin-x64, locale en-CA)
• Flutter version 2.10.3 at /Users/guillaumeferron/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 7e9793dee1 (3 weeks ago), 2022-03-02 11:23:12 -0600
• Engine revision bd539267b4
• Dart version 2.16.1
• DevTools version 2.9.2
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/guillaumeferron/Library/Android/sdk
• Platform android-31, build-tools 30.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.2)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 60.1.4
• Dart plugin version 212.5284.31
[✓] VS Code (version 1.65.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.36.0
[✓] Connected device (2 available)
• sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 99.0.4844.51
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
I've been looking around for a couple hours now, to no avail.
Flutter 2.10.x is not the problem itself, it is Android SDK 31 that is. Indeed, this only happens when I change the SDK version, unfortunately it is a required change in order to support the pub packages versions for 2.10.x.
If I println the different env variables I would get when having it as APP_VERSION_ANDROID="0.2.3" for instance, would be the first occurrence "0.2.3", and null the second, which triggers the error.
I have done all the flutter clean, flutter pub get, flutter pub upgrade, gradle clean, etc..
Any help would be appreciated, as I did not find anything relevant online, and lack the Android dev expertise to debug it myself.
Note: the flavour infrastructure I went for is https://medium.com/#animeshjain/build-flavors-in-flutter-android-and-ios-with-different-firebase-projects-per-flavor-27c5c5dac10b
For anyone stumbling upon this, after many hours of testing and research, what fixed it was to properly upgrade the Android version. So make sure that:
You open the project with Android Studio, and have all proper grade versions downloaded by going to File > Project Structure. Gradle should be v6.1.1 and Plugin v4.0.1
Set your kotlin version to v1.5.31 (https://docs.flutter.dev/release/breaking-changes/kotlin-version)
Have both your target and compile sdk version to 31
This should then work properly, and the gradle won't be executed a second time with no flavor.

Failed to apply plugin [id 'com.android.internal.version-check']

I am experiencing issues building an android application on flutter. The IOS app complies with no problems.
The issue seems to be along the lines of Gradle versioning for the flutter's plugin. However, the plugin itself shouldn't be a problem because (I) I can import it in an empty project without issues, (II) if I remove it, then something else fails along the similar lines.
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/rsirokov/.pub-cache/hosted/pub.dartlang.org/devicelocale-0.3.1/android/build.gradle' line: 22
* What went wrong:
A problem occurred evaluating root project 'devicelocale'.
> Failed to apply plugin [id 'com.android.internal.version-check']
> Minimum supported Gradle version is 5.6.4. Current version is 5.6.2. If using the gradle wrapper, try editing the distributionUrl in /Users/rsirokov/.pub-cache/hosted/pub.dartlang.org/devicelocale-0.3.1/android/gradle/wrapper/gradle-wrapper.properties to gradle-5.6.4-all.zip
* 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 6s
Exception: The plugin devicelocale could not be built due to the issue above.
Tried:
flutter pub cache repair;
flutter pub upgrade;
Different versions of Gradle for the main project;
Switched to Flutter stable channel of 1.17.4;
The aforementioned log proposes a solution to switch Gradle version in the plugin's project directory. However, I don't think this would be a good idea since this directory, .pub-cache, is handled automatically by package manager and any manual changes could only make it worse.
[✓] Flutter (Channel stable, v1.17.4, on Mac OS X 10.15.4 19E287, locale en-NO)
• Flutter version 1.17.4 at /Users/rsirokov/Projects/Plugins/flutter
• Framework revision 1ad9baa8b9 (3 weeks ago), 2020-06-17 14:41:16 -0700
• Engine revision ee76268252
• Dart version 2.8.4
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/rsirokov/Library/Android/sdk
• Platform android-30, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.5, Build version 11E608c
• CocoaPods version 1.9.3
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 47.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] IntelliJ IDEA Ultimate Edition (version 2019.1.3)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 39.0.3
• Dart plugin version 191.8423
[✓] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• No issues found!
The issue was indeed in the package, but not in the one Flutter was complaining about, not in devicelocale. The problem was in flutter_statusbar_manager. It is not natively migrated to AndroidX (and seems it won't be ever; the package is abandoned, so get rid of it if you're still using it). I actually saw in the logs automatic attempt to migrate it but didn't pay attention to it. It didn't throw any errors, so thought it was migrated successfully.
For more, I have a conversation in the flutter's repo HERE. The problem is that: (I) automatic AndroidX migration of the package by flutter has failed without throwing an error (?), (II) flutter provided misleading error saying that the problem is in the different package.

having trouble to run my first flutter app

I'm facing an error when i try to run a flutter project in android studio or in command line with flutter run
it gives me this error
Exception in thread "main" java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:851)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2055)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
at org.gradle.wrapper.Download.download(Download.java:44)
at org.gradle.wrapper.Install$1.call(Install.java:61)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Finished with error: Gradle task assembleDebug failed with exit code 1
the output of flutter doctor -v
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.17134.1425], locale en-US)
• Flutter version 1.12.13+hotfix.9 at C:\src\flutter
• Framework revision f139b11009 (5 weeks ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at C:\Users\win10\AppData\Local\Android\android-sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.3
• ANDROID_HOME = C:\Users\win10\AppData\Local\Android\android-sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.
[√] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
[√] VS Code, 64-bit edition (version 1.34.0)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.2.0
[√] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)
• No issues found!
PS:
and i had another issue a while back so i changed flutter.gradle file like this
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
It seems your Gradle files are damaged.
Here's what you need to do:
open $HOME/.gradle/wrapper/dists and delete gralde-xxx-all . then execute command: flutter run again.
More info here.
Go into your Project folder and in the
gradle
wrapper
gradle-wrapper
change the number from:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
I'm gonna say exactly how I overcome this issue .some steps might not be necessary but i did all of this :
unistall flutter and android studio
install the lastest version of both (android studio and flutter )
then add
maven {
url 'http://download.flutter.io'
}
in your build.gradle file
then change compile and target sdk version to 29 (just find them and replace 29 with 28 )
C:\Users\$USER\AndroidStudioProjects\$projectname\android\app\build.gradle
like this
compileSdkVersion 29
targetSdkVersion 29
this is how it got solved for me . i hope it works for you guys too .

Flutter run release fails: Minimum supported Gradle version is 5.6.4. Current version is 5.6.2

When trying to run my app with flutter run --release it throws an error:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\Chris\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\device_info-0.4.2+1\android\build.gradle' line: 22
* What went wrong:
A problem occurred evaluating root project 'device_info'.
> Failed to apply plugin [id 'com.android.internal.version-check']
> Minimum supported Gradle version is 5.6.4. Current version is 5.6.2. If using the gradle wrapper, try editing the distributionUrl in C:\Users\Chris\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\device_info-0.4.2+1\android\gradle\wrapper\gradle-wrapper.properties to gradle-5.6.4-all.zip
If I remove this device_info plugin, I get the same error just pointing to Gradle current version to be 4.10.2 due to another plugin flutter_plugin_android_lifecycle.
I don't understand. I tried updating my gradle-wrapper.properties to
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Previously it was set to 5.6.2, but this changed nothing. Also tried with 4.10.2, but it equally just get's ignored.
I updated the gradle version in my build.gradle to
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
I created a new flutter project, just copied my pages and the pubspec... I tried in console, I tried with android studio. flutter clean, flutter build appBundle, deleting gradle versions, I tried everything I could think of or that I have read somewhere...
Nothing could help to get rid of this error, gradle insists that its current version is 5.6.2.
A new "virgin" flutter project however, I can run in release mode, without problems.
It appears these plugins will download their own gradle version. I could see it in Android Studio how an old gradle version is downloaded in contrary to the actual gradle version stated in my settings. Either way after 3 days with this, I'm running out of options and ideas.
Does anyone know how to solve this or to narrow the problem down? I also would be glad for an explanation on what's going on here.
My flutter doctor output:
[√] Flutter (Channel master, v1.17.1-pre.23, on Microsoft Windows [Version 10.0.18362.720], locale de-DE)
• Flutter version 1.17.1-pre.23 at C:\flutter
• Framework revision a2e6c30b44 (12 hours ago), 2020-04-03 20:26:01 -0700
• Engine revision 09bc1fc45e
• Dart version 2.8.0 (build 2.8.0-dev.19.0 e736495eb7)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at C:\Users\Chris\AppData\Local\Android\sdk
• Platform android-R, build-tools 29.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.
[√] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 45.0.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
[√] VS Code (version 1.43.2)
• VS Code at C:\Users\Chris\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.9.0
[√] Connected device (1 available)
• Lenovo A6020l36 • 32aac289 • android-arm64 • Android 5.1.1 (API 22)
• No issues found!
I found the problem.
It was a totally different plugin unique_identifier 0.0.3 that caused the error. After removing it, the app compiles dine again.
If you have a similar case: I had to test for every single package installed until I found it.

Categories

Resources