Skip to content

Commit

Permalink
Fix scenario tests on Android (flutter#33360)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia authored May 20, 2022
1 parent 5f0547c commit bdfedde
Show file tree
Hide file tree
Showing 20 changed files with 482 additions and 284 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ deps = {
'src/third_party/imgui':
Var('github_git') + '/ocornut/imgui.git' + '@' + '29d462ebce0275345a6ce4621d8fff0ded57c9e5',

'src/gradle': {
'src/third_party/gradle': {
'packages': [
{
'version': 'version:7.0.2',
Expand Down
2 changes: 1 addition & 1 deletion ci/licenses_golden/tool_signature
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Signature: 8066f905d0713ee8318704cfaa0b8ebe
Signature: 5c3efe46a56136a2ee290d3349383eda

2 changes: 1 addition & 1 deletion testing/rules/run_gradle.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

BAT = '.bat' if sys.platform.startswith(('cygwin', 'win')) else ''
GRADLE_BIN = os.path.normpath(os.path.join(SCRIPT_PATH, '..', '..', '..',
'gradle', 'bin', 'gradle%s' % BAT))
'third_party', 'gradle', 'bin', 'gradle%s' % BAT))

ANDROID_HOME = os.path.normpath(os.path.join(SCRIPT_PATH, '..', '..', '..',
'third_party', 'android_tools', 'sdk'))
Expand Down
2 changes: 1 addition & 1 deletion testing/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def JavaBin():
def RunJavaTests(filter, android_variant='android_debug_unopt'):
"""Runs the Java JUnit unit tests for the Android embedding"""
test_runner_dir = os.path.join(buildroot_dir, 'flutter', 'shell', 'platform', 'android', 'test_runner')
gradle_bin = os.path.join(buildroot_dir, 'gradle', 'bin', 'gradle.bat' if IsWindows() else 'gradle')
gradle_bin = os.path.join(buildroot_dir, 'third_party', 'gradle', 'bin', 'gradle.bat' if IsWindows() else 'gradle')
flutter_jar = os.path.join(out_dir, android_variant, 'flutter.jar')
android_home = os.path.join(buildroot_dir, 'third_party', 'android_tools', 'sdk')
build_dir = os.path.join(out_dir, android_variant, 'robolectric_tests', 'build')
Expand Down
19 changes: 14 additions & 5 deletions testing/scenario_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ compared against golden reside.

## Running for Android

The only test that is currently run is the Firebase TestLab test, which is a
smoke test to make sure an application can be built and run on a real Android
device.
### Integration tests

To run it, build the `android_profile_arm64` variant of the engine, and run
For emulators running on a x64 host, build `android_debug_unopt_x64` using
`./tools/gn --android --unoptimized --goma --android-cpu=x64`.

Then, launch the emulator, and run `./testing/scenario_app/run_android_tests.sh android_debug_unopt_x64`.

If you wish to build a different engine variant, make sure to pass that variant to the script `run_android_tests.sh`.

If you make a change to the source code, you would need to rebuild the same engine variant.

### Smoke test on FTL

To run the smoke test on Firebase TestLab test, build `android_profile_arm64`, and run
`./flutter/ci/firebase_testlab.py`. If you wish to test a different variant, e.g.
debug arm64, pass `--variant android_debug_arm64`.

Expand All @@ -72,5 +81,5 @@ To generate new lockfiles, run:

```bash
cd android
../../../../gradle/bin/gradle generateLockfiles
../../../../third_party/gradle/bin/gradle generateLockfiles
```
24 changes: 23 additions & 1 deletion testing/scenario_app/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _android_sources = [
"app/src/androidTest/java/dev/flutter/TestRunner.java",
"app/src/androidTest/java/dev/flutter/scenarios/EngineLaunchE2ETest.java",
"app/src/androidTest/java/dev/flutter/scenarios/ExampleInstrumentedTest.java",
"app/src/androidTest/java/dev/flutter/scenariosui/ExternalTextureTests.java",
"app/src/androidTest/java/dev/flutter/scenariosui/MemoryLeakTests.java",
"app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java",
"app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewUiTests.java",
Expand Down Expand Up @@ -47,8 +48,29 @@ gradle_task("build_apk") {
]
}

copy("android") {
gradle_task("build_test_apk") {
app_name = "scenario_app"
task = ":app:packageDebugAndroidTest"
gradle_project_dir = rebase_path(".")
sources = _android_sources
outputs = [ "$root_out_dir/scenario_app/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk" ]

deps = [
":android_lint",
"//flutter/testing/scenario_app:scenario_app_snapshot",
]
}

copy("firebase_apk") {
sources = get_target_outputs(":build_apk")
outputs = [ "$root_out_dir/firebase_apks/scenario_app.apk" ]
deps = [ ":build_apk" ]
}

group("android") {
deps = [
":build_apk",
":build_test_apk",
":firebase_apk",
]
}
14 changes: 3 additions & 11 deletions testing/scenario_app/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
apply plugin: 'com.android.application'
apply plugin: 'com.facebook.testing.screenshot'
apply plugin: 'kotlin-android'

screenshots {
failureDir = "${rootProject.buildDir}/reports/diff_failures"
recordDir = "${rootProject.projectDir}/reports/screenshots"
}

android {
lintOptions {
abortOnError true
checkAllWarnings true
showAll true
warningsAsErrors true
checkTestSources true
htmlReport false
xmlReport true
xmlOutput file("${rootProject.buildDir}/reports/lint-results.xml")
textOutput 'stdout'
// UnpackedNativeCode can break stack unwinding - see b/193408481
// NewerVersionAvailable and GradleDependency need to be taken care of
// by a roller rather than as part of CI.
Expand Down Expand Up @@ -62,13 +54,13 @@ dependencies {
if (project.hasProperty('flutter_jar')) {
implementation files(project.property('flutter_jar'))
}
implementation 'com.facebook.testing.screenshot:layout-hierarchy-common:0.12.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'com.google.guava:guava:30.1-android'

def leakcanary_version = '2.7'
androidTestImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
Expand All @@ -85,7 +77,7 @@ configureDependencies(new File(rootDir, '../../..')) { dependency ->

tasks.register('generateLockfiles') {
rootProject.subprojects.each { subproject ->
def gradle = "${rootProject.projectDir}/../../../../gradle/bin/gradle"
def gradle = "${rootProject.projectDir}/../../../../third_party/gradle/bin/gradle"
rootProject.exec {
workingDir rootProject.projectDir
executable gradle
Expand Down
Loading

0 comments on commit bdfedde

Please sign in to comment.