Flutter build failing after switching from compileSdkVersion 30 to compileSdkVersion 31 - flutter

I had an old project which I had released and the person I made it for wanted me to add notifications. I added the flutter messaging and flutter local notifications and updated the firebase dependencies accordingly. After this I tried to run the app but it said you have to upgrade the compileSdkVersion to 31. But this resulted in the following error.
Up till now I have tried upgrading my dart sdk, deleting the pubspec.lock file and running it again. I have also tried importing my project again after reinstalling flutter. The error just won't go away.

Related

I am having a problem building a Flutter App

I has a build a flutter app before successfully, but I try to update the code of my flutter app because I discovered some bugs but when j try to build it I get a error about error configuring video_player Android, I try to add it as a Dependencies but still it didn't work, I also invalidate cache's too it didn't work because it also said something about Cache's, I also upgraded my flutter SDK, still it didn't work, I will attach a image under this write up.
The error I am facing 😭😪
The error I am facing 😭😪
Write below command in terminal to clear cache with android project path.
flutter pub cache clean
./gradlew clean
gradlew cleanBuildCache

How can I solve the version of the Android embedding?

I have this problem. Plz let me know how to solve this problem..
I got this git code from a lesson made about 2years ago.
Also different errors showed up when I made a flutter project using git code.
-> This is the problem
This app is using a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to migrate this app to the V2 embedding.
If you are here because of the flutter 2.10, do this:
Change this:
<application
android:icon="#mipmap/ic_launcher"
android:name="io.flutter.app.FlutterApplication"
android:label="PassesBox"
...
To this:
<application
android:icon="#mipmap/ic_launcher"
android:name="${applicationName}"
android:label="PassesBox"
...
If the application is very old, you should consult the migration guide that the documentation or fial offers you, just like the other answers recommend.
https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
but if you still have the deprecated application warnning try the following
step one: delete the cache. flutter clean
step two: remove the pubspec.lock file from the root of the project. rm pubspec.lock
step three: update the libraries if you have any very outdated, you can do it manually or through the command. flutter pub upgrade --major-versions (this command will update all the libraries you have, be careful, before evaluating if such an update is necessary in your project).
then you must make some changes at the android folder level
change the gradle.zip in android/gradle/wrapper/gradle-wrapper.properties to a newer version like:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
and in android/build.gradle update the version to
classpath 'com.android.tools.build:gradle:7.1.2'
the kotlin version in : ext.kotlin_version = '1.6.10'
and if you were using code obfuscation with proguard-rules.pro
remove any added configurations that reference that file in android/app/build.gradle and you should be left with just this
buildTypes {
release {
signingConfig signingConfigs.release
}
}
finally close the code editor or the IDE you use
and in console run flutter pub get and run your project flutter run
Last but not least, do not forget to update the build version of your application to API 33 or higher and have your android studio updated (VERY IMPORTANT FOR UPDATE, )
android-studio
This has been answered before here on SO.
Here:
Your Flutter application is created using an older version of the Android embedding
And here: How to Fix Flutter Warning: Your Flutter application is created using an older version
You can also look at the source of how to migrate here:
https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects

How to enable Multidex inside flutter which is added to existing android project as module

I have and android project, which I added flutter on it as module,
In my original android app, multidex is enabled, but this do not help me, when running the app in debug it's working normally, but when creating a release apk or even debug apk the FlutterFragment is appearing as white, like the engine did not attach.
Things I notice, 'flutter run --release' will ask me to support multidex, and will not run, updating the minSdkVersion to 21 and enabling multidex in .android/app/build.gradle then again 'flutter run --release' works perfect, but this have no effect on the host app because it's under .android which automatically build, and ignored by the host app.
Also I tried to search for how to update minSdkVersion to 21 instead of 16, but references lead to change in the .android which have no effect.
Hey you can do two thing
Update your flutter SDK version by running command
flutter upgrade
The new version of flutter(2.10) multidex support automatically.
simply pass the --multidex flag to flutter build appbundle or flutter build apk and your app will support multidex.
2.In your app folder inside android [project_folder]/app/build.gradle and add following lines.
defaultConfig {
...
multiDexEnabled true
}
and
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}
After a lot of investigation, the reason was related to something in the entry point, which needed to add project name, referring to this link

Flutter Gradle build with error exception

i just setup my android studio and vs code and flutter SDK installed but any time i try running the project i get this Gradle error, i cant figure out what the problem is please help me out.
After running the flutter doctor everything seems to be okay.
the problem might be caused by many factors so lets try some solutions
after each one rebuild your app if the error message changed or the problem solved please keep us informed
run these commands one by one
flutter channel stable
flutter upgrade --force
flutter pub cache repair
cd your app folder
flutter clean
edit app/build.gradle in your host app such as it includes the local repo
like in here
repositories {
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
}
use VPN and rebuild your app

The built failed likely due to AndroidX incompatibilities in a plugin,for plugin Workmanager in Flutter

I wanted to run a background process in flutter.I used the code in https://pub.dev/packages/workmanager#-example-tab- and added the dependency required in pubspec.yaml file.
But I am getting "The built failed likely due to AndroidX incompatibilities in a plugin".The detail of the which I am sharing in the screenshot below(2 images):
I tried checking my gradle.properties file as suggested in some posts.But useAndroidX,enableJetifier were set "true".The details of gradle.properties is below:
android.useAndroidX=true
android.enableJetifier=true
This is my flutter doctor -v details:
The flutter build --verbose
I recently got this error, while using cloud_firestore plugin.
Since, Starting from Flutter v1.12.13, new projects created with flutter use AndroidX by default, therefore that didn't solve my problem.
After several times doing Pub get with any versions of plugin,
I figured all you have to do is:
• Go to android/app/build.gradle of your Flutter project, and
• Set minSdkVersion 21
Now, on running flutter build apk, the error should go away.
you just need to migrate to AndroidX maybe
https://flutter.dev/docs/development/androidx-migration
refer this link, please