Repository: flutter
Issue: Build aar fails if one plugin depends on another plugin in gradle.
Labels: c: crash,platform-android,tool,t: gradle,P2,team-android,triaged-android

I have a project structured like this:

project
    | - pluginA
    | - some directory
            | - pluginB

pluginA depends on pluginB.

When run flutter build aar in project directory, I got this:
<details>
  <summary>error</summary>

```
[  +13 ms] Gradle task assembleAarDebug failed with exit code 1
[  +58 ms] FAILURE: Build failed with an exception.
[        ] * Where:
[        ] Script 'flutter/packages/flutter_tools/gradle/flutter.gradle' line: 929
[        ] * What went wrong:
[        ] Execution failed for task ':flutter:buildPluginDebugMethodChannel'.
[        ] > Process 'command 'flutter/bin/flutter'' finished with non-zero exit value 1
[        ] * 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
[   +1 ms] Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
[        ] See https://docs.gradle.org/4.6/userguide/command_line_interface.html#sec:command_line_warnings
[        ] BUILD FAILED in 24s
[ +397 ms] Running Gradle task 'assembleAarDebug'... (completed in 25.2s)
[   +3 ms] "flutter aar" took 28,766ms.
Gradle task assembleAarDebug failed with exit code 1

#0      throwToolExit (package:flutter_tools/src/base/common.dart:28:3)
#1      buildGradleAar (package:flutter_tools/src/android/gradle.dart:577:5)
<asynchronous suspension>
#2      AarBuilderImpl.build (package:flutter_tools/src/android/aar.dart:54:11)
<asynchronous suspension>
#3      BuildAarCommand.runCommand (package:flutter_tools/src/commands/build_aar.dart:77:22)
<asynchronous suspension>
#4      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:490:18)
<asynchronous suspension>
#5      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:407:33)
<asynchronous suspension>
#6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:154:29)
<asynchronous suspension>
#7      _rootRun (dart:async/zone.dart:1124:13)
#8      _CustomZone.run (dart:async/zone.dart:1021:19)
#9      _runZoned (dart:async/zone.dart:1516:10)
#10     runZoned (dart:async/zone.dart:1463:12)
#11     AppContext.run (package:flutter_tools/src/base/context.dart:153:18)
<asynchronous suspension>
#12     FlutterCommand.run (package:flutter_tools/src/runner/flutter_command.dart:397:20)
#13     CommandRunner.runCommand (package:args/command_runner.dart:197:27)
<asynchronous suspension>
#14     FlutterCommandRunner.runCommand.<anonymous closure>
(package:flutter_tools/src/runner/flutter_command_runner.dart:402:21)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:154:29)
<asynchronous suspension>
#16     _rootRun (dart:async/zone.dart:1124:13)
#17     _CustomZone.run (dart:async/zone.dart:1021:19)
#18     _runZoned (dart:async/zone.dart:1516:10)
#19     runZoned (dart:async/zone.dart:1463:12)
#20     AppContext.run (package:flutter_tools/src/base/context.dart:153:18)
<asynchronous suspension>
#21     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:356:19)
<asynchronous suspension>
#22     CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:112:25)
#23     new Future.sync (dart:async/future.dart:224:31)
#24     CommandRunner.run (package:args/command_runner.dart:112:14)
#25     FlutterCommandRunner.run (package:flutter_tools/src/runner/flutter_command_runner.dart:242:18)
#26     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:63:22)
<asynchronous suspension>
#27     _rootRun (dart:async/zone.dart:1124:13)
#28     _CustomZone.run (dart:async/zone.dart:1021:19)
#29     _runZoned (dart:async/zone.dart:1516:10)
#30     runZoned (dart:async/zone.dart:1500:12)
#31     run.<anonymous closure> (package:flutter_tools/runner.dart:61:18)
<asynchronous suspension>
#32     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:154:29)
<asynchronous suspension>
#33     _rootRun (dart:async/zone.dart:1124:13)
#34     _CustomZone.run (dart:async/zone.dart:1021:19)
#35     _runZoned (dart:async/zone.dart:1516:10)
#36     runZoned (dart:async/zone.dart:1463:12)
#37     AppContext.run (package:flutter_tools/src/base/context.dart:153:18)
<asynchronous suspension>
#38     runInContext (package:flutter_tools/src/context_runner.dart:59:24)
<asynchronous suspension>
#39     run (package:flutter_tools/runner.dart:50:10)
#40     main (package:flutter_tools/executable.dart:65:9)
<asynchronous suspension>
#41     main (file:///Users/gt/tools/flutter/packages/flutter_tools/bin/flutter_tools.dart:8:3)
#42     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:303:32)
#43     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
```

</details>

After doing some research, I found out the following informations:
- the project causing build failure is pluginA
- flutter build aar is recursively executed under every plugin project
- every plugin project seems to be treated as a root project
- real error is Project with path ':pluginB' could not be found in root project 'pluginA'


flutter doctor -v
```
[✓] Flutter (Channel unknown, v1.9.1+hotfix.6, on Mac OS X 10.14.6 18G1012, locale zh-Hans-CN)
    • Flutter version 1.9.1+hotfix.6 at /Users/gt/tools/flutter
    • Framework revision 68587a0916 (2 months ago), 2019-09-13 19:46:58 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/gt/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/gt/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✗] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin
        usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install:
        sudo gem install cocoapods

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 40.0.2
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.40.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.6.0

[✓] Connected device (1 available)
    • MIX 2 • 6ba49c5b • android-arm64 • Android 8.0.0 (API 26)

! Doctor found issues in 1 category.
```