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
65599e28
Unverified
Commit
65599e28
authored
Feb 16, 2021
by
Jonah Williams
Committed by
GitHub
Feb 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] use less path manipulation in the Android SDK (#75930)
parent
2d9a01a8
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
68 additions
and
44 deletions
+68
-44
android_sdk.dart
packages/flutter_tools/lib/src/android/android_sdk.dart
+36
-28
android_workflow.dart
packages/flutter_tools/lib/src/android/android_workflow.dart
+1
-1
gradle_utils.dart
packages/flutter_tools/lib/src/android/gradle_utils.dart
+2
-2
config.dart
packages/flutter_tools/lib/src/commands/config.dart
+1
-1
config_test.dart
...utter_tools/test/commands.shard/hermetic/config_test.dart
+2
-1
build_aar_test.dart
...r_tools/test/commands.shard/permeable/build_aar_test.dart
+1
-1
build_apk_test.dart
...r_tools/test/commands.shard/permeable/build_apk_test.dart
+1
-1
build_appbundle_test.dart
...s/test/commands.shard/permeable/build_appbundle_test.dart
+1
-1
android_gradle_builder_test.dart
...st/general.shard/android/android_gradle_builder_test.dart
+1
-1
android_sdk_test.dart
...er_tools/test/general.shard/android/android_sdk_test.dart
+21
-6
gradle_test.dart
...flutter_tools/test/general.shard/android/gradle_test.dart
+1
-1
No files found.
packages/flutter_tools/lib/src/android/android_sdk.dart
View file @
65599e28
...
...
@@ -45,8 +45,8 @@ class AndroidSdk {
static
const
String
_javaHomeEnvironmentVariable
=
'JAVA_HOME'
;
static
const
String
_javaExecutable
=
'java'
;
/// The
path to the Android SDK
.
final
String
directory
;
/// The
Android SDK root directory
.
final
Directory
directory
;
List
<
AndroidSdkVersion
>
_sdkVersions
;
AndroidSdkVersion
_latestVersion
;
...
...
@@ -57,9 +57,8 @@ class AndroidSdk {
/// the expectation that it will be downloaded later, e.g. by gradle or the
/// sdkmanager. The [licensesAvailable] property should be used to determine
/// whether the licenses are at least possibly accepted.
bool
get
platformToolsAvailable
=>
globals
.
fs
.
directory
(
globals
.
fs
.
path
.
join
(
directory
,
'cmdline-tools'
)).
existsSync
()
||
globals
.
fs
.
directory
(
globals
.
fs
.
path
.
join
(
directory
,
'platform-tools'
)).
existsSync
();
bool
get
platformToolsAvailable
=>
directory
.
childDirectory
(
'cmdline-tools'
).
existsSync
()
||
directory
.
childDirectory
(
'platform-tools'
).
existsSync
();
/// Whether the `licenses` directory exists in the Android SDK.
///
...
...
@@ -68,7 +67,7 @@ class AndroidSdk {
/// from another workstation such as in CI scenarios. If these files are valid
/// gradle or the sdkmanager will be able to download and use other parts of
/// the SDK on demand.
bool
get
licensesAvailable
=>
globals
.
fs
.
directory
(
globals
.
fs
.
path
.
join
(
directory
,
'licenses'
)
).
existsSync
();
bool
get
licensesAvailable
=>
directory
.
childDirectory
(
'licenses'
).
existsSync
();
static
AndroidSdk
locateAndroidSdk
()
{
String
findAndroidHomeDir
()
{
...
...
@@ -149,7 +148,7 @@ class AndroidSdk {
return
null
;
}
return
AndroidSdk
(
androidHomeDir
);
return
AndroidSdk
(
globals
.
fs
.
directory
(
androidHomeDir
)
);
}
static
bool
validSdkDirectory
(
String
dir
)
{
...
...
@@ -200,7 +199,7 @@ class AndroidSdk {
);
}
Directory
get
_platformsDir
=>
globals
.
fs
.
directory
(
globals
.
fs
.
path
.
join
(
directory
,
'platforms'
)
);
Directory
get
_platformsDir
=>
directory
.
childDirectory
(
'platforms'
);
Iterable
<
Directory
>
get
_platforms
{
Iterable
<
Directory
>
platforms
=
<
Directory
>[];
...
...
@@ -236,9 +235,13 @@ class AndroidSdk {
}
String
getPlatformToolsPath
(
String
binaryName
)
{
final
String
path
=
globals
.
fs
.
path
.
join
(
directory
,
'platform-tools'
,
binaryName
);
if
(
globals
.
fs
.
file
(
path
).
existsSync
())
{
return
path
;
final
File
cmdlineToolsBinary
=
directory
.
childDirectory
(
'cmdline-tools'
).
childFile
(
binaryName
);
if
(
cmdlineToolsBinary
.
existsSync
())
{
return
cmdlineToolsBinary
.
path
;
}
final
File
platformToolBinary
=
directory
.
childDirectory
(
'platform-tools'
).
childFile
(
binaryName
);
if
(
platformToolBinary
.
existsSync
())
{
return
platformToolBinary
.
path
;
}
return
null
;
}
...
...
@@ -249,9 +252,9 @@ class AndroidSdk {
// try both.
final
List
<
String
>
searchFolders
=
<
String
>[
'emulator'
,
'tools'
];
for
(
final
String
folder
in
searchFolders
)
{
final
String
path
=
globals
.
fs
.
path
.
join
(
directory
,
folder
,
binaryName
);
if
(
globals
.
fs
.
file
(
path
)
.
existsSync
())
{
return
path
;
final
File
file
=
directory
.
childDirectory
(
folder
).
childFile
(
binaryName
);
if
(
file
.
existsSync
())
{
return
file
.
path
;
}
}
return
null
;
...
...
@@ -259,9 +262,9 @@ class AndroidSdk {
String
getAvdManagerPath
()
{
final
String
binaryName
=
globals
.
platform
.
isWindows
?
'avdmanager.bat'
:
'avdmanager'
;
final
String
path
=
globals
.
fs
.
path
.
join
(
directory
,
'tools'
,
'bin'
,
binaryName
);
if
(
globals
.
fs
.
file
(
path
)
.
existsSync
())
{
return
path
;
final
File
file
=
directory
.
childDirectory
(
'tools'
).
childDirectory
(
'bin'
).
childFile
(
binaryName
);
if
(
file
.
existsSync
())
{
return
file
.
path
;
}
return
null
;
}
...
...
@@ -273,7 +276,7 @@ class AndroidSdk {
void
reinitialize
()
{
List
<
Version
>
buildTools
=
<
Version
>[];
// 19.1.0, 22.0.1, ...
final
Directory
buildToolsDir
=
globals
.
fs
.
directory
(
globals
.
fs
.
path
.
join
(
directory
,
'build-tools'
)
);
final
Directory
buildToolsDir
=
directory
.
childDirectory
(
'build-tools'
);
if
(
buildToolsDir
.
existsSync
())
{
buildTools
=
buildToolsDir
.
listSync
()
...
...
@@ -339,17 +342,22 @@ class AndroidSdk {
/// The sdkmanager was previously in the tools directory but this component
/// was marked as obsolete in 3.6.
String
get
sdkManagerPath
{
final
File
cmdlineTool
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
directory
,
'cmdline-tools'
,
'latest'
,
'bin'
,
globals
.
platform
.
isWindows
?
'sdkmanager.bat'
:
'sdkmanager'
),
);
final
String
executable
=
globals
.
platform
.
isWindows
?
'sdkmanager.bat'
:
'sdkmanager'
;
final
File
cmdlineTool
=
directory
.
childDirectory
(
'cmdline-tools'
)
.
childDirectory
(
'latest'
)
.
childDirectory
(
'bin'
)
.
childFile
(
executable
);
if
(
cmdlineTool
.
existsSync
())
{
return
cmdlineTool
.
path
;
}
return
globals
.
fs
.
path
.
join
(
directory
,
'tools'
,
'bin'
,
'sdkmanager'
);
return
directory
.
childDirectory
(
'tools'
)
.
childDirectory
(
'bin'
)
.
childFile
(
executable
)
.
path
;
}
/// First try Java bundled with Android Studio, then sniff JAVA_HOME, then fallback to PATH.
...
...
@@ -477,11 +485,11 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
}
String
getPlatformsPath
(
String
itemName
)
{
return
_fileSystem
.
path
.
join
(
sdk
.
directory
,
'platforms'
,
platformName
,
itemName
)
;
return
sdk
.
directory
.
childDirectory
(
'platforms'
).
childDirectory
(
platformName
).
childFile
(
itemName
).
path
;
}
String
getBuildToolsPath
(
String
binaryName
)
{
return
_fileSystem
.
path
.
join
(
sdk
.
directory
,
'build-tools'
,
buildToolsVersionName
,
binaryName
)
;
return
sdk
.
directory
.
childDirectory
(
'build-tools'
).
childDirectory
(
buildToolsVersionName
).
childFile
(
binaryName
).
path
;
}
@override
...
...
packages/flutter_tools/lib/src/android/android_workflow.dart
View file @
65599e28
...
...
@@ -189,7 +189,7 @@ class AndroidValidator extends DoctorValidator {
return
ValidationResult
(
ValidationType
.
partial
,
messages
);
}
messages
.
add
(
ValidationMessage
(
_userMessages
.
androidSdkLocation
(
_androidSdk
.
directory
)));
messages
.
add
(
ValidationMessage
(
_userMessages
.
androidSdkLocation
(
_androidSdk
.
directory
?.
path
)));
String
sdkVersionText
;
if
(
_androidSdk
.
latestVersion
!=
null
)
{
...
...
packages/flutter_tools/lib/src/android/gradle_utils.dart
View file @
65599e28
...
...
@@ -240,7 +240,7 @@ void updateLocalProperties({
}
if
(
globals
.
androidSdk
!=
null
)
{
changeIfNecessary
(
'sdk.dir'
,
globals
.
fsUtils
.
escapePath
(
globals
.
androidSdk
.
directory
));
changeIfNecessary
(
'sdk.dir'
,
globals
.
fsUtils
.
escapePath
(
globals
.
androidSdk
.
directory
.
path
));
}
changeIfNecessary
(
'flutter.sdk'
,
globals
.
fsUtils
.
escapePath
(
Cache
.
flutterRoot
));
...
...
@@ -271,7 +271,7 @@ void updateLocalProperties({
void
writeLocalProperties
(
File
properties
)
{
final
SettingsFile
settings
=
SettingsFile
();
if
(
globals
.
androidSdk
!=
null
)
{
settings
.
values
[
'sdk.dir'
]
=
globals
.
fsUtils
.
escapePath
(
globals
.
androidSdk
.
directory
);
settings
.
values
[
'sdk.dir'
]
=
globals
.
fsUtils
.
escapePath
(
globals
.
androidSdk
.
directory
.
path
);
}
settings
.
writeContents
(
properties
);
}
...
...
packages/flutter_tools/lib/src/commands/config.dart
View file @
65599e28
...
...
@@ -180,7 +180,7 @@ class ConfigCommand extends FlutterCommand {
results
[
'android-studio-dir'
]
=
androidStudio
.
directory
;
}
if
(
results
[
'android-sdk'
]
==
null
&&
globals
.
androidSdk
!=
null
)
{
results
[
'android-sdk'
]
=
globals
.
androidSdk
.
directory
;
results
[
'android-sdk'
]
=
globals
.
androidSdk
.
directory
.
path
;
}
globals
.
printStatus
(
const
JsonEncoder
.
withIndent
(
' '
).
convert
(
results
));
...
...
packages/flutter_tools/test/commands.shard/hermetic/config_test.dart
View file @
65599e28
...
...
@@ -10,6 +10,7 @@ import 'package:args/command_runner.dart';
import
'package:flutter_tools/src/android/android_sdk.dart'
;
import
'package:flutter_tools/src/android/android_studio.dart'
;
import
'package:flutter_tools/src/base/context.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/config.dart'
;
...
...
@@ -271,7 +272,7 @@ class MockAndroidStudio extends Mock implements AndroidStudio, Comparable<Androi
class
MockAndroidSdk
extends
Mock
implements
AndroidSdk
{
@override
String
get
directory
=>
'path/to/android/sdk'
;
Directory
get
directory
=>
globals
.
fs
.
directory
(
'path/to/android/sdk'
)
;
}
class
MockFlutterVersion
extends
Mock
implements
FlutterVersion
{}
packages/flutter_tools/test/commands.shard/permeable/build_aar_test.dart
View file @
65599e28
...
...
@@ -227,7 +227,7 @@ void main() {
when
(
mockProcessManager
.
canRun
(
any
)).
thenReturn
(
false
);
mockAndroidSdk
=
MockAndroidSdk
();
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
'irrelevant'
);
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
globals
.
fs
.
directory
(
'irrelevant'
)
);
});
tearDown
(()
{
...
...
packages/flutter_tools/test/commands.shard/permeable/build_apk_test.dart
View file @
65599e28
...
...
@@ -174,7 +174,7 @@ void main() {
});
mockAndroidSdk
=
MockAndroidSdk
();
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
'irrelevant'
);
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
globals
.
fs
.
directory
(
'irrelevant'
)
);
});
tearDown
(()
{
...
...
packages/flutter_tools/test/commands.shard/permeable/build_appbundle_test.dart
View file @
65599e28
...
...
@@ -154,7 +154,7 @@ void main() {
when
(
mockAndroidSdk
.
licensesAvailable
).
thenReturn
(
true
);
when
(
mockAndroidSdk
.
platformToolsAvailable
).
thenReturn
(
true
);
when
(
mockAndroidSdk
.
validateSdkWellFormed
()).
thenReturn
(
const
<
String
>[]);
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
'irrelevant'
);
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
globals
.
fs
.
directory
(
'irrelevant'
)
);
});
tearDown
(()
{
...
...
packages/flutter_tools/test/general.shard/android/android_gradle_builder_test.dart
View file @
65599e28
...
...
@@ -56,7 +56,7 @@ void main() {
logger:
logger
,
);
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
'irrelevant'
);
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
fileSystem
.
directory
(
'irrelevant'
)
);
final
Directory
rootDirectory
=
fileSystem
.
currentDirectory
;
cache
=
Cache
.
test
(
...
...
packages/flutter_tools/test/general.shard/android/android_sdk_test.dart
View file @
65599e28
...
...
@@ -73,10 +73,10 @@ void main() {
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
();
fileSystem
.
file
(
fileSystem
.
path
.
join
(
sdk
.
directory
,
'cmdline-tools'
,
'latest'
,
'bin'
,
'sdkmanager'
)
fileSystem
.
path
.
join
(
sdk
.
directory
.
path
,
'cmdline-tools'
,
'latest'
,
'bin'
,
'sdkmanager'
)
).
createSync
(
recursive:
true
);
expect
(
sdk
.
sdkManagerPath
,
fileSystem
.
path
.
join
(
sdk
.
directory
,
'cmdline-tools'
,
'latest'
,
'bin'
,
'sdkmanager'
));
expect
(
sdk
.
sdkManagerPath
,
fileSystem
.
path
.
join
(
sdk
.
directory
.
path
,
'cmdline-tools'
,
'latest'
,
'bin'
,
'sdkmanager'
));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
...
...
@@ -90,11 +90,11 @@ void main() {
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
();
fileSystem
.
file
(
fileSystem
.
path
.
join
(
sdk
.
directory
,
'cmdline-tools'
,
'latest'
,
'bin'
,
'sdkmanager.bat'
)
fileSystem
.
path
.
join
(
sdk
.
directory
.
path
,
'cmdline-tools'
,
'latest'
,
'bin'
,
'sdkmanager.bat'
)
).
createSync
(
recursive:
true
);
expect
(
sdk
.
sdkManagerPath
,
fileSystem
.
path
.
join
(
sdk
.
directory
,
'cmdline-tools'
,
'latest'
,
'bin'
,
'sdkmanager.bat'
));
fileSystem
.
path
.
join
(
sdk
.
directory
.
path
,
'cmdline-tools'
,
'latest'
,
'bin'
,
'sdkmanager.bat'
));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
...
...
@@ -102,17 +102,32 @@ void main() {
Config:
()
=>
config
,
});
testUsingContext
(
'returns sdkmanager path under tools if cmdline doesnt exist'
,
()
{
testUsingContext
(
"returns sdkmanager path under tools if cmdline doesn't exist"
,
()
{
sdkDir
=
MockAndroidSdk
.
createSdkDirectory
();
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
();
expect
(
sdk
.
sdkManagerPath
,
fileSystem
.
path
.
join
(
sdk
.
directory
,
'tools'
,
'bin'
,
'sdkmanager'
));
expect
(
sdk
.
sdkManagerPath
,
fileSystem
.
path
.
join
(
sdk
.
directory
.
path
,
'tools'
,
'bin'
,
'sdkmanager'
));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Config:
()
=>
config
,
Platform:
()
=>
FakePlatform
(
operatingSystem:
'linux'
),
});
testUsingContext
(
"returns sdkmanager path under tools if cmdline doesn't exist on windows"
,
()
{
sdkDir
=
MockAndroidSdk
.
createSdkDirectory
();
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
();
expect
(
sdk
.
sdkManagerPath
,
fileSystem
.
path
.
join
(
sdk
.
directory
.
path
,
'tools'
,
'bin'
,
'sdkmanager.bat'
));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Config:
()
=>
config
,
Platform:
()
=>
FakePlatform
(
operatingSystem:
'windows'
),
});
testUsingContext
(
'returns sdkmanager version'
,
()
{
...
...
packages/flutter_tools/test/general.shard/android/gradle_test.dart
View file @
65599e28
...
...
@@ -841,7 +841,7 @@ flutter:
fs
=
MemoryFileSystem
.
test
();
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]);
mockAndroidSdk
=
MockAndroidSdk
();
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
'irrelevant'
);
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
fs
.
directory
(
'irrelevant'
)
);
builder
=
AndroidGradleBuilder
(
logger:
logger
);
});
...
...
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