Flutter Android 12 install error when using intent-filter - flutter

I'm struggling with the error below.
adb: failed to install F:\xxx\src\FlutterDemoApp\FlutterDemoApp\build\app\outputs\flutter-apk\app.
apk: Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl1942767517.tmp/base.apk (at Binary XML file line #102):
com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]
Error launching application on Pixel 4 XL.
As I found at Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present] and Android Studio error: "Manifest merger failed: Apps targeting Android 12" this is simply a matter of adding android:exported="true" to android/app/src/main/AndroidManifest.xml
But the issue is it is already there in my environment and I still get the error.
Am I missing something else?

Also make this in note,
Starting from Android 12 (SDK 31) and when using intent-filter, the attribut android:exported must be set explicitly to false or true. Without this attribut the application wouldn't be able to be installed.
References:
Resource:
(contains the warning about installing an application without this attribut on Android 12 or higher)
When a new flutter project is created the default AndroidManifest.xml should contain this attribute set to true as the intent is a android.intent.category.LAUNCHER:
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="..."
android:hardwareAccelerated="true"
android:exported="true" <== SHOULD BE ADDED
android:windowSoftInputMode="adjustResize">

I tried cleaning the project & changing package names to lowercase as advised in the comments. But nothing worked.
Below is what worked for me. Hope somebody fined this helpful.
I had to add Multi Dex support to my build.gradle
defaultConfig {
applicationId "com.example.demo_app"
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled = true //★This
}
and
dependencies {
implementation("androidx.multidex:multidex:2.0.1")//★This
implementation 'org.altbeacon:android-beacon-library:2.19'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Not exactly sure why this work, but you can read more here
https://developer.android.com/studio/build/multidex

Related

Share_plus plugin - Error: Call requires API level 22 (current min is 16): android.content.Intent#createChooser [NewApi]

My flutter version: Flutter 3.0.0
Gradle version: Gradle 7.2
when I run .../android$ ./gradlew clean and then .../android$ ./gradlew build -warning-mode all in terminal, I get the following error:
> Task :share_plus:lintDebug FAILED
Lint found 4 errors, 3 warnings. First failure:
/home/my-name/.pub-cache/hosted/pub.dartlang.org/share_plus-6.2.0/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt:68: Error: Call requires API level 22 (current min is 16): android.content.Intent#createChooser [NewApi]
Intent.createChooser(
I changed minSdkVersion like the following but it is still not working.
android/app/build.gradle:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.citymarker"
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
android/local.properties:
sdk.dir=/home/my-name/Android/Sdk
flutter.sdk=/home/thiago/development/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=23
flutter.targetSdkVersion=33
flutter.compileSdkVersion=33
I tried everything I could, but nothing is working.
I solved using a lower version of share_plus plugin. Just add the below line in your pubspec.yaml under dependencies:
share_plus: 4.0.2
I don't know yet why the error was happening even after changing minSdkVersion to 23. If someone has an answer, please, share with us.
under External Libraries you can find all the libraries u r using including share_plus (these are the files generated when u run 'flutter pub get'). U need to update share_plus/android/build.gradle with minSdkVersion 23, and it should build.enter image description here

Missing compileSdkVersion for google mobile ads

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.ringit2"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Here is what I found on my build.gradle and I can't find compileSdkVersion which I have to change to at least 28 in order for google mobile ads to operate.
After I added google_mobile_ads: ^1.1.0 on pubspec.yaml and imported the package to the main.dart, The app opens as I run the simulator but shuts down right away. Console shows me this message and it is stuck just like this forever.
Launching lib\main.dart on SM G950N in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Please note that my ext.kotlin_version is '1.6.10' because people have recommended to upgrade it
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
Also changed the distributionUrl...
Not sure why google mobile ads package is so hard to use even just to start but what should I change to use it?
I am also using kotlin version '1.6.10' and compilesdk version is inside android>app>build.gradle
The compileSdkVersion will be inside
android>app>build.gradle
inside that you can see compileSdkVersion in line 30
Also check your environment path of flutter

Flutter app is crashing after 'flutter clean' and debug

I don't understand why everything is not working after I did a 'flutter clean'. At nearly the same time I accidentally pressed the Debug button near the play button. Not sure which one messed things up though. Here is the message I get in the console:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugGoogleServices'.
> No matching client found for package name 'com.example.activities'
I went back and recreated the google-services.json file from Firebase. The Android Package Name that I chose, after clicking to add an Android App, was incorrect. It wasn't the same as the one I used when I made my app.
I also had to add multiDexEnabled true in the the default config {} of the app\build.gradle file. So now it looks like:
defaultConfig {
applicationId "com.example.activities"
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Seems like a non-good idea to add multiDexEnabled to true but it works for now.

Flutter error: Execution failed for task ':app:compileDebugJavaWithJavac'

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

flutter - use tools:overrideLibrary="io.flutter.plugins.camera"

While implementing camera in flutter I face this problem with manifest file
android\app\src\main\AndroidManifest.xml Error:
uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera] D:\My Files\flutter-apps\login\build\camera\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera] D:\My Files\flutter-apps\login\build\camera\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)**strong text**
If you want to use camera plugin you need to update your Flutter Android minSdkVersion to 21 in your android build.gradle file located here:
./android/app/build.gradle
This how it should be:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.my_flutter_app"
minSdkVersion 21
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
If you look at the plugin page, yuo can see they also tell you what to do.