Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
79747f49
Commit
79747f49
authored
Aug 24, 2017
by
Mikkel Nygaard Ravn
Committed by
GitHub
Aug 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Gradle error output in Flutter commands (#11703)
parent
8c2c5022
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
29 deletions
+103
-29
gradle_plugin_test.dart
dev/devicelab/bin/tasks/gradle_plugin_test.dart
+91
-28
flutter.gradle
packages/flutter_tools/gradle/flutter.gradle
+6
-0
gradle.dart
packages/flutter_tools/lib/src/android/gradle.dart
+6
-1
No files found.
dev/devicelab/bin/tasks/gradle_plugin_test.dart
View file @
79747f49
...
...
@@ -15,6 +15,7 @@ void main() {
final
Directory
tmp
=
await
Directory
.
systemTemp
.
createTemp
(
'gradle'
);
final
FlutterProject
project
=
await
FlutterProject
.
create
(
tmp
,
'hello'
);
try
{
section
(
'gradlew assembleDebug'
);
await
project
.
runGradleTask
(
'assembleDebug'
);
...
...
@@ -36,11 +37,53 @@ void main() {
await
project
.
addProductFlavor
(
'free'
);
await
project
.
runGradleTask
(
'assembleFreeDebug'
);
await
project
.
parent
.
delete
(
recursive:
true
);
await
project
.
introduceError
();
section
(
'gradlew on build script with error'
);
{
final
ProcessResult
result
=
await
project
.
resultOfGradleTask
(
'assembleRelease'
);
if
(
result
.
exitCode
==
0
)
return
_failure
(
'Gradle did not exit with error as expected'
,
result
);
final
String
output
=
result
.
stdout
+
'
\n
'
+
result
.
stderr
;
if
(
output
.
contains
(
'GradleException'
)
||
output
.
contains
(
'Failed to notify'
)
||
output
.
contains
(
'at org.gradle'
))
return
_failure
(
'Gradle output should not contain stacktrace'
,
result
);
if
(!
output
.
contains
(
'Build failed'
)
||
!
output
.
contains
(
'builTypes'
))
return
_failure
(
'Gradle output should contain a readable error message'
,
result
);
}
section
(
'flutter build apk on build script with error'
);
{
final
ProcessResult
result
=
await
project
.
resultOfFlutterCommand
(
'build'
,
<
String
>[
'apk'
]);
if
(
result
.
exitCode
==
0
)
return
_failure
(
'flutter build apk should fail when Gradle does'
,
result
);
final
String
output
=
result
.
stdout
+
'
\n
'
+
result
.
stderr
;
if
(!
output
.
contains
(
'Build failed'
)
||
!
output
.
contains
(
'builTypes'
))
return
_failure
(
'flutter build apk output should contain a readable Gradle error message'
,
result
);
if
(
_hasMultipleOccurrences
(
output
,
'builTypes'
))
return
_failure
(
'flutter build apk should not invoke Gradle repeatedly on error'
,
result
);
}
return
new
TaskResult
.
success
(
null
);
}
catch
(
e
)
{
return
new
TaskResult
.
failure
(
e
.
toString
());
}
finally
{
project
.
parent
.
deleteSync
(
recursive:
true
);
}
});
}
TaskResult
_failure
(
String
message
,
ProcessResult
result
)
{
print
(
'Unexpected process result:'
);
print
(
'Exit code:
${result.exitCode}
'
);
print
(
'Std out :
\n
${result.stdout}
'
);
print
(
'Std err :
\n
${result.stderr}
'
);
return
new
TaskResult
.
failure
(
message
);
}
bool
_hasMultipleOccurrences
(
String
text
,
Pattern
pattern
)
{
return
text
.
indexOf
(
pattern
)
!=
text
.
lastIndexOf
(
pattern
);
}
class
FlutterProject
{
FlutterProject
(
this
.
parent
,
this
.
name
);
...
...
@@ -90,18 +133,38 @@ android {
'''
);
}
Future
<
Null
>
runGradleTask
(
String
task
)
async
{
final
ProcessResult
result
=
await
Process
.
run
(
'./gradlew'
,
<
String
>[
'-q'
,
'app:
$task
'
],
workingDirectory:
androidPath
,
Future
<
Null
>
introduceError
()
async
{
final
File
buildScript
=
new
File
(
path
.
join
(
androidPath
,
'app'
,
'build.gradle'
),
);
await
buildScript
.
writeAsString
((
await
buildScript
.
readAsString
()).
replaceAll
(
'buildTypes'
,
'builTypes'
));
}
Future
<
Null
>
runGradleTask
(
String
task
)
async
{
final
ProcessResult
result
=
await
resultOfGradleTask
(
task
);
if
(
result
.
exitCode
!=
0
)
{
print
(
'stdout:'
);
print
(
result
.
stdout
);
print
(
'stderr:'
);
print
(
result
.
stderr
);
}
assert
(
result
.
exitCode
==
0
);
if
(
result
.
exitCode
!=
0
)
throw
'Gradle exited with error'
;
}
Future
<
ProcessResult
>
resultOfGradleTask
(
String
task
)
{
return
Process
.
run
(
'./gradlew'
,
<
String
>[
'app:
$task
'
],
workingDirectory:
androidPath
,
);
}
Future
<
ProcessResult
>
resultOfFlutterCommand
(
String
command
,
List
<
String
>
options
)
{
return
Process
.
run
(
path
.
join
(
flutterDirectory
.
path
,
'bin'
,
'flutter'
),
<
String
>[
command
]..
addAll
(
options
),
workingDirectory:
rootPath
,
);
}
}
packages/flutter_tools/gradle/flutter.gradle
View file @
79747f49
...
...
@@ -157,6 +157,9 @@ class FlutterPlugin implements Plugin<Project> {
}
private
void
addFlutterJarProvidedDependency
(
Project
project
)
{
if
(
project
.
state
.
failure
)
{
return
}
project
.
dependencies
{
if
(
flutterJar
!=
null
)
{
provided
project
.
files
(
flutterJar
)
...
...
@@ -204,6 +207,9 @@ class FlutterPlugin implements Plugin<Project> {
}
private
void
addFlutterTask
(
Project
project
)
{
if
(
project
.
state
.
failure
)
{
return
}
if
(
project
.
flutter
.
source
==
null
)
{
throw
new
GradleException
(
"Must provide Flutter source directory"
)
}
...
...
packages/flutter_tools/lib/src/android/gradle.dart
View file @
79747f49
...
...
@@ -97,7 +97,12 @@ Future<GradleProject> _readGradleProject() async {
status
.
stop
();
return
project
;
}
catch
(
e
)
{
printError
(
'Error running gradle:
$e
'
);
if
(
flutterPluginVersion
==
FlutterPluginVersion
.
managed
)
{
printError
(
'Error running Gradle:
\n
$e
\n
'
);
throwToolExit
(
'Please review your Gradle project setup in the android/ folder.'
,
);
}
}
// Fall back to the default
return
new
GradleProject
(<
String
>[
'debug'
,
'profile'
,
'release'
],
<
String
>[],
gradleAppOutDirV1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment