flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

Execution failed for task ':permission_handler_android:compileDebugJavaWithJavac'.

Open aawhitfield opened this issue 2 years ago • 4 comments

🐛 Bug Report

error: warnings found and -Werror specified 1 error

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':permission_handler_android:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

Expected behavior

Should compile

Reproduction steps

Run flutter run

Configuration

Version: 9.2.0

Platform:

  • [ ] :iphone: iOS
  • [ X] :robot: Android

aawhitfield avatar Sep 12 '22 04:09 aawhitfield

I resolved the issue. Change your compile and targeted version to 33 Solution 1

compileSdkVersion 33
defaultConfig {
        
        minSdkVersion 21
        targetSdkVersion 33
...
    }

Solution 2 downgrade permissin_handler to 9.2.0

kashiflab avatar Sep 16 '22 06:09 kashiflab

You should up your compileSdkVersion to 33 image

mvavld avatar Sep 19 '22 08:09 mvavld

你应该把你的 compileSdkVersion 提高到 33 图片

But another one need 31,how can I solve this problem?

Jambooo avatar Sep 21 '22 09:09 Jambooo

你应该把你的 compileSdkVersion 提高到 33 图片

But another one need 31,how can I solve this problem?

Update your pub dev

flutter pub upgrade

kashiflab avatar Sep 21 '22 10:09 kashiflab

You should up your compileSdkVersion to 33 image

it worked

Saddi993 avatar Jan 25 '23 14:01 Saddi993

@Saddi993 I am facing the same issue, I have compileSdkVersion 33

strmchsr avatar May 30 '23 03:05 strmchsr

@strmchsr,

What version of the permission handler are you using?

TimHoogstrate avatar Jun 29 '23 13:06 TimHoogstrate

I came into the same issue with permission_handler 9.0.2+1

TLiana avatar Jun 30 '23 03:06 TLiana

Hi, I have the same issue with permission_handler: ^10.4.0. It works fine when building the app (I see no errors), but it throws when trying to run integration tests using Patrol.

	FAILURE: Build failed with an exception.
	
	* What went wrong:
	Execution failed for task ':permission_handler_android: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

We have these sdk settings: compileSdkVersion 33, minSdkVersion 23, targetSdkVersion 33.

tenhobi avatar Jun 30 '23 08:06 tenhobi

Update: I uninstalled openjdk (20) and installed openjdk@11 and it seems to work now. 🤔

tenhobi avatar Jun 30 '23 08:06 tenhobi

(10.4.2) ('com.android.tools.build:gradle:7.4.2') (distributionUrl=https://services.gradle.org/distributions/gradle-7.5-bin.zip)

in my case compileSdkVersion 33 still not working build pass on Android Platform everything seems fine, but flutter runs into error: "Execution failed for task ':permission_handler_android:compileDebugJavaWithJavac'."

update: upgrade flutter to 3.7.7 solved

AkashiWen avatar Jul 12 '23 02:07 AkashiWen

Closing this issue as these are all related to local environment. Things to verify are:

  • Make sure the environment uses JDK 11 or higher.
  • Make sure the compileSdkVersion is set to 33 in the android/app/build.gradle file.

If this still causes problems, please file a new bug with complete log output by running the flutter build apk -v (or flutter build appbundle -v when build an Android application bundle).

mvanbeusekom avatar Jul 12 '23 09:07 mvanbeusekom

@kashiflab Currently, I can successfully compile and build an APK for my Flutter application without encountering any issues. However, as soon as I include the 'permission_handler' package, I am unable to do so. I have tried using multiple versions of the 'permission_handler' package, and compileSdkVersion 33 targetSdkVersion 33 but the problem persists. The error message I receive is as follows:

error: warnings found and -Werror specified

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':permission_handler_android:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

essyty avatar Jul 20 '23 09:07 essyty

@essyty can you please tell me which 'permission_handler' version are you using?

kashiflab avatar Jul 20 '23 09:07 kashiflab

@essyty can you please tell me which 'permission_handler' version are you using?

The last version, 10.4.3, and i tried other versions

essyty avatar Jul 20 '23 09:07 essyty

@essyty Please double-check the documentation of the permission handler maybe you are missing some steps

The TL;DR version is:

Add the following to your "gradle.properties" file: android.useAndroidX=true android.enableJetifier=true

Make sure you set the compileSdkVersion in your "android/app/build.gradle" file to 33: android { compileSdkVersion 33 ... }

Also upgrade flutter

kashiflab avatar Jul 20 '23 09:07 kashiflab

i ll add this 2 lines and i see android.useAndroidX=true android.enableJetifier=true everything else is correct

essyty avatar Jul 20 '23 09:07 essyty

Hi @essyty,

The problem seems to be related to the -Werror switch the permission_handler includes in it's build.gradle file.

Basically this switch makes sure the code only compiles when the build process doesn't throw any warnings. I think this switch populates to the whole application and doesn't solely stick to the permission_handler plugin alone.

In hindsight this is a bit to restrictive and developers/ companies should be able to determine themselves how to threat warnings. Therefore I will release a new version where I will remove the -Werror switch and move it into our example application. This way we will still make sure warning will be treated as errors when the CI builds the example application. However, consumers of the permission_handler plugin will not inherit this setting and should be able to configure it for themselves.

I will inform you here when the new build is ready. Would be great if you'd be able to confirm if it solves the problem.

mvanbeusekom avatar Jul 20 '23 09:07 mvanbeusekom

I changed the java's version installed in my computer from 20 to 11 and i can compil my code now ... i really don't know why. but when i build the apk it does not show me the permission dialog

main.dart : import 'package:flutter/material.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_web_plugins/url_strategy.dart'; import 'package:provider/provider.dart';

import 'flutter_flow/flutter_flow_theme.dart'; import 'flutter_flow/flutter_flow_util.dart'; import 'flutter_flow/internationalization.dart'; import 'flutter_flow/nav/nav.dart'; import 'index.dart';

void main() async { WidgetsFlutterBinding.ensureInitialized(); usePathUrlStrategy();

await FlutterFlowTheme.initialize();

final appState = FFAppState(); // Initialize FFAppState await appState.initializePersistedState();

runApp(ChangeNotifierProvider( create: (context) => appState, child: MyApp(), )); }

class MyApp extends StatefulWidget { // This widget is the root of your application. @override State<MyApp> createState() => _MyAppState();

static _MyAppState of(BuildContext context) => context.findAncestorStateOfType<_MyAppState>()!; }

class _MyAppState extends State<MyApp> { Locale? _locale; ThemeMode _themeMode = FlutterFlowTheme.themeMode; late AppStateNotifier _appStateNotifier; late GoRouter _router; late Future storagePermissionChecker;

@override void initState() { super.initState(); _appStateNotifier = AppStateNotifier.instance; _router = createRouter(_appStateNotifier); storagePermissionChecker = checkStoragePermission(); }

Future checkStoragePermission() async { final result = await Permission.storage.status; setState(() {}); if (result.isGranted) { return 1; } return requestStoragePermission(); }

Future requestStoragePermission() async { final result = await Permission.storage.request(); return result.isGranted ? 1 : 0; }

void setLocale(String language) { setState(() => _locale = createLocale(language)); }

void setThemeMode(ThemeMode mode) => setState(() { _themeMode = mode; FlutterFlowTheme.saveThemeMode(mode); });

@override Widget build(BuildContext context) { return MaterialApp.router( title: 'GP12', localizationsDelegates: [ FFLocalizationsDelegate(), GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], locale: _locale, supportedLocales: const [Locale('en', '')], theme: ThemeData(brightness: Brightness.light), darkTheme: ThemeData(brightness: Brightness.dark), themeMode: _themeMode, routerConfig: _router, ); } }

essyty avatar Jul 20 '23 11:07 essyty

Update : I think the problem in Android 13, i installed the app in device with Android 12 and it's works

essyty avatar Jul 20 '23 11:07 essyty

@essyty, since you are requesting storage permissions, please carefully read our FAQ on this topic.

mvanbeusekom avatar Jul 20 '23 11:07 mvanbeusekom