Skip to content

Android build fails with certain plugins if project is in a different drive (from sdk) #105395

Open
@VarunS2002

Description

@VarunS2002

Steps to Reproduce

  1. Create project in a different drive from Flutter SDK
  2. Add shared_preferences and url_launcher to pubspec.yaml and run flutter pub get
  3. Open the android folder with Android Studio or IDEA
  4. Gradle sync fails (error logs below)

I checked stackoverflow and https://stackoverflow.com/a/71734846/13978447 this is the workaround that works for me too.
The build fails only if the project is in a different drive from the drive in which the sdk is in.
My project is in D: and both (Android and Flutter) SDKs are in C:.
I copied the project to C: and the build succeeds.
Although this fixes the issue I do not want to store the project in C: drive (and I shouldn't have to).
I also noticed that using an old version of the plugin shared_preferences: 2.0.6 instead of the latest 2.0.15 fixes the issue for this plugin atleast.

Screenshots and Logs

image

logs_1.txt

image

logs_2.txt

image

logs_3.txt

image

logs_4.txt

image

Flutter Doctor
[√] Flutter (Channel stable, 3.0.1, on Microsoft Windows [Version 10.0.19043.1706], locale en-IN)
    • Flutter version 3.0.1 at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fb57da5f94 (2 weeks ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)                              
    • Android SDK at C:\Users\VARUN\AppData\Local\Android\Sdk                                                 
    • Platform android-Tiramisu, build-tools 32.0.0                                                           
    • ANDROID_HOME = C:\Users\VARUN\AppData\Local\Android\Sdk                                                 
    • ANDROID_SDK_ROOT = C:\Users\VARUN\AppData\Local\Android\Sdk                                             
    • Java binary at: C:\Users\VARUN\.jdks\corretto-11.0.15\bin\java                                          
    • Java version OpenJDK Runtime Environment Corretto-11.0.15.9.1 (build 11.0.15+9-LTS)                     
    • All Android licenses accepted.                                                                          
                                                                                                              
[√] Chrome - develop for the web                                                                              
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe                                   
                                                                                                              
[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.9.3)                               
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools                         
    • Visual Studio Build Tools 2019 version 16.9.31129.286                                                   
    • Windows 10 SDK version 10.0.18362.0                                                                     
                                                                                                              
[!] Android Studio (not installed)                                                                            
    • Android Studio not found; download from https://developer.android.com/studio/index.html                 
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[√] IntelliJ IDEA Ultimate Edition (version 2022.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2022.1
    • Flutter plugin version 68.1.4
    • Dart plugin version 221.5787.37

[√] VS Code, 64-bit edition (version 1.67.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19043.1706]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 102.0.5005.63
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 101.0.1210.39

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Activity

added
in triagePresently being triaged by the triage team
on Jun 6, 2022
huycozy

huycozy commented on Jun 6, 2022

@huycozy
Member

Hi @VarunS2002,
I can not reproduce this issue on the latest stable and master channels.
The project I created on drive D: run well with Flutter SDK located on drive C:

Sample code

The default new created project with adding two dependencies:

  shared_preferences: ^2.0.15
  url_launcher: ^6.1.2
Logs
PS D:\WIP\reproducesample> flutterm run -t .\lib\build_fail_diff_storage_105395.dart
Running "flutter pub get" in reproducesample...                  2,162ms
Launching .\lib\build_fail_diff_storage_105395.dart on Pixel 3a in debug mode...
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Running Gradle task 'assembleDebug'...                             56.7s
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...              2,770ms
Syncing files to device Pixel 3a...                                185ms

Flutter run key commands.
r Hot reload.
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

 Running with sound null safety 

An Observatory debugger and profiler on Pixel 3a is available at: http://127.0.0.1:50155/V-NbAkkmIG8=/
The Flutter DevTools debugger and profiler on Pixel 3a is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:50155/V-NbAkkmIG8=/
flutter doctor -v
[√] Flutter (Channel stable, 3.0.1, on Microsoft Windows [Version 10.0.19043.1706], locale en-US)
    • Flutter version 3.0.1 at C:\WIP\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fb57da5f94 (2 weeks ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\AndroidSDK
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = C:\AndroidSDK
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.6)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.1.32421.90
    • Windows 10 SDK version 10.0.20348.0

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] VS Code (version 1.67.2)
    • VS Code at C:\Users\ADMIN\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.42.0

[√] Connected device (4 available)
    • Pixel 3a (mobile) • 964AY0WL20 • android-arm64  • Android 12 (API 32)
    • Windows (desktop) • windows    • windows-x64    • Microsoft Windows [Version 10.0.19043.1706]
    • Chrome (web)      • chrome     • web-javascript • Google Chrome 102.0.5005.63
    • Edge (web)        • edge       • web-javascript • Microsoft Edge 101.0.1210.53

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
[√] Flutter (Channel master, 3.1.0-0.0.pre.1116, on Microsoft Windows [Version 10.0.19043.1706], locale en-US)
    • Flutter version 3.1.0-0.0.pre.1116 at C:\WIP\flutter_master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 66be43338e (in the future), 2022-06-06 03:53:08 -0400
    • Engine revision 054e4b2af9
    • Dart version 2.18.0 (build 2.18.0-170.0.dev)
    • DevTools version 2.14.0

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\AndroidSDK
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = C:\AndroidSDK
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.6)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.1.32421.90
    • Windows 10 SDK version 10.0.20348.0

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] VS Code (version 1.67.2)
    • VS Code at C:\Users\ADMIN\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.42.0

[√] Connected device (4 available)
    • Pixel 3a (mobile) • 964AY0WL20 • android-arm64  • Android 12 (API 32)
    • Windows (desktop) • windows    • windows-x64    • Microsoft Windows [Version 10.0.19043.1706]
    • Chrome (web)      • chrome     • web-javascript • Google Chrome 102.0.5005.63
    • Edge (web)        • edge       • web-javascript • Microsoft Edge 101.0.1210.53

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

As I can see from your flutter doctor -v:

[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

It seems you're not using Android Studio. What's your current IDEA? Or can you try installing Android Studio and retry?

added
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Jun 6, 2022
VarunS2002

VarunS2002 commented on Jun 6, 2022

@VarunS2002
Author

@huycozy
Oh no don't get me wrong.
flutter run and flutter build apk both work fine.

Which indicates that the gradle tasks assembleDebug and assembleRelease both work.
Only the gradle sync process fails in IDEA when I open the android folder as a project resulting in me unable to use the native Android features in IDEA.
One thing to note is that I am using Android Gradle Build Plugin 7.0.4 instead of the Flutter default 7.1.2 because IDEA 2022.1.2 doesn't support it apparently.

I will install and setup Android Studio to test the same but I will need a few days time so please don't close the issue by then,

removed
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Jun 6, 2022
VarunS2002

VarunS2002 commented on Jun 6, 2022

@VarunS2002
Author

@huycozy Oh no don't get me wrong. flutter run and flutter build apk both work fine.

Which indicates that the gradle tasks assembleDebug and assembleRelease both work. Only the gradle sync process fails in IDEA when I open the android folder as a project resulting in me unable to use the native Android features in IDEA. One thing to note is that I am using Android Gradle Build Plugin 7.0.4 instead of the Flutter default 7.1.2 because IDEA 2022.1.2 doesn't support it apparently.

I will install and setup Android Studio to test the same but I will need a few days time so please don't close the issue by then,

I tried it with the latest Android Studio Chipmunk 2021.2.1 Patch 1 but the issue persists.

With Android Gradle Plugin 7.0.4:

image

With Android Gradle Plugin 7.1.2:

image

VarunS2002

VarunS2002 commented on Jun 6, 2022

@VarunS2002
Author

@huycozy Oh no don't get me wrong. flutter run and flutter build apk both work fine.
Which indicates that the gradle tasks assembleDebug and assembleRelease both work. Only the gradle sync process fails in IDEA when I open the android folder as a project resulting in me unable to use the native Android features in IDEA. One thing to note is that I am using Android Gradle Build Plugin 7.0.4 instead of the Flutter default 7.1.2 because IDEA 2022.1.2 doesn't support it apparently.
I will install and setup Android Studio to test the same but I will need a few days time so please don't close the issue by then,

I tried it with the latest Android Studio Chipmunk 2021.2.1 Patch 1 but the issue persists.

With Android Gradle Plugin 7.0.4:

image

With Android Gradle Plugin 7.1.2:

image

I created a new empty project to reproduce the issue which I'm attaching here:
test.zip

New Flutter Doctor output
[√] Flutter (Channel stable, 3.0.1, on Microsoft Windows [Version 10.0.19043.1706], locale en-IN)
    • Flutter version 3.0.1 at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fb57da5f94 (3 weeks ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at C:\Users\VARUN\AppData\Local\Android\Sdk
    • Platform android-Tiramisu, build-tools 32.1.0-rc1
    • ANDROID_HOME = C:\Users\VARUN\AppData\Local\Android\Sdk
    • ANDROID_SDK_ROOT = C:\Users\VARUN\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.9.3)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
    • Visual Studio Build Tools 2019 version 16.9.31129.286
    • Windows 10 SDK version 10.0.18362.0

[√] Android Studio (version 2021.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)

[√] IntelliJ IDEA Ultimate Edition (version 2022.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2022.1
    • Flutter plugin version 68.1.4
    • Dart plugin version 221.5787.37

[√] VS Code, 64-bit edition (version 1.67.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19043.1706]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 102.0.5005.63
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 101.0.1210.39

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

huycozy

huycozy commented on Jun 7, 2022

@huycozy
Member

@VarunS2002

Opened your test.zip and see the version is different than you reported.
It's using 7.1.2:

classpath 'com.android.tools.build:gradle:7.1.2'

Anyway, I got the same error when creating new project and adding dependencies as above mentioned.

Logs
Could not create task ':shared_preferences_android:generateDebugUnitTestConfig'.
this and base files have different roots: D:\WIP\test_flutter_gradle\build\shared_preferences_android and C:\Users\ADMIN\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\shared_preferences_android-2.0.12\android.

The temporary workaround is to use lower gradle 4.1.3:

classpath 'com.android.tools.build:gradle:4.1.3'

FYI, there is a completed work here #87649 in order to support for Android Gradle Plugin 7.0.0, but it's not supported for first party packages/plugins yet. Follow up on #88666 for further updates.

I'm closing the current one as a duplicate.
If you disagree, please write in the comments and I will reopen it.

added
r: duplicateIssue is closed as a duplicate of an existing issue
and removed
in triagePresently being triaged by the triage team
on Jun 7, 2022
VarunS2002

VarunS2002 commented on Jun 7, 2022

@VarunS2002
Author

The version was different because I created a new project in the latest Android Studio to test this issue (to check whether IDEA or AGB 7.0.4 was the problem). My main project still has AGP 7.04 and throws the same error.

Either way you're able to reproduce the error so it doesn't matter.

VarunS2002

VarunS2002 commented on Jun 7, 2022

@VarunS2002
Author

Also I'm curious why this happens only on a different drive and works fine on the drive that has the sdk?

reopened this on Jun 7, 2022
huycozy

huycozy commented on Jun 7, 2022

@huycozy
Member

Also I'm curious why this happens only on a different drive and works fine on the drive that has the sdk?

You're right, it worked well on the same drive even with default Gradle 7.1.2. It means that we don't need to update anything from new project when creating the project in the same drive with Flutter SDK.

Reopen this issue for further investigation from the team due to this issue's occurring in a special case, it is unlikely that #88666 will be aware/fix it next time.

69 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: pluginsSupport for writing, building, and running plugin packagescustomer: crowdAffects or could affect many people, though not necessarily a specific customer.found in release: 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @stuartmorgan-g@Hixie@praveenb@absar@MrTaz

        Issue actions

          Android build fails with certain plugins if project is in a different drive (from sdk) · Issue #105395 · flutter/flutter