Search code examples
androidgradleflutterandroid-lifecycleandroidx

Flutter returns `lifecycle-common-java8.jar (androidx.lifecycle:lifecycle-common-java8:2.0.0)` error


Flutter project won't run in Android Studio with AndroidX compatibility and returns following errors in Run/Console window:

FAILURE: Build failed with an exception.

And

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.

Solution

  • If you faced those errors just do the following steps:

    1. open Android project in Android Studio (u can open a File or Class in android path then select Open for Editing interface Android Studio like next image)

    enter image description here

    1. In Build window select error line then in right side select Affected Modules:

    enter image description here

    1. For each modules in opened files (build.gradle) add lifecycle-common-java8 api inside dependencies{} section and then Build project:

      dependencies {
      ...
      
       api "androidx.lifecycle:lifecycle-common-java8:2.2.0"
      
      }
      

    enter image description here

    1. Finally close Android project and run Flutter project.