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
3d94b8fd
Unverified
Commit
3d94b8fd
authored
Oct 19, 2022
by
Alex Li
Committed by
GitHub
Oct 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[tool] Install the corresponding APK in `flutter run` (#113622)
parent
1b4b99b4
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
77 additions
and
55 deletions
+77
-55
run_release_test.dart
dev/devicelab/bin/tasks/run_release_test.dart
+2
-2
application_package.dart
...es/flutter_tools/lib/src/android/application_package.dart
+12
-3
gradle.dart
packages/flutter_tools/lib/src/android/gradle.dart
+25
-27
flutter_application_package.dart
...es/flutter_tools/lib/src/flutter_application_package.dart
+1
-0
android_device_start_test.dart
...test/general.shard/android/android_device_start_test.dart
+5
-5
android_install_test.dart
...ools/test/general.shard/android/android_install_test.dart
+14
-14
gradle_test.dart
...flutter_tools/test/general.shard/android/gradle_test.dart
+14
-0
application_package_test.dart
...er_tools/test/general.shard/application_package_test.dart
+3
-3
resident_runner_test.dart
...lutter_tools/test/general.shard/resident_runner_test.dart
+1
-1
No files found.
dev/devicelab/bin/tasks/run_release_test.dart
View file @
3d94b8fd
...
...
@@ -114,8 +114,8 @@ void main() {
_findNextMatcherInList
(
stdout
,
(
String
line
)
=>
line
.
startsWith
(
'Installing build/app/outputs/flutter-apk/app.apk...'
),
'Installing build/app/outputs/flutter-apk/app.apk...'
,
(
String
line
)
=>
line
.
startsWith
(
'Installing build/app/outputs/flutter-apk/app
-release
.apk...'
),
'Installing build/app/outputs/flutter-apk/app
-release
.apk...'
,
);
_findNextMatcherInList
(
...
...
packages/flutter_tools/lib/src/android/application_package.dart
View file @
3d94b8fd
...
...
@@ -103,11 +103,20 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
required
ProcessUtils
processUtils
,
required
Logger
logger
,
required
FileSystem
fileSystem
,
BuildInfo
?
buildInfo
,
})
async
{
File
apkFile
;
final
File
apkFile
;
final
String
filename
;
if
(
buildInfo
==
null
)
{
filename
=
'app.apk'
;
}
else
if
(
buildInfo
.
flavor
==
null
)
{
filename
=
'app-
${buildInfo.mode.name}
.apk'
;
}
else
{
filename
=
'app-
${buildInfo.lowerCasedFlavor}
-
${buildInfo.mode.name}
.apk'
;
}
if
(
androidProject
.
isUsingGradle
&&
androidProject
.
isSupportedVersion
)
{
apkFile
=
getApkDirectory
(
androidProject
.
parent
).
childFile
(
'app.apk'
);
apkFile
=
getApkDirectory
(
androidProject
.
parent
).
childFile
(
filename
);
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.
...
...
@@ -124,7 +133,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
// command will grab a new AndroidApk after building, to get the updated
// IDs.
}
else
{
apkFile
=
fileSystem
.
file
(
fileSystem
.
path
.
join
(
getAndroidBuildDirectory
(),
'app.apk'
));
apkFile
=
fileSystem
.
file
(
fileSystem
.
path
.
join
(
getAndroidBuildDirectory
(),
filename
));
}
final
File
manifest
=
androidProject
.
appManifestFile
;
...
...
packages/flutter_tools/lib/src/android/gradle.dart
View file @
3d94b8fd
...
...
@@ -465,41 +465,39 @@ class AndroidGradleBuilder implements AndroidBuilder {
);
return
;
}
// Gradle produced
an APK
.
// Gradle produced
APKs
.
final
Iterable
<
String
>
apkFilesPaths
=
project
.
isModule
?
findApkFilesModule
(
project
,
androidBuildInfo
,
_logger
,
_usage
)
:
listApkPaths
(
androidBuildInfo
);
final
Directory
apkDirectory
=
getApkDirectory
(
project
);
final
File
apkFile
=
apkDirectory
.
childFile
(
apkFilesPaths
.
first
);
if
(!
apkFile
.
existsSync
())
{
_exitWithExpectedFileNotFound
(
project:
project
,
fileExtension:
'.apk'
,
logger:
_logger
,
usage:
_usage
,
);
}
// Copy the first APK to app.apk, so `flutter run` can find it.
// TODO(egarciad): Handle multiple APKs.
apkFile
.
copySync
(
apkDirectory
.
childFile
(
'app.apk'
)
.
path
);
_logger
.
printTrace
(
'calculateSha:
$apkDirectory
/app.apk'
);
// Generate sha1 for every generated APKs.
for
(
final
File
apkFile
in
apkFilesPaths
.
map
(
apkDirectory
.
childFile
))
{
if
(!
apkFile
.
existsSync
())
{
_exitWithExpectedFileNotFound
(
project:
project
,
fileExtension:
'.apk'
,
logger:
_logger
,
usage:
_usage
,
);
}
final
File
apkShaFile
=
apkDirectory
.
childFile
(
'app.apk.sha1'
);
apkShaFile
.
writeAsStringSync
(
_calculateSha
(
apkFile
));
final
String
filename
=
apkFile
.
basename
;
_logger
.
printTrace
(
'Calculate SHA1:
$apkDirectory
/
$filename
'
);
final
File
apkShaFile
=
apkDirectory
.
childFile
(
'
$filename
.sha1'
);
apkShaFile
.
writeAsStringSync
(
_calculateSha
(
apkFile
));
final
String
appSize
=
(
buildInfo
.
mode
==
BuildMode
.
debug
)
?
''
// Don't display the size when building a debug variant.
:
' (
${getSizeAsMB(apkFile.lengthSync())}
)'
;
_logger
.
printStatus
(
'
${_logger.terminal.successMark}
Built
${_fileSystem.path.relative(apkFile.path)}$appSize
.'
,
color:
TerminalColor
.
green
,
);
final
String
appSize
=
(
buildInfo
.
mode
==
BuildMode
.
debug
)
?
''
// Don't display the size when building a debug variant.
:
' (
${getSizeAsMB(apkFile.lengthSync())}
)'
;
_logger
.
printStatus
(
'
${_logger.terminal.successMark}
Built
${_fileSystem.path.relative(apkFile.path)}$appSize
.'
,
color:
TerminalColor
.
green
,
);
if
(
buildInfo
.
codeSizeDirectory
!=
null
)
{
await
_performCodeSizeAnalysis
(
'apk'
,
apkFile
,
androidBuildInfo
);
if
(
buildInfo
.
codeSizeDirectory
!=
null
)
{
await
_performCodeSizeAnalysis
(
'apk'
,
apkFile
,
androidBuildInfo
);
}
}
}
...
...
packages/flutter_tools/lib/src/flutter_application_package.dart
View file @
3d94b8fd
...
...
@@ -66,6 +66,7 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory {
androidSdk:
_androidSdk
,
userMessages:
_userMessages
,
fileSystem:
_fileSystem
,
buildInfo:
buildInfo
,
);
}
return
AndroidApk
.
fromApk
(
...
...
packages/flutter_tools/test/general.shard/android/android_device_start_test.dart
View file @
3d94b8fd
...
...
@@ -65,7 +65,7 @@ void main() {
platform:
FakePlatform
(),
androidSdk:
androidSdk
,
);
final
File
apkFile
=
fileSystem
.
file
(
'app.apk'
)..
createSync
();
final
File
apkFile
=
fileSystem
.
file
(
'app
-debug
.apk'
)..
createSync
();
final
AndroidApk
apk
=
AndroidApk
(
id:
'FlutterApp'
,
applicationPackage:
apkFile
,
...
...
@@ -88,7 +88,7 @@ void main() {
command:
<
String
>[
'adb'
,
'-s'
,
'1234'
,
'shell'
,
'pm'
,
'list'
,
'packages'
,
'FlutterApp'
],
));
processManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'adb'
,
'-s'
,
'1234'
,
'install'
,
'-t'
,
'-r'
,
'app.apk'
],
command:
<
String
>[
'adb'
,
'-s'
,
'1234'
,
'install'
,
'-t'
,
'-r'
,
'app
-debug
.apk'
],
));
processManager
.
addCommand
(
kShaCommand
);
processManager
.
addCommand
(
const
FakeCommand
(
...
...
@@ -132,7 +132,7 @@ void main() {
platform:
FakePlatform
(),
androidSdk:
androidSdk
,
);
final
File
apkFile
=
fileSystem
.
file
(
'app.apk'
)..
createSync
();
final
File
apkFile
=
fileSystem
.
file
(
'app
-debug
.apk'
)..
createSync
();
final
AndroidApk
apk
=
AndroidApk
(
id:
'FlutterApp'
,
applicationPackage:
apkFile
,
...
...
@@ -170,7 +170,7 @@ void main() {
platform:
FakePlatform
(),
androidSdk:
androidSdk
,
);
final
File
apkFile
=
fileSystem
.
file
(
'app.apk'
)..
createSync
();
final
File
apkFile
=
fileSystem
.
file
(
'app
-debug
.apk'
)..
createSync
();
final
AndroidApk
apk
=
AndroidApk
(
id:
'FlutterApp'
,
applicationPackage:
apkFile
,
...
...
@@ -200,7 +200,7 @@ void main() {
'-r'
,
'--user'
,
'10'
,
'app.apk'
,
'app
-debug
.apk'
,
],
stdout:
'
\n\n
The Dart VM service is listening on http://127.0.0.1:456
\n\n
'
,
));
...
...
packages/flutter_tools/test/general.shard/android/android_install_test.dart
View file @
3d94b8fd
...
...
@@ -31,7 +31,7 @@ const FakeCommand kInstallCommand = FakeCommand(
'-r'
,
'--user'
,
'10'
,
'app.apk'
,
'app
-debug
.apk'
,
],
);
const
FakeCommand
kStoreShaCommand
=
FakeCommand
(
...
...
@@ -71,7 +71,7 @@ void main() {
stdout:
'[ro.build.version.sdk]: [11]'
,
),
]);
final
File
apk
=
fileSystem
.
file
(
'app.apk'
)..
createSync
();
final
File
apk
=
fileSystem
.
file
(
'app
-debug
.apk'
)..
createSync
();
final
AndroidApk
androidApk
=
AndroidApk
(
applicationPackage:
apk
,
id:
'app'
,
...
...
@@ -87,7 +87,7 @@ void main() {
});
testWithoutContext
(
'Cannot install app if APK file is missing'
,
()
async
{
final
File
apk
=
fileSystem
.
file
(
'app.apk'
);
final
File
apk
=
fileSystem
.
file
(
'app
-debug
.apk'
);
final
AndroidApk
androidApk
=
AndroidApk
(
applicationPackage:
apk
,
id:
'app'
,
...
...
@@ -115,7 +115,7 @@ void main() {
kInstallCommand
,
kStoreShaCommand
,
]);
final
File
apk
=
fileSystem
.
file
(
'app.apk'
)..
createSync
();
final
File
apk
=
fileSystem
.
file
(
'app
-debug
.apk'
)..
createSync
();
final
AndroidApk
androidApk
=
AndroidApk
(
applicationPackage:
apk
,
id:
'app'
,
...
...
@@ -144,7 +144,7 @@ void main() {
kInstallCommand
,
kStoreShaCommand
,
]);
final
File
apk
=
fileSystem
.
file
(
'app.apk'
)..
createSync
();
final
File
apk
=
fileSystem
.
file
(
'app
-debug
.apk'
)..
createSync
();
final
AndroidApk
androidApk
=
AndroidApk
(
applicationPackage:
apk
,
id:
'app'
,
...
...
@@ -182,13 +182,13 @@ void main() {
'-r'
,
'--user'
,
'jane'
,
'app.apk'
,
'app
-debug
.apk'
,
],
exitCode:
1
,
stderr:
'Exception occurred while executing: java.lang.IllegalArgumentException: Bad user number: jane'
,
),
]);
final
File
apk
=
fileSystem
.
file
(
'app.apk'
)..
createSync
();
final
File
apk
=
fileSystem
.
file
(
'app
-debug
.apk'
)..
createSync
();
final
AndroidApk
androidApk
=
AndroidApk
(
applicationPackage:
apk
,
id:
'app'
,
...
...
@@ -221,8 +221,8 @@ void main() {
stdout:
'example_sha'
,
),
]);
final
File
apk
=
fileSystem
.
file
(
'app.apk'
)..
createSync
();
fileSystem
.
file
(
'app.apk.sha1'
).
writeAsStringSync
(
'example_sha'
);
final
File
apk
=
fileSystem
.
file
(
'app
-debug
.apk'
)..
createSync
();
fileSystem
.
file
(
'app
-debug
.apk.sha1'
).
writeAsStringSync
(
'example_sha'
);
final
AndroidApk
androidApk
=
AndroidApk
(
applicationPackage:
apk
,
id:
'app'
,
...
...
@@ -254,7 +254,7 @@ void main() {
stdout:
'different_example_sha'
,
),
const
FakeCommand
(
command:
<
String
>[
'adb'
,
'-s'
,
'1234'
,
'install'
,
'-t'
,
'-r'
,
'--user'
,
'10'
,
'app.apk'
],
command:
<
String
>[
'adb'
,
'-s'
,
'1234'
,
'install'
,
'-t'
,
'-r'
,
'--user'
,
'10'
,
'app
-debug
.apk'
],
exitCode:
1
,
stderr:
'[INSTALL_FAILED_INSUFFICIENT_STORAGE]'
,
),
...
...
@@ -262,8 +262,8 @@ void main() {
kInstallCommand
,
const
FakeCommand
(
command:
<
String
>[
'adb'
,
'-s'
,
'1234'
,
'shell'
,
'echo'
,
'-n'
,
'example_sha'
,
'>'
,
'/data/local/tmp/sky.app.sha1'
]),
]);
final
File
apk
=
fileSystem
.
file
(
'app.apk'
)..
createSync
();
fileSystem
.
file
(
'app.apk.sha1'
).
writeAsStringSync
(
'example_sha'
);
final
File
apk
=
fileSystem
.
file
(
'app
-debug
.apk'
)..
createSync
();
fileSystem
.
file
(
'app
-debug
.apk.sha1'
).
writeAsStringSync
(
'example_sha'
);
final
AndroidApk
androidApk
=
AndroidApk
(
applicationPackage:
apk
,
id:
'app'
,
...
...
@@ -291,12 +291,12 @@ void main() {
stdout:
'
\n
'
),
const
FakeCommand
(
command:
<
String
>[
'adb'
,
'-s'
,
'1234'
,
'install'
,
'-t'
,
'-r'
,
'--user'
,
'10'
,
'app.apk'
],
command:
<
String
>[
'adb'
,
'-s'
,
'1234'
,
'install'
,
'-t'
,
'-r'
,
'--user'
,
'10'
,
'app
-debug
.apk'
],
exitCode:
1
,
stderr:
'[INSTALL_FAILED_INSUFFICIENT_STORAGE]'
,
),
]);
final
File
apk
=
fileSystem
.
file
(
'app.apk'
)..
createSync
();
final
File
apk
=
fileSystem
.
file
(
'app
-debug
.apk'
)..
createSync
();
final
AndroidApk
androidApk
=
AndroidApk
(
applicationPackage:
apk
,
id:
'app'
,
...
...
packages/flutter_tools/test/general.shard/android/gradle_test.dart
View file @
3d94b8fd
...
...
@@ -121,6 +121,20 @@ void main() {
});
group
(
'listApkPaths'
,
()
{
testWithoutContext
(
'Finds APK without flavor in debug'
,
()
{
final
Iterable
<
String
>
apks
=
listApkPaths
(
const
AndroidBuildInfo
(
BuildInfo
(
BuildMode
.
debug
,
''
,
treeShakeIcons:
false
)),
);
expect
(
apks
,
<
String
>[
'app-debug.apk'
]);
});
testWithoutContext
(
'Finds APK with flavor in debug'
,
()
{
final
Iterable
<
String
>
apks
=
listApkPaths
(
const
AndroidBuildInfo
(
BuildInfo
(
BuildMode
.
debug
,
'flavor1'
,
treeShakeIcons:
false
)),
);
expect
(
apks
,
<
String
>[
'app-flavor1-debug.apk'
]);
});
testWithoutContext
(
'Finds APK without flavor in release'
,
()
{
final
Iterable
<
String
>
apks
=
listApkPaths
(
const
AndroidBuildInfo
(
BuildInfo
(
BuildMode
.
release
,
''
,
treeShakeIcons:
false
)),
...
...
packages/flutter_tools/test/general.shard/application_package_test.dart
View file @
3d94b8fd
...
...
@@ -57,7 +57,7 @@ void main() {
testUsingContext
(
'Licenses not available, platform and buildtools available, apk exists'
,
()
async
{
const
String
aaptPath
=
'aaptPath'
;
final
File
apkFile
=
globals
.
fs
.
file
(
'app.apk'
);
final
File
apkFile
=
globals
.
fs
.
file
(
'app
-debug
.apk'
);
final
FakeAndroidSdkVersion
sdkVersion
=
FakeAndroidSdkVersion
();
sdkVersion
.
aaptPath
=
aaptPath
;
sdk
.
latestVersion
=
sdkVersion
;
...
...
@@ -81,7 +81,7 @@ void main() {
TargetPlatform
.
android_arm
,
applicationBinary:
apkFile
,
))!;
expect
(
applicationPackage
.
name
,
'app.apk'
);
expect
(
applicationPackage
.
name
,
'app
-debug
.apk'
);
expect
(
applicationPackage
,
isA
<
PrebuiltApplicationPackage
>());
expect
((
applicationPackage
as
PrebuiltApplicationPackage
).
applicationPackage
.
path
,
apkFile
.
path
);
expect
(
fakeProcessManager
,
hasNoRemainingExpectations
);
...
...
@@ -103,7 +103,7 @@ void main() {
await
ApplicationPackageFactory
.
instance
!.
getPackageForPlatform
(
TargetPlatform
.
android_arm
,
applicationBinary:
globals
.
fs
.
file
(
'app.apk'
),
applicationBinary:
globals
.
fs
.
file
(
'app
-debug
.apk'
),
);
expect
(
fakeProcessManager
,
hasNoRemainingExpectations
);
},
overrides:
overrides
);
...
...
packages/flutter_tools/test/general.shard/resident_runner_test.dart
View file @
3d94b8fd
...
...
@@ -312,7 +312,7 @@ void main() {
<
FlutterDevice
>[
flutterDevice
,
],
applicationBinary:
globals
.
fs
.
file
(
'app.apk'
),
applicationBinary:
globals
.
fs
.
file
(
'app
-debug
.apk'
),
stayResident:
false
,
debuggingOptions:
DebuggingOptions
.
enabled
(
BuildInfo
.
debug
),
target:
'main.dart'
,
...
...
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