Flutter does not compile after adding flutter_email_sender plugin - android

I am trying to redirect my users to an email client so they can send an attachement i have created within my app.
However on adding flutter_email_sender to my pubspec.yaml my app no longer compiles.
I am getting the following error:
I have tried adding the line to my AndroidManifest with no success.
"The prefix 'tools' for at tribute 'tools:replace' associated with an element type 'application' is not bound"
The documentation says i should have compileSdkVersion 28 which i have.
How do i resolve this error?

You need to migrate to androidx. Which means you need to update all packages that you added in your pubspec.yaml to ensure that they are compatible with androidx. So make sure that all your packages are up to date, then open the android project of your flutter app with android studio. Go to Refactor-> Migrate to AndroidX. Then rebuild your project. And you will be fine.
Hope it helps!

Related

How can I fix "unexpected element <queries> found in <manifest>" error?

All of a sudden, I am getting this build error in my Android project:
unexpected element <queries> found in <manifest>
How do I fix it?
The Android Gradle Plugin needs to know about new manifest elements, particularly
for the manifest merger process. The plugin has a tendency to get confused if it
sees elements in the manifest merger that it does not recognize, tossing out
build errors like the one in the question.
In this case, Android 11 introduced <queries> as a manifest element, and older versions of the Android Gradle Plugin do not know about that element.
The fact that this occurs from manifest merger means that simply upgrading a dependency
might bring about this error. For example, if you upgrade to the latest
version of com.awesome:awesome-library, and it contained a <queries> element
in its manifest, you might crash with the aforementioned error in your builds,
even without any other changes in your code.
Google released a series of patch versions of the Android Gradle Plugin to address this:
3.3.3
3.4.3
3.5.4
3.6.4
4.0.1
If you are using an existing plugin in the 3.3.* through 4.0.* series, upgrade
to the associated patch version (or higher) from that list, and you should no longer
run into that error (e.g., classpath 'com.android.tools.build:gradle:4.0.1').
If you are using Android Studio 4.1 or higher, with a matching
Android Gradle Plugin (e.g., in the 4.1.* series), you should be fine without
any changes. Those plugin versions were already aware of <queries>.
See this Android Developers Blog post for more.
I had this issue in Flutter, but I believe this solution will work for both Flutter and native Flutter development.
Follow these steps
Read this short blog post to get some understanding: Preparing your Gradle build for package visibility in Android 11
Delete the .gradle folder inside the Android folder, i.e., android > .gradle
In the project build.gradle file, upgrade your class path appropriately based on the blog in the link above, e.g., I upgraded to classpath 'com.android.tools.build:gradle:4.0.1'
Upgrade the distribution URL too. It's in android>gradle>gradle-wrapper.properties file appropriately. E.g., I upgraded it to distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
You can invalidate caches and restart your Android Studio. Make sure you have a good Internet connection, because it will download the new Gradle files.
I also suddenly had the same issue two days ago in Android Studio 4.1.1. I solved the issue by upgrading the build Gradle version.
Previous setting in the build.gradle file of the project was:
classpath("com.android.tools.build:gradle:3.5.3")
Current setting:
classpath("com.android.tools.build:gradle:3.5.4")
The issue was gone immediately. :)
Fixing the error is very simple.
Update your Android Studio to the last version
and use the last stable Gradle plugin version.
At the current time, I use Android Studio version 4.1.3 with Gradle Plugin 6.8.2
For use in queries, you should write queries code in out of application tag, not inside application tag.
For more information, see the photo below:
I had this error in the react-native-image-crop-picker library, and I solved this problem by updating the Gradle version as mentioned in previous answers.
It was:
classpath("com.android.tools.build:gradle:3.5.3")
Updated to:
classpath("com.android.tools.build:gradle:3.5.4")
And I ran a:
cd android && ./gradlew clean && cd .. && npx react-native run-android
Then it worked OK.
Due to the new default settings and features for package visibility in Android 11 that need to add <queries>, you must update your Android Gradle plugin.
Google has added some patches to current versions listed in Android Gradle plugin release notes, 4.0.0 (April 2020).
If you want to use a newer version of Android Gradle, you should search for a compatible wrapper from Android Gradle plugin release notes, Update Gradle.
Update your Gradle version to 4.0.1 or later.
File android/gradle/wrapper/gradle-wrapper.properties: update the distribution URL to:
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
File android/build.gradle: update the Gradle plugin:
classpath 'com.android.tools.build:gradle:4.1.2'
to 4.0.1 or later. Here it is 4.1.2 with Gradle version to 6.5 or later.
You can see the distribution chart at How to update gradle in android studio?

Migrate Flutter project to AndroidX

The issue I was facing was to build and run my application and terminal saying 'Your project is doesn't support AndroidX'.
Solution: https://flutter.dev/docs/development/androidx-migration
So I went to the given link and tried to implement it by the help of Android Studio, but it always leads to No usage found.
So I went back to the link and tried the other approach of editing the gradle.properties in android level (android/gradle) and add these properties:
android.useAndroidX=true
android.enableJetifier=true

Your app isn't using AndroidX - Flutter doesn't allow me to generate apk

I developed an app in flutter with Visual Studio code on Mac. I ran the application without any kind of problem on IOS. I also installed it on a physical device and it works perfectly, but I have a problem generating the Android project study and its APK on with flutter.
Message:
flutter build appbundle
[!] Your app isn't using AndroidX.
To avoid potential build failures, you can quickly migrate your app by following the
steps on ...
Running Gradle task 'bundleRelease'...
Note: Some input files use unchecked or unsafe operations.
Running Gradle task 'bundleRelease'... Note: Recompile with -Xlint:unchecked for details.
Running Gradle task 'bundleRelease'...
Running Gradle task 'bundleRelease'... Done 217,9s (!)
Gradle build failed to produce an .aab file. It's likely that this file was generated under
/Users/riccardo/Desktop/QuoteFlutter/quote/build, but the tool couldn't find it.
in my own case my gradle.properties was missing. I Just created a new gradle.properties file inside the android folder, with the below parameter
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
you should go to
YourAppName=> android => gradle.properties
inside gradle.properties add these two lines
android.useAndroidX=true
android.enableJetifier=true
dat should solve it.
The error description clearly states that
Your app isn't using AndroidX.
To avoid potential build failures, you can quickly migrate your app by following the
steps on ...
How to resolve this?
Follow this detailed documentation.
this because your project is missing gradle.prperties file >> open terminal in android studio or vs code and write "flutter create ." it will create missing file one of them is gradle.properties.
I had an old project using Firestore, that I was trying to open, and got this message. I could not find any easy way to fix it.
These were the steps I took to migrate it, hope it helps someone.
Create a new folder.
Then run this command in Terminal, in the folder:
flutter create --org com.yourdomain your_app_name
Copy the files from lib folder, (and any other modifications from android or ios folders).
Copy google-services.json to android\app folder.
Modify pubspec.yaml and copy the dependencies under dependencies:
Change android\app\build.gradle change version to:
minSdkVersion 21
Add the plugins needed in android\app\build.gradle:
apply plugin: 'com.google.gms.google-services'
In Android\build.gradle file:
Add the dependency (with your version):
classpath 'com.google.gms:google-services:4.3.3'
You need to convert your project to AndroidX. Execute the following command:
flutter create --androidx -t <project-type> <new-project-path>
Project types can be app, package or plugin
More information here.
Note: This Problem can also come while building an app downloaded from github, in VSCode with Flutter.
its August 2021
Answer:
if you are not using android studio as i am using vscode.
add below lines to flutter_app_path/android/gradle.properties.
android.useAndroidX=true
android.enableJetifier=true
Google introduced android jetpack(another topic) in which AndroidX package name and namespace default for jetpack libraries and minimum support library 28 required what i guess now flutter team wants to migrate flutter support to android jetpack near future. come to point now migrating to androidx make sure your project has support library 28
add below lines to flutter_app_path/android/app/build.gradle.
android {
compileSdkVersion 28
// other lines of code
}
Optional Story
i had same issue when i cloned my old flutter repo
if you have cloned flutter legacy app repo from github and your development flutter SDK version is 2.2.x first you need to migrate your app to NULL Safety after you should migrate to androidx follow my Answer
if you want an APK then use
flutter clean
flutter build apk

Android Studio 3.0.1 Error: Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly

I've installed Android studio 3.0.1 then tried to build very first app by choosing an empty activity, but I've got this message:
Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly
and the error message like this:
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.
Could not resolve com.android.support:appcompat-v7:26.1.0.
Required by:
project :app
Could not resolve com.android.support:appcompat-v7:26.1.0.
> Could not parse POM https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom
> Already seen doctype.
The first part of log message is like this:
2018-01-03 11:11:12,671 [d thread 8] WARN - ect.sync.idea.ProjectSetUpTask - Already seen doctype.
Consult IDE log for more details (Help | Show Log)
2018-01-03 11:11:12,671 [d thread 8] INFO - e.project.sync.GradleSyncState - Gradle sync failed: Already seen doctype.
I've tried some suggested solutions like changing gradle version, update Kotlin plugin(!) and so, but they didn't work.
Any solution?
This problem occurs when the Build Tools Version is not set for the project.
You just set the build tools version by following this process...
By opening your project structure [File->Project Structure] and selecting the Build Tools Version from app's property tab in Modules section.
This will add build tools version to your gradle file (Module:app) and re-sync the project.
The problem caused by my connection. I needed to set proxy to download some components.
For me the issue was one of the external libraries required SDK 28 but android studio didnt have it so it did not work. I installed SDK 28 and the problem was fixed. I saw the problem in the log file it generated
The error happens under fluctuating network. So at first make sure your connection is stable. Plus, if you are using any VPN check your gradle.properties is configured correctly.
The correct form of VPN connection on gradle.properties is as follows,
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=8080
My host connection is 127.0.0.1, and its port is 8080 for both http and https.
Just one more thing, make sure adding https (It is mandatory).
I had the same problem when i was upgrading to android studio 3.1.2 and the problem i was using the previous JDK which i installed before 5 years back.
The steps:-
Go to File -> Project Structures -> SDK Location -> JDK Location -> check the
Option Use embedded JDK (recommended).
I tried all suggestions, only one works for me:
open 'Gradle' tab on right vertical panel
right click on project name
'Refresh Gradle Dependencies' and wait background downloading
right click on project name again
'Reload Gradle Project' and wait refreshing
I was also stuck with the same issue for quite few minutes till I figured out the solution:
So you have to visit Gradle Releases and
there scroll down a little bit and you will find the plugin version and required gradle version. Make sure you use the latest version of both or the ones which are compatible with each other.
For today I am using :
Android Gradle Plugin Version - 7.0.2
Gradle Version - 7.2
You can update it by navigating to:
> File -> Project Structure -> Project
Suddenly My Project showing this Error(Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly). Then i Try to various solutions but not solved.
Then i close the android studio, and open the project location and delete the .idea and .iml file, After deleting this file open the project again on Android studio, after that the project working fine.
I had the same problem, I did download gradle version and used it as a local distribution.
Settings/Build,../Gradle/Use local distribution.
Else you will have to reinstall all the software.
The solution is kinda of very simple.
It's because the "compileSdkVersion" that you are using
in your build.gradle (Module:app) is higher than the SDK installed in your Android studio.
Now, what to do?
Just go on SDK Manager and download an Api Level higher or equal to your "compileSdkVersion" and you're done
Look at the manifest, something may have to go wrong there. In my case I had this label
<uses-sdk android: minSdkVersion = "7" android: targetSdkVersion = "15" />, which was from an example.
Then the error is displayed, and the correspondent is now updated <uses-sdk android: minSdkVersion = "15" android: targetSdkVersion = "27" />
As #oyeraghib said,
Visit this link to check the compatibility of your Android Gradle Plugin in comparison with Gradle itself. I was using an older version of both and updated to version 7 in both.
File -> Project Structure -> Project
It may take a while. Wait for it to load.
change the grade version to the latest one in gradle-wrapper
Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly
Go to gradle scripts -> build gradle(app) -> made following changes:
Finally it works.

Sinch tutorial gradle build errors

Im trying to get sinch going, and I am following their tutorial form here.
https://www.sinch.com/tutorials/android-messaging-tutorial-using-sinch-and-parse/
step one is download the skelton and do the gradle build, however first error was unsporrted version of gradle. android studio fixed it automatically and re-imported. and then i get this error:
Error:(15, 0) Gradle DSL method not found: 'runProguard()'
Possible causes:The project 'messenger' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
I'm new to android programming and android studio, so I'm kinda lost. How can i get this built and continue with the tutorial?
To comply with the newer versions of Gradle, change 'runProguard' to 'minifyEnabled'
in my case, i am using sinch 3.11.1.
it is aar file.
so you need to import aar file.
after that you can use sinch on your project.
to import aar file you can follow this video (it is not mine):
https://www.youtube.com/watch?v=J-GbMTa1fX0
hope it helps.

Categories

Resources