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
6d03cb65
Unverified
Commit
6d03cb65
authored
May 28, 2021
by
Jenn Magder
Committed by
GitHub
May 28, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up null assumptions for Gradle classes (#83443)
parent
43e31977
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
56 deletions
+65
-56
gradle.dart
packages/flutter_tools/lib/src/android/gradle.dart
+9
-8
gradle_errors.dart
packages/flutter_tools/lib/src/android/gradle_errors.dart
+42
-42
gradle_utils.dart
packages/flutter_tools/lib/src/android/gradle_utils.dart
+14
-6
No files found.
packages/flutter_tools/lib/src/android/gradle.dart
View file @
6d03cb65
...
@@ -190,7 +190,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
...
@@ -190,7 +190,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
@required
FlutterProject
project
,
@required
FlutterProject
project
,
@required
Set
<
AndroidBuildInfo
>
androidBuildInfo
,
@required
Set
<
AndroidBuildInfo
>
androidBuildInfo
,
@required
String
target
,
@required
String
target
,
@required
String
outputDirectoryPath
,
String
outputDirectoryPath
,
@required
String
buildNumber
,
@required
String
buildNumber
,
})
async
{
})
async
{
Directory
outputDirectory
=
Directory
outputDirectory
=
...
@@ -361,7 +361,8 @@ class AndroidGradleBuilder implements AndroidBuilder {
...
@@ -361,7 +361,8 @@ class AndroidGradleBuilder implements AndroidBuilder {
if
(
target
!=
null
)
{
if
(
target
!=
null
)
{
command
.
add
(
'-Ptarget=
$target
'
);
command
.
add
(
'-Ptarget=
$target
'
);
}
}
if
(
project
.
manifest
.
deferredComponents
!=
null
)
{
final
List
<
DeferredComponent
>
deferredComponents
=
project
.
manifest
.
deferredComponents
;
if
(
deferredComponents
!=
null
)
{
if
(
deferredComponentsEnabled
)
{
if
(
deferredComponentsEnabled
)
{
command
.
add
(
'-Pdeferred-components=true'
);
command
.
add
(
'-Pdeferred-components=true'
);
androidBuildInfo
.
buildInfo
.
dartDefines
.
add
(
'validate-deferred-components=
$validateDeferredComponents
'
);
androidBuildInfo
.
buildInfo
.
dartDefines
.
add
(
'validate-deferred-components=
$validateDeferredComponents
'
);
...
@@ -369,7 +370,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
...
@@ -369,7 +370,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
// Pass in deferred components regardless of building split aot to satisfy
// Pass in deferred components regardless of building split aot to satisfy
// android dynamic features registry in build.gradle.
// android dynamic features registry in build.gradle.
final
List
<
String
>
componentNames
=
<
String
>[];
final
List
<
String
>
componentNames
=
<
String
>[];
for
(
final
DeferredComponent
component
in
project
.
manifest
.
deferredComponents
)
{
for
(
final
DeferredComponent
component
in
deferredComponents
)
{
componentNames
.
add
(
component
.
name
);
componentNames
.
add
(
component
.
name
);
}
}
if
(
componentNames
.
isNotEmpty
)
{
if
(
componentNames
.
isNotEmpty
)
{
...
@@ -756,7 +757,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
...
@@ -756,7 +757,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
Future
<
void
>
buildPluginsAsAar
(
Future
<
void
>
buildPluginsAsAar
(
FlutterProject
flutterProject
,
FlutterProject
flutterProject
,
AndroidBuildInfo
androidBuildInfo
,
{
AndroidBuildInfo
androidBuildInfo
,
{
Directory
buildDirectory
,
@required
Directory
buildDirectory
,
})
async
{
})
async
{
final
File
flutterPluginFile
=
flutterProject
.
flutterPluginsFile
;
final
File
flutterPluginFile
=
flutterProject
.
flutterPluginsFile
;
if
(!
flutterPluginFile
.
existsSync
())
{
if
(!
flutterPluginFile
.
existsSync
())
{
...
@@ -806,14 +807,13 @@ class AndroidGradleBuilder implements AndroidBuilder {
...
@@ -806,14 +807,13 @@ class AndroidGradleBuilder implements AndroidBuilder {
/// Prints how to consume the AAR from a host app.
/// Prints how to consume the AAR from a host app.
void
printHowToConsumeAar
(
{
void
printHowToConsumeAar
(
{
@required
Set
<
String
>
buildModes
,
@required
Set
<
String
>
buildModes
,
@required
String
androidPackage
,
String
androidPackage
=
'unknown'
,
@required
Directory
repoDirectory
,
@required
Directory
repoDirectory
,
@required
Logger
logger
,
@required
Logger
logger
,
@required
FileSystem
fileSystem
,
@required
FileSystem
fileSystem
,
String
buildNumber
,
String
buildNumber
,
})
{
})
{
assert
(
buildModes
!=
null
&&
buildModes
.
isNotEmpty
);
assert
(
buildModes
!=
null
&&
buildModes
.
isNotEmpty
);
assert
(
androidPackage
!=
null
);
assert
(
repoDirectory
!=
null
);
assert
(
repoDirectory
!=
null
);
buildNumber
??=
'1.0'
;
buildNumber
??=
'1.0'
;
...
@@ -919,10 +919,11 @@ Iterable<String> findApkFilesModule(
...
@@ -919,10 +919,11 @@ Iterable<String> findApkFilesModule(
if
(
apkFile
.
existsSync
())
{
if
(
apkFile
.
existsSync
())
{
return
<
File
>[
apkFile
];
return
<
File
>[
apkFile
];
}
}
if
(
buildInfo
.
flavor
!=
null
)
{
final
String
flavor
=
buildInfo
.
flavor
;
if
(
flavor
!=
null
)
{
// Android Studio Gradle plugin v3 adds flavor to path.
// Android Studio Gradle plugin v3 adds flavor to path.
apkFile
=
apkDirectory
apkFile
=
apkDirectory
.
childDirectory
(
buildInfo
.
flavor
)
.
childDirectory
(
flavor
)
.
childDirectory
(
modeName
)
.
childDirectory
(
modeName
)
.
childFile
(
apkFileName
);
.
childFile
(
apkFileName
);
if
(
apkFile
.
existsSync
())
{
if
(
apkFile
.
existsSync
())
{
...
...
packages/flutter_tools/lib/src/android/gradle_errors.dart
View file @
6d03cb65
...
@@ -18,8 +18,8 @@ typedef GradleErrorTest = bool Function(String);
...
@@ -18,8 +18,8 @@ typedef GradleErrorTest = bool Function(String);
/// A Gradle error handled by the tool.
/// A Gradle error handled by the tool.
class
GradleHandledError
{
class
GradleHandledError
{
const
GradleHandledError
({
const
GradleHandledError
({
this
.
test
,
@required
this
.
test
,
this
.
handler
,
@required
this
.
handler
,
this
.
eventLabel
,
this
.
eventLabel
,
});
});
...
@@ -29,10 +29,10 @@ class GradleHandledError {
...
@@ -29,10 +29,10 @@ class GradleHandledError {
/// The handler function.
/// The handler function.
final
Future
<
GradleBuildStatus
>
Function
({
final
Future
<
GradleBuildStatus
>
Function
({
String
line
,
@required
String
line
,
FlutterProject
project
,
@required
FlutterProject
project
,
bool
usesAndroidX
,
@required
bool
usesAndroidX
,
bool
shouldBuildPluginAsAar
,
@required
bool
shouldBuildPluginAsAar
,
})
handler
;
})
handler
;
/// The [BuildEvent] label is named gradle-[eventLabel].
/// The [BuildEvent] label is named gradle-[eventLabel].
...
@@ -85,10 +85,10 @@ final GradleHandledError permissionDeniedErrorHandler = GradleHandledError(
...
@@ -85,10 +85,10 @@ final GradleHandledError permissionDeniedErrorHandler = GradleHandledError(
'Permission denied'
,
'Permission denied'
,
]),
]),
handler:
({
handler:
({
String
line
,
@required
String
line
,
FlutterProject
project
,
@required
FlutterProject
project
,
bool
usesAndroidX
,
@required
bool
usesAndroidX
,
bool
shouldBuildPluginAsAar
,
@required
bool
shouldBuildPluginAsAar
,
})
async
{
})
async
{
globals
.
printStatus
(
'
${globals.logger.terminal.warningMark}
Gradle does not have execution permission.'
,
emphasis:
true
);
globals
.
printStatus
(
'
${globals.logger.terminal.warningMark}
Gradle does not have execution permission.'
,
emphasis:
true
);
globals
.
printStatus
(
globals
.
printStatus
(
...
@@ -122,10 +122,10 @@ final GradleHandledError networkErrorHandler = GradleHandledError(
...
@@ -122,10 +122,10 @@ final GradleHandledError networkErrorHandler = GradleHandledError(
'Gateway Time-out'
'Gateway Time-out'
]),
]),
handler:
({
handler:
({
String
line
,
@required
String
line
,
FlutterProject
project
,
@required
FlutterProject
project
,
bool
usesAndroidX
,
@required
bool
usesAndroidX
,
bool
shouldBuildPluginAsAar
,
@required
bool
shouldBuildPluginAsAar
,
})
async
{
})
async
{
globals
.
printError
(
globals
.
printError
(
'
${globals.logger.terminal.warningMark}
Gradle threw an error while downloading artifacts from the network. '
'
${globals.logger.terminal.warningMark}
Gradle threw an error while downloading artifacts from the network. '
...
@@ -152,10 +152,10 @@ final GradleHandledError r8FailureHandler = GradleHandledError(
...
@@ -152,10 +152,10 @@ final GradleHandledError r8FailureHandler = GradleHandledError(
'com.android.tools.r8'
,
'com.android.tools.r8'
,
]),
]),
handler:
({
handler:
({
String
line
,
@required
String
line
,
FlutterProject
project
,
@required
FlutterProject
project
,
bool
usesAndroidX
,
@required
bool
usesAndroidX
,
bool
shouldBuildPluginAsAar
,
@required
bool
shouldBuildPluginAsAar
,
})
async
{
})
async
{
globals
.
printStatus
(
'
${globals.logger.terminal.warningMark}
The shrinker may have failed to optimize the Java bytecode.'
,
emphasis:
true
);
globals
.
printStatus
(
'
${globals.logger.terminal.warningMark}
The shrinker may have failed to optimize the Java bytecode.'
,
emphasis:
true
);
globals
.
printStatus
(
'To disable the shrinker, pass the `--no-shrink` flag to this command.'
,
indent:
4
);
globals
.
printStatus
(
'To disable the shrinker, pass the `--no-shrink` flag to this command.'
,
indent:
4
);
...
@@ -191,10 +191,10 @@ final GradleHandledError androidXFailureHandler = GradleHandledError(
...
@@ -191,10 +191,10 @@ final GradleHandledError androidXFailureHandler = GradleHandledError(
_androidXFailureRegex
.
hasMatch
(
line
);
_androidXFailureRegex
.
hasMatch
(
line
);
},
},
handler:
({
handler:
({
String
line
,
@required
String
line
,
FlutterProject
project
,
@required
FlutterProject
project
,
bool
usesAndroidX
,
@required
bool
usesAndroidX
,
bool
shouldBuildPluginAsAar
,
@required
bool
shouldBuildPluginAsAar
,
})
async
{
})
async
{
final
bool
hasPlugins
=
project
.
flutterPluginsFile
.
existsSync
();
final
bool
hasPlugins
=
project
.
flutterPluginsFile
.
existsSync
();
if
(!
hasPlugins
)
{
if
(!
hasPlugins
)
{
...
@@ -259,10 +259,10 @@ final GradleHandledError licenseNotAcceptedHandler = GradleHandledError(
...
@@ -259,10 +259,10 @@ final GradleHandledError licenseNotAcceptedHandler = GradleHandledError(
'You have not accepted the license agreements of the following SDK components'
,
'You have not accepted the license agreements of the following SDK components'
,
]),
]),
handler:
({
handler:
({
String
line
,
@required
String
line
,
FlutterProject
project
,
@required
FlutterProject
project
,
bool
usesAndroidX
,
@required
bool
usesAndroidX
,
bool
shouldBuildPluginAsAar
,
@required
bool
shouldBuildPluginAsAar
,
})
async
{
})
async
{
const
String
licenseNotAcceptedMatcher
=
const
String
licenseNotAcceptedMatcher
=
r'You have not accepted the license agreements of the following SDK components:\s*\[(.+)\]'
;
r'You have not accepted the license agreements of the following SDK components:\s*\[(.+)\]'
;
...
@@ -293,10 +293,10 @@ final GradleHandledError flavorUndefinedHandler = GradleHandledError(
...
@@ -293,10 +293,10 @@ final GradleHandledError flavorUndefinedHandler = GradleHandledError(
return
_undefinedTaskPattern
.
hasMatch
(
line
);
return
_undefinedTaskPattern
.
hasMatch
(
line
);
},
},
handler:
({
handler:
({
String
line
,
@required
String
line
,
FlutterProject
project
,
@required
FlutterProject
project
,
bool
usesAndroidX
,
@required
bool
usesAndroidX
,
bool
shouldBuildPluginAsAar
,
@required
bool
shouldBuildPluginAsAar
,
})
async
{
})
async
{
final
RunResult
tasksRunResult
=
await
globals
.
processUtils
.
run
(
final
RunResult
tasksRunResult
=
await
globals
.
processUtils
.
run
(
<
String
>[
<
String
>[
...
@@ -366,10 +366,10 @@ final GradleHandledError minSdkVersion = GradleHandledError(
...
@@ -366,10 +366,10 @@ final GradleHandledError minSdkVersion = GradleHandledError(
return
_minSdkVersionPattern
.
hasMatch
(
line
);
return
_minSdkVersionPattern
.
hasMatch
(
line
);
},
},
handler:
({
handler:
({
String
line
,
@required
String
line
,
FlutterProject
project
,
@required
FlutterProject
project
,
bool
usesAndroidX
,
@required
bool
usesAndroidX
,
bool
shouldBuildPluginAsAar
,
@required
bool
shouldBuildPluginAsAar
,
})
async
{
})
async
{
final
File
gradleFile
=
project
.
directory
final
File
gradleFile
=
project
.
directory
.
childDirectory
(
'android'
)
.
childDirectory
(
'android'
)
...
@@ -405,10 +405,10 @@ final GradleHandledError transformInputIssue = GradleHandledError(
...
@@ -405,10 +405,10 @@ final GradleHandledError transformInputIssue = GradleHandledError(
return
line
.
contains
(
'https://issuetracker.google.com/issues/158753935'
);
return
line
.
contains
(
'https://issuetracker.google.com/issues/158753935'
);
},
},
handler:
({
handler:
({
String
line
,
@required
String
line
,
FlutterProject
project
,
@required
FlutterProject
project
,
bool
usesAndroidX
,
@required
bool
usesAndroidX
,
bool
shouldBuildPluginAsAar
,
@required
bool
shouldBuildPluginAsAar
,
})
async
{
})
async
{
final
File
gradleFile
=
project
.
directory
final
File
gradleFile
=
project
.
directory
.
childDirectory
(
'android'
)
.
childDirectory
(
'android'
)
...
@@ -438,10 +438,10 @@ final GradleHandledError lockFileDepMissing = GradleHandledError(
...
@@ -438,10 +438,10 @@ final GradleHandledError lockFileDepMissing = GradleHandledError(
return
line
.
contains
(
'which is not part of the dependency lock state'
);
return
line
.
contains
(
'which is not part of the dependency lock state'
);
},
},
handler:
({
handler:
({
String
line
,
@required
String
line
,
FlutterProject
project
,
@required
FlutterProject
project
,
bool
usesAndroidX
,
@required
bool
usesAndroidX
,
bool
shouldBuildPluginAsAar
,
@required
bool
shouldBuildPluginAsAar
,
})
async
{
})
async
{
final
File
gradleFile
=
project
.
directory
final
File
gradleFile
=
project
.
directory
.
childDirectory
(
'android'
)
.
childDirectory
(
'android'
)
...
...
packages/flutter_tools/lib/src/android/gradle_utils.dart
View file @
6d03cb65
...
@@ -19,6 +19,7 @@ import '../cache.dart';
...
@@ -19,6 +19,7 @@ import '../cache.dart';
import
'../globals_null_migrated.dart'
as
globals
;
import
'../globals_null_migrated.dart'
as
globals
;
import
'../project.dart'
;
import
'../project.dart'
;
import
'../reporting/reporting.dart'
;
import
'../reporting/reporting.dart'
;
import
'android_sdk.dart'
;
const
String
_defaultGradleVersion
=
'6.7'
;
const
String
_defaultGradleVersion
=
'6.7'
;
...
@@ -133,8 +134,13 @@ bool _isWithinVersionRange(
...
@@ -133,8 +134,13 @@ bool _isWithinVersionRange(
assert
(
min
!=
null
);
assert
(
min
!=
null
);
assert
(
max
!=
null
);
assert
(
max
!=
null
);
final
Version
parsedTargetVersion
=
Version
.
parse
(
targetVersion
);
final
Version
parsedTargetVersion
=
Version
.
parse
(
targetVersion
);
return
parsedTargetVersion
>=
Version
.
parse
(
min
)
&&
final
Version
minVersion
=
Version
.
parse
(
min
);
parsedTargetVersion
<=
Version
.
parse
(
max
);
final
Version
maxVersion
=
Version
.
parse
(
max
);
return
minVersion
!=
null
&&
maxVersion
!=
null
&&
parsedTargetVersion
!=
null
&&
parsedTargetVersion
>=
minVersion
&&
parsedTargetVersion
<=
maxVersion
;
}
}
/// Returns the Gradle version that is required by the given Android Gradle plugin version
/// Returns the Gradle version that is required by the given Android Gradle plugin version
...
@@ -217,8 +223,9 @@ void updateLocalProperties({
...
@@ -217,8 +223,9 @@ void updateLocalProperties({
changed
=
true
;
changed
=
true
;
}
}
if
(
globals
.
androidSdk
!=
null
)
{
final
AndroidSdk
androidSdk
=
globals
.
androidSdk
;
changeIfNecessary
(
'sdk.dir'
,
globals
.
fsUtils
.
escapePath
(
globals
.
androidSdk
.
directory
.
path
));
if
(
androidSdk
!=
null
)
{
changeIfNecessary
(
'sdk.dir'
,
globals
.
fsUtils
.
escapePath
(
androidSdk
.
directory
.
path
));
}
}
changeIfNecessary
(
'flutter.sdk'
,
globals
.
fsUtils
.
escapePath
(
Cache
.
flutterRoot
));
changeIfNecessary
(
'flutter.sdk'
,
globals
.
fsUtils
.
escapePath
(
Cache
.
flutterRoot
));
...
@@ -248,8 +255,9 @@ void updateLocalProperties({
...
@@ -248,8 +255,9 @@ void updateLocalProperties({
/// Writes the path to the Android SDK, if known.
/// Writes the path to the Android SDK, if known.
void
writeLocalProperties
(
File
properties
)
{
void
writeLocalProperties
(
File
properties
)
{
final
SettingsFile
settings
=
SettingsFile
();
final
SettingsFile
settings
=
SettingsFile
();
if
(
globals
.
androidSdk
!=
null
)
{
final
AndroidSdk
androidSdk
=
globals
.
androidSdk
;
settings
.
values
[
'sdk.dir'
]
=
globals
.
fsUtils
.
escapePath
(
globals
.
androidSdk
.
directory
.
path
);
if
(
androidSdk
!=
null
)
{
settings
.
values
[
'sdk.dir'
]
=
globals
.
fsUtils
.
escapePath
(
androidSdk
.
directory
.
path
);
}
}
settings
.
writeContents
(
properties
);
settings
.
writeContents
(
properties
);
}
}
...
...
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