APT: error: attribute android:usesPermissionFlags not found - flutter

I want to compile simple app in Flutter. I am using flutter_reactive_ble library and I have following error:
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
/Users/michalsniady/Desktop/Engineering Thesis/take_your_pills/build/app/intermediates/packaged_manifests/debug/AndroidManifest.xml:18: AAPT: error: attribute android:usesPermissionFlags not found.
My permissions in main Android Manifest look like that:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
And my build.gradle code looks like that:
compileSdkVersion 29
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
}
Does anyone has any idea what might be the problem?

Try to compile and/or target Android 31. The feature you're trying to use has been added to Android 31 (Platform 31 = Android 12).

Related

Flutter Android 12 install error when using intent-filter

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

How to solve permission handler error in flutter?

Not sure where I made mistake but I got error while implementing permission_handler: ^7.1.0 ,the error message is ``` C:\src\flutter.pub-cache\hosted\http://pub.dartlang.org\permission_handler-7.2.0\android\src\main\java\com\baseflow\permissionhandler\ServiceManager.java:152: warning: [deprecation] getDefaultAdapter() in BluetoothAdapter has been deprecated
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
^
error: warnings found and -Werror specified
1 error
1 warning
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':permission_handler: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 1m 10s
Exception: Gradle task assembleDebug failed with exit code 1 ```
Below I attached necessary screenshots
And I also given permission in Androidmanifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
And compileSdkVersion 31, minSdkVersion 21, targetSdkVersion 30. Hope I have given all necessary details. If anything need please comment and please help to solve this issue and I don’t want to change my sdk version. Thank you in Advance.
Try flutter clean, delete the pubspec.lock file. Then run flutter pub get and then flutter run. It should resolve the issue.
Changing the compileSdkVersion to 30 or 31 in android\app\build.gradle can fix this issue
in pubspec.yaml Change permission_handler TO
permission_handler: ^8.1.5

MissingPluginException(No implementation found for method gps on channel top.kikt/gps)

I am trying to implement https://pub.dev/packages/gps. But while using it it is throwing following exception-
MissingPluginException(No implementation found for method gps on channel top.kikt/gps)
what is this exception and how to fix it.
note -I can not use other libraries it is necessary to implement this library.
i wrote this code to access current position but this piece of code returning null to me
var position = await Gps.currentGps();
build.gradle info
compileSdkVersion 28
minSdkVersion 16
targetSdkVersion 28
var position = await Gps.currentGps();
manifest permission I added-
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Stop the running project
and run the command -
1)flutter clean
2)flutter pub get
and run the app again

Flutter - Execution failed for task ':app:multiDexListDebug'

After adding the plugin webview_flutter_plus and after adding this line in android:usesCleartextTraffic="true" in your <project-directory>/android/app/src/main/AndroidManifest.xml under application
and Required Permissions line
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
I am facing the below error. Can anyone help me out to get this fixed?
Error :
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:multiDexListDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Type io.flutter.plugins.webviewflutter.WebViewFlutterPlugin is defined multiple times: C:\Users\Admin\Downloads\flow-0.1-master\build\webview_media\intermediates\runtime_library_classes\debug\classes.jar:io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.class, C:\Users\Admin\Downloads\flow-0.1-master\build\webview_flutter\intermediates\runtime_library_classes\debug\classes.jar:io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.class
* 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 1m 47s
Exception: Gradle task assembleDebug failed with exit code 1
If your minSdkVersion is set to 21 or higher, multidex is enabled by default and you do not need the multidex support library.
Below 21 API
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3' // add latest dependency
}
Have you tried enabling multiDex in android folder -> app folder -> build.gradle file?
defaultConfig {
multiDexEnabled true
}
this happens because the library you are using uses the same dependences.
in my case,i use package
flutter html : 1.0.0
youtube_player_flutter: ^6.1.0
and both packages use the same dependences, namely webview_flutter so that the error is
io.flutter.plugins.webviewflutter.WebViewFlutterPlugin
Solution
in VSCode Search (Ctrl+Shift + P)
in your error io.flutter.plugins.webviewflutter.WebViewFlutterPlugin search for keywords webview.
Find a library that uses the same dependences, then update to the latest package version.(Work for me)
This solution will keep the library you are using without deleting it.
flutter html : 1.0.0
youtube_player_flutter: ^7.0.0

Flutter, background fetch package not working, androidx incompatibility

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.