How to solve permission handler error in flutter? - 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

Related

Unable to add firebase_messaging to flutter module

I wanted to add firebase_messaging package to my flutter module and failing to build aar. I am using flutter 3.0.1. Steps to reproduce:
flutter create -t module --org com.example my_flutter_abc
cd my_flutter_abc
flutter pub add firebase_messaging
flutter build aar
Getting the following error
Running "flutter pub get" in my_flutter_abc... 2,428ms
Building with sound null safety
Running Gradle task 'assembleAarDebug'... 33.6s
Warning: The plugin firebase_messaging requires Android SDK version 33.
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to C:\workspace\flutter-module\my_flutter_abc\.android\Flutter\build.gradle:
android {
compileSdkVersion 33
...
}
c:\flutter_3_0_1\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-14.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:399: error: cannot find symbol
.checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS)
^
symbol: variable POST_NOTIFICATIONS
location: class permission
c:\flutter_3_0_1\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-14.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebasePermissionManager.java:63: error: cannot find symbol
permissions.add(Manifest.permission.POST_NOTIFICATIONS);
^
symbol: variable POST_NOTIFICATIONS
location: class permission
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: c:\flutter_3_0_1\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-14.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':firebase_messaging: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 32s
Gradle task assembleAarDebug failed with exit code 1.
Modified my_flutter_abc.android\Flutter\build.gradle to use
android {
compileSdkVersion 33
....
}
then getting the following error when run flutter build aar again
Building with sound null safety
Running Gradle task 'assembleAarDebug'... 15.8s
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: c:\flutter_3_0_1\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-14.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':firebase_messaging:uploadArchives'.
> Could not publish configuration 'archives'
> Could not write to file 'c:\flutter_3_0_1\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-14.1.4\android\build\poms\pom-default.xml'.
* 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 14s
Gradle task assembleAarDebug failed with exit code 1.
The gradle files are automatically generated when flutter build command is executed. There seems to be compatibility issues related to firebase_messaging package. When I remove this package from pubspec.yaml, everything works fine.
This issue is not seen when flutter app project is created.

I always fail to run with an error description in the flutter contact picker

This problem only exists when I run it on Android, for iOS there is no problem, I run it smoothly.
This is an error display when I try to run it :
e: /Users/yohanescatur/Documents/Development/flutter/.pub-cache/hosted/pub.dartlang.org/fluttercontactpicker-4.2.1/android/src/main/kotlin/me/schlaubi/fluttercontactpicker/ContactPicker.kt: (52, 280): Unresolved reference: stackTraceToString
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':fluttercontactpicker:compileDebugKotlin'.
Compilation error. See log for more 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 28s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
can you help me find this problem?
set kotlin to 1.4.21
this is what i did to solve this problem.
set kotlin to 1.5.10
this is what i did to solve this problem.
please flutter clean and pub get after upgrade kotlin version

Flutter Execution failed for task ':audioplayers:compileDebugKotlin'

I tried installing audioplayers: ^0.17.1 and ran my flutter project. It throws the following error. Can someone help, please?
e: C:\Users\User\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (181, 52): Expecting a parameter declaration
e: C:\Users\User\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (231, 38): Expecting an argument
e: C:\Users\User\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\ByteDataSource.kt: (8, 37): Expecting a parameter declaration
e: C:\Users\User\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedMediaPlayer.kt: (10, 39): Expecting a parameter declaration
e: C:\Users\User\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (168, 32): Expecting a parameter declaration
e: C:\Users\User\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (205, 26): Expecting an argument
e: C:\Users\User\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (46, 77): Type inference failed. Expected type mismatch: inferred type is List<???> but MutableList<WrappedSoundPool> was expected
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':audioplayers:compileDebugKotlin'.
> Compilation error. See log for more 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 37s
Exception: Gradle task assembleDebug failed with exit code 1
I had been struggling with this issue since morning and finally here are 2 fixes:
Upgrade to flutter 2.0 and then update audioplayers dependency to 0.19.0 in pubspec.yaml
*in the build.gradle change ext.kotlin_version to '1.4.32'
or
If you don't want to upgrade to flutter 2.0 due to some reasons then downgrade your audioplayers dependency to ^0.16.0.
Note: To update Flutter SDK use the flutter upgrade command.
The current latest version is 0.18.0, but I faced the same problem. And I could solve that problem by following Gradle Build Failing.
In order to support the playBytes method, this has a hard requirement on using API >= 23 features, and your build may failure depending on your minimum SDK targeting. To override this, you will need to add
<uses-sdk tools:overrideLibrary="xyz.luan.audioplayers"/> to your AndroidManifest.xml file.
If you still facing an error on the compiling, you should change version of kotline following this issue.
faced same issue, fixed by updating ext.kotlin_version to 1.4.31 in android/build.gradle.
Downgrade your audioplayers dependency to ^0.16.0
Open C:\Users\User\flutter.pub-cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\ folder and delete it.
It helps me

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: Build Error: Execution failed for task ':app:processDebugResources'

Everything was working fine before upgrading flutter to v1.17.3,
Already tried:
flutter clean
And
flutter downgrade
Error that I'm getting (Build Fail):
FAILURE: Build failed with an exception.
* 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
C:\Users\Shamuvel\Desktop\App Development\PROJECTS\Grocery Store\groci\android\Store\groci\android\app\src\main\AndroidManifest.xml:8:5-47:19: AAPT: error: attribute android:requestLegacyExternalStorage 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 1m 27s
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 path_provider...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'path_provider'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* 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 5s
Exception: The plugin path_provider could not be built due to the issue above.
gradle.properties file:
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
Solutions Appreciated
Thanks!
Finally, switching compileSdkVersion & targetSdkVersion from 28 to 29 in android/app/build.gradle file worked.
Check these solutions as well, might help you:-
AAPT: error: attribute android:requestLegacyExternalStorage not found
Flutter: Debug build successful but release gives error
Go to File->Project Structure->Project->Project SDK
and select the latest SDK.
I am a rookie in flutter app development and faced this problem in the very first app I was building.
Fix it with remove android:networkSecurityConfig="#xml/network_security_config" from android manifest.