project/build.gradle
apply plugin: 'com.android.application'
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.3.2'
}
In app/build.gradle
line no.24 apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "blablabla.com"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
}
apply plugin: 'com.google.gms.google-services'
In pubspec.yaml
dependencies:
flutter:
sdk: flutter
firebase_database: ^2.0.2
firebase_core: ^0.3.1+1
timeago: ^2.0.10
Im getting this error
$ flutter run
Using hardware rendering with device Android SDK built for x86. If you
get graphics artifacts, consider enabling software rendering with
"--enable-software-rendering".
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle... 2.2s
Resolving dependencies...
* Error running Gradle:
ProcessException: Process
"C:\Users\Krishnaganesh\Desktop\flutter_blog_app-master\android\gradlew.bat" exited abnormally:
FAILURE: Build failed with an exception.
* Where:
Build file
'C:\Users\Krishnaganesh\Desktop\flutter_blog_app-master\android\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> ASCII
* 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 3s
Command:
C:\Users\Krishnaganesh\Desktop\flutter_blog_app-master\android\gradlew .bat app:properties
Please review your Gradle project setup in the android/ folder.
How to solve this Error ...???
Bump dependencies versions:
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.google.gms:google-services:4.3.3'
firebase_database: ^3.1.0
firebase_core: ^0.4.2+1
In app/build.gradle add these:
android {
...
defaultConfig {
...
multiDexEnabled true // add this
}
}
dependencies {
...
implementation 'com.android.support:multidex:1.0.3' // add this
}
Don't forget to create google-services.json file in app/ folder and fill it with your data (docs link) or use some mock (like this one):
{
"project_info": {...},
"client": [...],
}
Related
According to the documentation for "webview_flutter", the package requires Android SDK 20+. Immediately after running flutter pub add webview_flutter and restarting my app (without even attempting to use WebView yet), I'm greeted with the following error:
One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to /Users/chris/Projects/app/android/app/build.gradle:
android {
compileSdkVersion 32
...
}
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> One or more issues found when checking AAR metadata values:
Dependency 'androidx.webkit:webkit:1.5.0' requires 'compileSdkVersion' to be set to 32 or higher.
Compilation target for module ':app' is 'android-31'
BUILD FAILED in 4s
Exception: Gradle task assembleDebug failed with exit code 1
The device I'm testing on and compiling for is running version 31.
My android/app/build.gradle file:
...
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
...
defaultConfig {
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
...
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
I've also attempted to change the minSdkVersion to what the docs suggest, to no avail:
android {
defaultConfig {
minSdkVersion 20
}
}
I'll happily use an older version of webkit if it allows the compile sdk version to be lower, but I've tried flutter_webview versions 1.0.7 and 2.8.0 with the same result. How do I avoid this seemingly restrictive behaviour?
Will changing the compileSdkVersion to 32 as it suggests, still allow me to support devices using 31 or lower?
I fixed this issue by increasing sdk version to 33. Refer below code:
android {
ndkVersion "25.0.8775105"
compileSdkVersion 33
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.anncad.news_app_flutter"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 21
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
compileSdkVersion is the SDK version used to compile your app, has nothing to do with the Android version your device has.
Any compileSdkVersion will work on any device you have.
32 and 31 are almost the same, 31 is Android 12 and 32 is Android 12L, so if you are already using 31 is safe to use 32.
I am running into the same issue. I believe Android 10 (SDK 29) is required for non Google phones. Would it be possible to roll back to androidx.webkit:webkit:1.4.0 somewhere?
Currently running builds with:
flutter.minSdkVersion=29
flutter.targetSdkVersion=32
flutter.compileSdkVersion=33
With these:
ext.kotlin_version = '1.6.21'
classpath 'com.android.tools.build:gradle:7.1.2'
I tried generating a build release for flutter and I got these errors. Execution failed for task ':app:compileFlutterBuildRelease'. The code I used for generating build is flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi. The debug works perfectly.
android {
compileSdkVersion 29
buildToolsVersion 29
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.abc.def"
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
The code I used for generating build is flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi. The debug works perfectly. // This is the main section that I've updated
// to get the release APK to build
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so flutter run --release works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:25.12.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-functions:19.0.2'
implementation 'com.google.firebase:firebase-messaging:20.2.0'
implementation 'com.google.firebase:firebase-database:19.3.0'
implementation 'com.google.firebase:firebase-core:17.4.3'
implementation 'com.google.code.gson:gson:2.8.6'
}
apply plugin: 'com.google.gms.google-services'
First, make sure you have followed up correctly all procedures in this documentation, then after you are sure you have followed up correctly then
Try this out:
flutter clean
flutter build apk --debug
flutter build apk --profile
flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
suggestion:
if this doesn't help then add the full error which you are getting as well as both complete Gradle files
and instead of splitting apk use app bundle, for app bundle use:
flutter build appbundle
if this helps then please notify in comments
run in your terminal
flutter channel stable
flutter upgrade --force
flutter pub cache repair
next,
cd <YOUR APP FOLDER>
flutter clean
AND create a seperate fluter project using flutter create <app-name>
and include the generated ios folder and android folder into your project (obviously you need to delete the current ios and android folders) . If you made changes into these folders consider using version control
I wanted to make some operations while the app was not running, so I decided to use the background fetch package.I followed the android setup step by step
This is part of my pubspec.yaml
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
google_maps_flutter: ^0.5.16
geolocator: ^5.1.1
flutter_local_notifications: ^0.7.1+1
shared_preferences: '0.5.6+3'
background_fetch: '^0.5.1'
This is part of my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="firenzepuliziastrade.firenze_pulizia_strade">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
tools:replace="android:label"
android:name="io.flutter.app.FlutterApplication"
android:label="Firenze Pulizia Strade"
android:icon="#mipmap/ic_launcher">
This is part of my app/build.gradle
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "firenzepuliziastrade.firenze_pulizia_strade"
minSdkVersion 16
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
This is part of my android/build.gradle
buildscript {
ext.kotlin_version = '1.3.50'
ext {
compileSdkVersion = 28 // or higher
targetSdkVersion = 28 // or higher
appCompatVersion = "1.1.0" // or higher
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
maven {
// [required] background_fetch
url "${project(':background_fetch').projectDir}/libs"
}
}
}
This is my gradle.properties
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
I tried even the additional step to enable the Headless mechanism even though I thought that it was not necessary since my flutter version is Flutter 1.12.13 and I created this project recently.
But all that said I could not make the app do some work while not running, it just worked while being in the background. So I thought that the reason was that I was launching the app in debug mode and I tried to launch it in release mode, but I got the following error:
Launching lib/main.dart on POT LX1 in release mode...
Running Gradle task 'assembleRelease'...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':path_provider:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
/home/nik/.gradle/caches/transforms-2/files-2.1/0a271e99b6771ad4a84318244d532fb7/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found.
/home/nik/.gradle/caches/transforms-2/files-2.1/0a271e99b6771ad4a84318244d532fb7/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcIndex not found.
* 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 7s
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
Building plugin background_fetch...
Running Gradle task 'assembleAarRelease'...
Finished with error: ProcessException: Permission denied
Command: /home/nik/Desktop/Pulizia_Strade/flutter/.pub-cache/hosted/pub.dartlang.org/background_fetch-0.5.6/android/gradlew -I=/home/nik/Desktop/Pulizia_Strade/flutter/packages/flutter_tools/gradle/aar_init_script.gradle -Pflutter-root=/home/nik/Desktop/Pulizia_Strade/flutter -Poutput-dir=/home/nik/Desktop/Pulizia_Strade/firenze_pulizia_strade/build/app -Pis-plugin=true -Ptarget-platform=android-arm,android-arm64,android-x64 assembleAarRelease
I tried to create a new flutter project, specifying androidx, but it did notwork, I got the same error. Can someone help me, I really do not know what to do at this point...
It seems that your app is not compatible with AndroidX. So far you've done some troubleshooting but didn't get to make it work. Try to double check the AndroidX Migration Guide if you haven't missed anything.
So far, you've already enabled the Jetifier by adding the following lines to [project_folder]/android/app/gradle.properties
android.useAndroidX=true
android.enableJetifier=true
Now try to enable multidex by adding this line in the defaultConfig of [project_folder]/app/build.gradle
defaultConfig {
...
multiDexEnabled true
}
Then upgrade gradle dependency in the [project_folder]/android/build.gradle file:
classpath 'com.android.tools.build:gradle:4.1.0'
Latest version used in flutter as specified here.
Next, make sure that all your packages in the pubspec.yaml are of the latest version.
Lastly, run flutter clean and rebuild your project.
I try run on android and return this error.
I Aredy tried:
gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
build.gradle:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
my pubspec.yaml:
flutter_facebook_login: ^3.0.0
firebase_database: ^3.1.0
firebase_auth: ^0.15.0+1
cloud_firestore: ^0.12.11
url_launcher: ^5.2.7
google_maps_flutter: ^0.5.21+12
image_picker: ^0.6.2+1
firebase_storage: ^3.0.8
intl: ^0.16.0
What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for 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 35s The built failed likely due to AndroidX
incompatibilities in a plugin. The tool is about to try using Jetfier
to solve the incompatibility. Building plugin cloud_firestore... The
plugin cloud_firestore could not be built due to the issue above.
SOLUTION:
When you created the new project, did you select "androidX"? And are those versions the latest versions? (meaning, androidX compatible/requiring). if not sure, create a new project and make sure to select androidX, and change the sdk settings to 23/29 as above.
Edit: Solution was a combination of creating a new project with AndroidX selected and add the proper SDK versions to the gradle file. Possibly with using correct dependency versions.
To migrate to AndroidX, you need to set the SDK versions to 21 or higher. I recommend 23 because that removes some other issues as well.
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example"
minSdkVersion 23
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
I recently encountered this error using Flutter 2.2.2, None of the above solutions worked for me.
First try basic commands like:
cd android && ./gradlew clean
flutter clean
If it doesn't work:
set distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip in android/gradle/wrapper/gradle-wrapper.properties
if your gradle version is <= 6.7 (refer gradle issue)
Try basic commands and build again!
Solution
flutter clean
delete android/.gradle and run
revert pubspec.lock and flutter pub get
flutter run
Change compileSdkVersion value to flutter.compileSdkVersion
also change minSdkVersion,targetSdkVersion values as shown below
android {
compileSdkVersion flutter.compileSdkVersion
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.octs"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
This worked for me.
None of answers above helped me. I use IntelliJ Idea as an IDE instead of Android Studio (because I develop other modules in other langs, not only Flutter app). I was able to run ./gradlew :app:compileDebugJavaWithJavac from command line, but flutter run failed. After long time I've realized that Flutter uses Android Studio to let it build android app. So if you use IntelliJ Idea, do check what Java you use not only in Idea (I use Java 11), but what Java you use in Android Studio! (mine AS used Java 8). After changing to Java 11, problem was solved.
I solved my problem by changing the version (reduced the gradle version), which caused me another problem, but related to one API and Kotlin plugin. Since I cannot delete Kotlin I took out the API and it came to life again! thanks for your help here!
Try this package flutter_stripe: ^3.2.0
Whenever I'm trying to include flutter geolocation(https://github.com/loup-v/geolocation) plugin I'm getting following error.
Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
* 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 3s
Finished with error: Gradle build failed: 1
My pubspec.yml dependancies list is
dependencies:
flutter:
sdk: flutter
google_sign_in: "^3.0.2"
firebase_auth: "^0.5.5"
shared_preferences: "^0.4.1"
cloud_firestore: "^0.7.2"
firebase_storage: "^0.2.5"
image_picker: "^0.4.1"
progress_hud: "^0.2.2"
cached_network_image: "^0.4.1"
intl: "^0.15.6"
path: "^1.5.1"
geolocation: "^0.2.1"
My app>build.gradle code
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.bhramaan.bhramaan"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
What's going wrong?
There are three things I can suggest to help. The first is to do a full rebuild by first running flutter clean and then running again. Occasionally things get a little bit messed up between flutter & android, and that helps.
The next thing I would do is check that you're getting the same version of all the Play services. For some reason gradlew sometimes messes that up. Run gradlew app:dependencies from the android (or ./gradlew if you're on mac/linux). If you're getting different versions, add them all as dependencies of the same version.
For example, in my android/app/build.gradle, I had to set
implementation 'com.google.android.gms:play-services-base:15.0.2'
implementation 'com.google.android.gms:play-services-vision:15.0.2'
even though Gradle should have sorted that out. In particular look out for com.google.android.gms:play-services-location as it's a dependency of the geolocation package. Same goes for the com.android.support libraries.
If that still doesn't work, try running the gradle build directly, and in particular looking at the stack trace (gradlew app:build --stacktrace from the android folder) to see if it tells you anything. You could then post that, or take a look at the generic Android questions for a solution. It could be that you need to enabler multi-dex, although I don't think so.
I believe this is an issue with geolocation gradle version of firebase and your flutter version being incompatible. Try adding multiDexEnabled true to your build gradle. If that does not solve it open your flutters android project in android studio and go to the geolocation build gradle and change dependencies version to classpath 'com.android.tools.build:gradle:3.1.2' & at the bottom update the play services to api "com.google.android.gms:play-services-location:15.+".
Finally, I've fixed this by following the steps as mentioned by #rmtmckenzie.
In my android/app/build.gradle I added following piece of code &
configurations.all {
resolutionStrategy {
force 'com.google.android.gms:play-services-location:15.0.1'
}
}
and enabled multiDexEnabled true
defaultConfig {
multiDexEnabled true
}
With this setting now, my whole app working fine.
In your app's top level build.gradle update classpath. For me
classpath 'com.android.tools.build:gradle:3.5.3' is working fine.