1

i try to devolop an app using flutter so i add these dependencies(file_picker: ^2.1.0,path: ^1.7.0, dio: ^3.0.10,) but i got this error when i remove these dependencies the error is gone and when I add them, the error comes back i tried some solution in the stackoverflow but couldn't solve it

`
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\hp\AndroidStudioProjects\youtubeclone\build\file_picker\intermediates\library_manifest\debug\AndroidManifest.xml:9:5-15:15: AAPT: error: unexpected element <queries> found in <manifest>.


* 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 45s
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 file_picker...

C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:10: error: cannot find symbol
import androidx.lifecycle.DefaultLifecycleObserver;
                         ^
  symbol:   class DefaultLifecycleObserver
  location: package androidx.lifecycle
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:20: error: cannot find symbol
import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter;
                                                    ^
  symbol:   class FlutterLifecycleAdapter
  location: package io.flutter.embedding.engine.plugins.lifecycle
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:38: error: cannot find symbol
            implements Application.ActivityLifecycleCallbacks, DefaultLifecycleObserver {
                                                               ^
  symbol:   class DefaultLifecycleObserver
  location: class FilePickerPlugin
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:45: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:49: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:53: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:57: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:61: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:66: error: method does not override or implement a method from a supertype
        @Override
        ^
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:277: error: cannot find symbol
            this.lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(activityBinding);
                             ^
  symbol:   variable FlutterLifecycleAdapter
  location: class FilePickerPlugin
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:278: error: incompatible types: FilePickerPlugin.LifeCycleObserver cannot be converted to LifecycleObserver
            this.lifecycle.addObserver(this.observer);
                                           ^
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\file_picker-2.1.0\android\src\main\java\com\mr\flutter\plugin\filepicker\FilePickerPlugin.java:287: error: incompatible types: FilePickerPlugin.LifeCycleObserver cannot be converted to LifecycleObserver
            this.lifecycle.removeObserver(this.observer);
                                              ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
12 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileReleaseJavaWithJavac'.
> 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 11s

Exception: The plugin file_picker could not be built due to the issue above.
`

this is my build.gradle

`def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.zaidounmohamed.youtubeclone"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

`

this is my code

`import 'package:dio/dio.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:path/path.dart';

class CustomFilePicker extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _CustomFilePicker();
  }
}

class _CustomFilePicker extends State<CustomFilePicker> {
  FilePickerResult selectedfile;
  Response response;
  String progress;
  Dio dio = new Dio();

  selectFile() async {
    selectedfile = await FilePicker.platform.pickFiles(
      type: FileType.custom,
      allowedExtensions: ['jpg', 'pdf', 'mp4', 'doc'],
      //allowed extension to choose
    );
    setState(() {}); //update the UI so that file name is shown
  }

  uploadFile() async {
    String uploadurl = "http://192.168.0.112/test/file_upload.php";
    //dont use http://localhost , because emulator don't get that address
    //insted use your local IP address or use live URL
    //hit "ipconfig" in windows or "ip a" in linux to get you local IP

    FormData formdata = FormData.fromMap({
      "file": await MultipartFile.fromFile(selectedfile.paths.toString(),
          filename: basename(selectedfile.paths.toString())
          //show only filename from path
          ),
    });

    response = await dio.post(
      uploadurl,
      data: formdata,
      onSendProgress: (int sent, int total) {
        String percentage = (sent / total * 100).toStringAsFixed(2);
        setState(() {
          progress = "$sent" +
              " Bytes of " "$total Bytes - " +
              percentage +
              " % uploaded";
          //update the progress
        });
      },
    );

    if (response.statusCode == 200) {
      print(response.toString());
      //print response from server
    } else {
      print("Error during connection to server.");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("Select File and Upload"),
          backgroundColor: Colors.orangeAccent,
        ), //set appbar
        body: Container(
            alignment: Alignment.center,
            padding: EdgeInsets.all(40),
            child: Column(
              children: <Widget>[
                Container(
                  margin: EdgeInsets.all(10),
                  //show file name here
                  child: progress == null
                      ? Text("Progress: 0%")
                      : Text(
                          basename("Progress: $progress"),
                          textAlign: TextAlign.center,
                          style: TextStyle(fontSize: 18),
                        ),
                  //show progress status here
                ),

                Container(
                  margin: EdgeInsets.all(10),
                  //show file name here
                  child: selectedfile == null
                      ? Text("Choose File")
                      : Text(basename(selectedfile.paths.toString())),
                  //basename is from path package, to get filename from path
                  //check if file is selected, if yes then show file name
                ),

                Container(
                    child: RaisedButton.icon(
                  onPressed: () {
                    selectFile();
                  },
                  icon: Icon(Icons.folder_open),
                  label: Text("CHOOSE FILE"),
                  color: Colors.redAccent,
                  colorBrightness: Brightness.dark,
                )),

                //if selectedfile is null then show empty container
                //if file is selected then show upload button
                selectedfile == null
                    ? Container()
                    : Container(
                        child: RaisedButton.icon(
                        onPressed: () {
                          uploadFile();
                        },
                        icon: Icon(Icons.folder_open),
                        label: Text("UPLOAD FILE"),
                        color: Colors.redAccent,
                        colorBrightness: Brightness.dark,
                      ))
              ],
            )));
  }
}`
1
  • 1
    try what this answer says. Commented Nov 20, 2020 at 16:04

2 Answers 2

7
  1. Delete the .gradle folder inside the android folder

  2. In the project build.gradle file, upgrade your class path

    Example: classpath 'com.android.tools.build:gradle:4.0.0'

  3. Goto android>gradle>gradle-wrapper.properties file and upgrade the distribution url.

    Example: distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.0-all.zip

  4. Invalidate caches and restart your android studio and it will download the new gradle files.

Sign up to request clarification or add additional context in comments.

Comments

0

Usually, androidResourceLinkingFailed errors are solved by clearing caches.

If you are using Android Studio, Go to File > Invalidate Caches / Restart and restart your IDE, or run this command in terminal: flutter clean.

1 Comment

i run it and nothing change but i will run it again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.