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
35f8724b
Unverified
Commit
35f8724b
authored
Sep 16, 2022
by
Christopher Fujino
Committed by
GitHub
Sep 16, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] fix AndroidSdk.reinitialize bad state error (#111527)
parent
619cbc9e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
44 deletions
+70
-44
android_sdk.dart
packages/flutter_tools/lib/src/android/android_sdk.dart
+8
-4
android_sdk_test.dart
...er_tools/test/general.shard/android/android_sdk_test.dart
+62
-40
No files found.
packages/flutter_tools/lib/src/android/android_sdk.dart
View file @
35f8724b
...
...
@@ -354,12 +354,16 @@ class AndroidSdk {
platformVersion
=
int
.
parse
(
numberedVersion
.
group
(
1
)!);
}
else
{
final
String
buildProps
=
platformDir
.
childFile
(
'build.prop'
).
readAsStringSync
();
final
String
?
versionString
=
const
LineSplitter
()
final
Iterable
<
Match
>
versionMatches
=
const
LineSplitter
()
.
convert
(
buildProps
)
.
map
<
RegExpMatch
?>(
_sdkVersionRe
.
firstMatch
)
.
whereType
<
Match
>()
.
first
.
group
(
1
);
.
whereType
<
Match
>();
if
(
versionMatches
.
isEmpty
)
{
return
null
;
}
final
String
?
versionString
=
versionMatches
.
first
.
group
(
1
);
if
(
versionString
==
null
)
{
return
null
;
}
...
...
packages/flutter_tools/test/general.shard/android/android_sdk_test.dart
View file @
35f8724b
...
...
@@ -24,18 +24,29 @@ void main() {
});
group
(
'AndroidSdk'
,
()
{
Directory
?
sdkDir
;
testUsingContext
(
'constructing an AndroidSdk handles no matching lines in build.prop'
,
()
{
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
,
withAndroidN:
true
,
// Does not have valid version string
buildProp:
'
\n\n\n
'
,
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
tearDown
(()
{
if
(
sdkDir
!=
null
)
{
tryToDelete
(
sdkDir
!);
sdkDir
=
null
;
try
{
AndroidSdk
.
locateAndroidSdk
()!;
}
on
StateError
catch
(
err
)
{
fail
(
'sdk.reinitialize() threw a StateError:
\n
$err
'
)
;
}
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Config:
()
=>
config
,
});
testUsingContext
(
'parse sdk'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
expect
(
sdk
.
latestVersion
,
isNotNull
);
...
...
@@ -47,8 +58,11 @@ void main() {
});
testUsingContext
(
'parse sdk N'
,
()
{
sdkDir
=
createSdkDirectory
(
withAndroidN:
true
,
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
withAndroidN:
true
,
fileSystem:
fileSystem
,
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
expect
(
sdk
.
latestVersion
,
isNotNull
);
...
...
@@ -60,8 +74,8 @@ void main() {
});
testUsingContext
(
'returns sdkmanager path under cmdline tools on Linux/macOS'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
fileSystem
.
file
(
...
...
@@ -77,8 +91,11 @@ void main() {
});
testUsingContext
(
'returns sdkmanager path under cmdline tools (highest version) on Linux/macOS'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
,
withSdkManager:
false
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
,
withSdkManager:
false
,
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
final
List
<
String
>
versions
=
<
String
>[
'3.0'
,
'2.1'
,
'1.0'
];
...
...
@@ -97,8 +114,11 @@ void main() {
});
testUsingContext
(
'Does not return sdkmanager under deprecated tools component'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
,
withSdkManager:
false
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
,
withSdkManager:
false
,
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
fileSystem
.
file
(
...
...
@@ -114,8 +134,11 @@ void main() {
});
testUsingContext
(
'Can look up cmdline tool from deprecated tools path'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
,
withSdkManager:
false
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
,
withSdkManager:
false
,
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
fileSystem
.
file
(
...
...
@@ -131,8 +154,8 @@ void main() {
});
testUsingContext
(
'Caches adb location after first access'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
final
File
adbFile
=
fileSystem
.
file
(
...
...
@@ -152,8 +175,8 @@ void main() {
});
testUsingContext
(
'returns sdkmanager.bat path under cmdline tools for windows'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
fileSystem
.
file
(
...
...
@@ -170,8 +193,8 @@ void main() {
});
testUsingContext
(
'returns sdkmanager version'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
processManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
...
...
@@ -192,14 +215,12 @@ void main() {
});
testUsingContext
(
'returns validate sdk is well formed'
,
()
{
sdkDir
=
createBrokenSdkDirectory
(
fileSystem:
fileSystem
,
);
final
Directory
sdkDir
=
createBrokenSdkDirectory
(
fileSystem:
fileSystem
);
processManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'/.tmp_rand0/flutter_mock_android_sdk.rand0/cmdline-tools/latest/bin/sdkmanager'
,
'--version'
,
]));
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
final
List
<
String
>
validationIssues
=
sdk
.
validateSdkWellFormed
();
...
...
@@ -215,8 +236,8 @@ void main() {
});
testUsingContext
(
'does not throw on sdkmanager version check failure'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
processManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
...
...
@@ -240,8 +261,8 @@ void main() {
});
testUsingContext
(
'throws on sdkmanager version check if sdkmanager not found'
,
()
{
sdkDir
=
createSdkDirectory
(
withSdkManager:
false
,
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
withSdkManager:
false
,
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
processManager
.
excludedExecutables
.
add
(
'/.tmp_rand0/flutter_mock_android_sdk.rand0/cmdline-tools/latest/bin/sdkmanager'
);
final
AndroidSdk
?
sdk
=
AndroidSdk
.
locateAndroidSdk
();
...
...
@@ -254,8 +275,8 @@ void main() {
});
testUsingContext
(
'returns avdmanager path under cmdline tools'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
fileSystem
.
file
(
...
...
@@ -271,8 +292,8 @@ void main() {
});
testUsingContext
(
'returns avdmanager path under cmdline tools on windows'
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
fileSystem
.
file
(
...
...
@@ -288,8 +309,8 @@ void main() {
});
testUsingContext
(
"returns avdmanager path under tools if cmdline doesn't exist"
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
fileSystem
.
file
(
...
...
@@ -305,8 +326,8 @@ void main() {
});
testUsingContext
(
"returns avdmanager path under tools if cmdline doesn't exist on windows"
,
()
{
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
!
.
path
);
final
Directory
sdkDir
=
createSdkDirectory
(
fileSystem:
fileSystem
);
config
.
setValue
(
'android-sdk'
,
sdkDir
.
path
);
final
AndroidSdk
sdk
=
AndroidSdk
.
locateAndroidSdk
()!;
fileSystem
.
file
(
...
...
@@ -357,6 +378,7 @@ Directory createSdkDirectory({
bool
withPlatformTools
=
true
,
bool
withBuildTools
=
true
,
required
FileSystem
fileSystem
,
String
buildProp
=
_buildProp
,
})
{
final
Directory
dir
=
fileSystem
.
systemTempDirectory
.
createTempSync
(
'flutter_mock_android_sdk.'
);
final
String
exe
=
globals
.
platform
.
isWindows
?
'.exe'
:
''
;
...
...
@@ -386,7 +408,7 @@ Directory createSdkDirectory({
_createSdkFile
(
dir
,
'platforms/android-23/android.jar'
);
if
(
withAndroidN
)
{
_createSdkFile
(
dir
,
'platforms/android-N/android.jar'
);
_createSdkFile
(
dir
,
'platforms/android-N/build.prop'
,
contents:
_
buildProp
);
_createSdkFile
(
dir
,
'platforms/android-N/build.prop'
,
contents:
buildProp
);
}
if
(
withSdkManager
)
{
...
...
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