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
75470a00
Unverified
Commit
75470a00
authored
Feb 19, 2021
by
Jonah Williams
Committed by
GitHub
Feb 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] unify gradle/android sdk reinitialize checks in cache.dart (#76342)
parent
c45e459e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
80 deletions
+41
-80
gradle.dart
packages/flutter_tools/lib/src/android/gradle.dart
+1
-67
application_package.dart
packages/flutter_tools/lib/src/application_package.dart
+2
-5
cache.dart
packages/flutter_tools/lib/src/cache.dart
+1
-0
project.dart
packages/flutter_tools/lib/src/project.dart
+25
-0
application_package_test.dart
...er_tools/test/general.shard/application_package_test.dart
+0
-6
cache_test.dart
packages/flutter_tools/test/general.shard/cache_test.dart
+12
-2
No files found.
packages/flutter_tools/lib/src/android/gradle.dart
View file @
75470a00
...
...
@@ -31,7 +31,6 @@ import 'gradle_errors.dart';
import
'gradle_utils.dart'
;
/// The directory where the APK artifact is generated.
@visibleForTesting
Directory
getApkDirectory
(
FlutterProject
project
)
{
return
project
.
isModule
?
project
.
android
.
buildDirectory
...
...
@@ -107,50 +106,6 @@ Iterable<String> _apkFilesFor(AndroidBuildInfo androidBuildInfo) {
return
<
String
>[
'app
$flavorString
-
$buildType
.apk'
];
}
/// Returns true if the current version of the Gradle plugin is supported.
bool
_isSupportedVersion
(
AndroidProject
project
)
{
final
FileSystem
fileSystem
=
project
.
hostAppGradleRoot
.
fileSystem
;
final
File
plugin
=
project
.
hostAppGradleRoot
.
childFile
(
fileSystem
.
path
.
join
(
'buildSrc'
,
'src'
,
'main'
,
'groovy'
,
'FlutterPlugin.groovy'
));
if
(
plugin
.
existsSync
())
{
return
false
;
}
final
File
appGradle
=
project
.
hostAppGradleRoot
.
childFile
(
fileSystem
.
path
.
join
(
'app'
,
'build.gradle'
));
if
(!
appGradle
.
existsSync
())
{
return
false
;
}
for
(
final
String
line
in
appGradle
.
readAsLinesSync
())
{
if
(
line
.
contains
(
RegExp
(
r'apply from: .*/flutter.gradle'
))
||
line
.
contains
(
"def flutterPluginVersion = 'managed'"
))
{
return
true
;
}
}
return
false
;
}
/// Runs `gradlew dependencies`, ensuring that dependencies are resolved and
/// potentially downloaded.
Future
<
void
>
checkGradleDependencies
(
Logger
logger
,
ProcessUtils
processUtils
)
async
{
final
Status
progress
=
logger
.
startProgress
(
'Ensuring gradle dependencies are up to date...'
,
);
final
FlutterProject
flutterProject
=
FlutterProject
.
current
();
await
processUtils
.
run
(<
String
>[
globals
.
gradleUtils
.
getExecutable
(
flutterProject
),
'dependencies'
,
],
throwOnError:
true
,
workingDirectory:
flutterProject
.
android
.
hostAppGradleRoot
.
path
,
environment:
<
String
,
String
>{
if
(
javaPath
!=
null
)
'JAVA_HOME'
:
javaPath
,
},
);
globals
.
androidSdk
?.
reinitialize
();
progress
.
stop
();
}
/// Tries to create `settings_aar.gradle` in an app project by removing the subprojects
/// from the existing `settings.gradle` file. This operation will fail if the existing
/// `settings.gradle` file has local edits.
...
...
@@ -330,10 +285,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
assert
(
localGradleErrors
!=
null
);
assert
(
globals
.
androidSdk
!=
null
);
if
(!
project
.
android
.
isUsingGradle
)
{
_exitWithProjectNotUsingGradleMessage
(
_usage
);
}
if
(!
_isSupportedVersion
(
project
.
android
))
{
if
(!
project
.
android
.
isSupportedVersion
)
{
_exitWithUnsupportedProjectMessage
(
_usage
);
}
final
Directory
buildDirectory
=
project
.
android
.
buildDirectory
;
...
...
@@ -915,24 +867,6 @@ void _exitWithUnsupportedProjectMessage(Usage usage) {
);
}
void
_exitWithProjectNotUsingGradleMessage
(
Usage
usage
)
{
BuildEvent
(
'unsupported-project'
,
eventError:
'app-not-using-gradle'
,
flutterUsage:
usage
).
send
();
throwToolExit
(
'
$warningMark
The build process for Android has changed, and the '
'current project configuration is no longer valid. Please consult
\n\n
'
'https://github.com/flutter/flutter/wiki/Upgrading-Flutter-projects-to-build-with-gradle
\n\n
'
'for details on how to upgrade the project.'
);
}
/// Returns the apk file created by [buildGradleProject]
Future
<
File
>
getGradleAppOut
(
AndroidProject
androidProject
,
Usage
usage
)
async
{
if
(!
_isSupportedVersion
(
androidProject
))
{
_exitWithUnsupportedProjectMessage
(
usage
);
}
return
getApkDirectory
(
androidProject
.
parent
).
childFile
(
'app.apk'
);
}
/// Returns [true] if the current app uses AndroidX.
// TODO(egarciad): https://github.com/flutter/flutter/issues/40800
// Remove `FlutterManifest.usesAndroidX` and provide a unified `AndroidProject.usesAndroidX`.
...
...
packages/flutter_tools/lib/src/application_package.dart
View file @
75470a00
...
...
@@ -64,9 +64,6 @@ class ApplicationPackageFactory {
case
TargetPlatform
.
android_arm64
:
case
TargetPlatform
.
android_x64
:
case
TargetPlatform
.
android_x86
:
if
(
_androidSdk
?.
licensesAvailable
==
true
&&
_androidSdk
?.
latestVersion
==
null
)
{
await
checkGradleDependencies
(
_logger
,
_processUtils
);
}
if
(
applicationBinary
==
null
)
{
return
await
AndroidApk
.
fromAndroidProject
(
FlutterProject
.
current
().
android
,
...
...
@@ -220,8 +217,8 @@ class AndroidApk extends ApplicationPackage {
})
async
{
File
apkFile
;
if
(
androidProject
.
isUsingGradle
)
{
apkFile
=
await
getGradleAppOut
(
androidProject
,
globals
.
flutterUsage
);
if
(
androidProject
.
isUsingGradle
&&
androidProject
.
isSupportedVersion
)
{
apkFile
=
getApkDirectory
(
androidProject
.
parent
).
childFile
(
'app.apk'
);
if
(
apkFile
.
existsSync
())
{
// Grab information from the .apk. The gradle build script might alter
// the application Id, so we need to look at what was actually built.
...
...
packages/flutter_tools/lib/src/cache.dart
View file @
75470a00
...
...
@@ -1201,6 +1201,7 @@ class AndroidMavenArtifacts extends ArtifactSet {
}
finally
{
status
.
stop
();
tempDir
.
deleteSync
(
recursive:
true
);
globals
.
androidSdk
?.
reinitialize
();
}
}
...
...
packages/flutter_tools/lib/src/project.dart
View file @
75470a00
...
...
@@ -822,6 +822,31 @@ class AndroidProject extends FlutterProjectPlatform {
/// True if the Flutter project is using the AndroidX support library.
bool
get
usesAndroidX
=>
parent
.
usesAndroidX
;
/// Returns true if the current version of the Gradle plugin is supported.
bool
get
isSupportedVersion
=>
_isSupportedVersion
??=
_computeSupportedVersion
();
bool
_isSupportedVersion
;
bool
_computeSupportedVersion
()
{
final
FileSystem
fileSystem
=
hostAppGradleRoot
.
fileSystem
;
final
File
plugin
=
hostAppGradleRoot
.
childFile
(
fileSystem
.
path
.
join
(
'buildSrc'
,
'src'
,
'main'
,
'groovy'
,
'FlutterPlugin.groovy'
));
if
(
plugin
.
existsSync
())
{
return
false
;
}
final
File
appGradle
=
hostAppGradleRoot
.
childFile
(
fileSystem
.
path
.
join
(
'app'
,
'build.gradle'
));
if
(!
appGradle
.
existsSync
())
{
return
false
;
}
for
(
final
String
line
in
appGradle
.
readAsLinesSync
())
{
if
(
line
.
contains
(
RegExp
(
r'apply from: .*/flutter.gradle'
))
||
line
.
contains
(
"def flutterPluginVersion = 'managed'"
))
{
return
true
;
}
}
return
false
;
}
/// True, if the app project is using Kotlin.
bool
get
isKotlin
{
final
File
gradleFile
=
hostAppGradleRoot
.
childDirectory
(
'app'
).
childFile
(
'build.gradle'
);
...
...
packages/flutter_tools/test/general.shard/application_package_test.dart
View file @
75470a00
...
...
@@ -96,10 +96,6 @@ void main() {
testUsingContext
(
'Licenses available, build tools not, apk exists'
,
()
async
{
when
(
sdk
.
latestVersion
).
thenReturn
(
null
);
final
FlutterProject
project
=
FlutterProject
.
fromDirectoryTest
(
fs
.
currentDirectory
);
final
File
gradle
=
project
.
android
.
hostAppGradleRoot
.
childFile
(
globals
.
platform
.
isWindows
?
'gradlew.bat'
:
'gradlew'
,
)..
createSync
(
recursive:
true
);
project
.
android
.
hostAppGradleRoot
.
childFile
(
'gradle.properties'
)
.
writeAsStringSync
(
'irrelevant'
);
...
...
@@ -111,8 +107,6 @@ void main() {
gradleWrapperDir
.
childFile
(
'gradlew'
).
writeAsStringSync
(
'irrelevant'
);
gradleWrapperDir
.
childFile
(
'gradlew.bat'
).
writeAsStringSync
(
'irrelevant'
);
fakeProcessManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
gradle
.
path
,
'dependencies'
]));
await
ApplicationPackageFactory
.
instance
.
getPackageForPlatform
(
TargetPlatform
.
android_arm
,
buildInfo:
null
,
...
...
packages/flutter_tools/test/general.shard/cache_test.dart
View file @
75470a00
...
...
@@ -767,6 +767,7 @@ void main() {
group
(
'AndroidMavenArtifacts'
,
()
{
MemoryFileSystem
memoryFileSystem
;
Cache
cache
;
FakeAndroidSdk
fakeAndroidSdk
;
setUp
(()
{
memoryFileSystem
=
MemoryFileSystem
.
test
();
...
...
@@ -774,6 +775,7 @@ void main() {
fileSystem:
memoryFileSystem
,
processManager:
FakeProcessManager
.
any
(),
);
fakeAndroidSdk
=
FakeAndroidSdk
();
});
testWithoutContext
(
'AndroidMavenArtifacts has a specified development artifact'
,
()
async
{
...
...
@@ -793,6 +795,7 @@ void main() {
await
mavenArtifacts
.
update
(
MockArtifactUpdater
(),
BufferLogger
.
test
(),
memoryFileSystem
,
MockOperatingSystemUtils
());
expect
(
await
mavenArtifacts
.
isUpToDate
(
memoryFileSystem
),
isFalse
);
expect
(
fakeAndroidSdk
.
reinitialized
,
true
);
},
overrides:
<
Type
,
Generator
>{
Cache:
()
=>
cache
,
FileSystem:
()
=>
memoryFileSystem
,
...
...
@@ -806,7 +809,7 @@ void main() {
'resolveDependencies'
,
])
]),
AndroidSdk:
()
=>
FakeAndroidSdk
()
AndroidSdk:
()
=>
fakeAndroidSdk
});
testUsingContext
(
'AndroidMavenArtifacts is a no-op if the Android SDK is absent'
,
()
async
{
...
...
@@ -903,4 +906,11 @@ class FakeCache extends Cache {
return
stampFile
;
}
}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{
bool
reinitialized
=
false
;
@override
void
reinitialize
()
{
reinitialized
=
true
;
}
}
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