Test the Android embedding v2 (#42708)

* Test the Android embedding v2

* Update integration tests

* Split into shards
This commit is contained in:
Emmanuel Garcia
2019-10-16 21:26:10 -07:00
committed by GitHub
parent 3917e585c9
commit 08c645b3b2
55 changed files with 431 additions and 108 deletions

View File

@@ -8,7 +8,7 @@
tests=(
"dev/integration_tests/release_smoke_test"
"dev/integration_tests/abstract_method_smoke_test"
"dev/integration_tests/android_embedding_2"
"dev/integration_tests/android_embedding_v2_smoke_test"
)
# The devices where the tests are run.

View File

@@ -925,8 +925,6 @@ Future<void> _runIntegrationTests() async {
// TODO(jmagman): Re-enable once flakiness is resolved.
// await _runDevicelabTest('module_test_ios');
}
// This does less work if the subshard isn't Android.
await _androidPluginTest();
}
}
@@ -949,44 +947,30 @@ String get androidSdkRoot {
return androidSdkRoot;
}
Future<void> _androidPluginTest() async {
if (androidSdkRoot == null) {
print('No Android SDK detected, skipping Android Plugin test.');
return;
}
final Map<String, String> env = <String, String> {
'ANDROID_HOME': androidSdkRoot,
'ANDROID_SDK_ROOT': androidSdkRoot,
};
await _runDevicelabTest('plugin_test', env: env);
}
Future<void> _androidGradleTests(String subShard) async {
// TODO(dnfield): gradlew is crashing on the cirrus image and it's not clear why.
if (androidSdkRoot == null || Platform.isWindows) {
print('No Android SDK detected or on Windows, skipping Android gradle test.');
return;
}
final Map<String, String> env = <String, String> {
final Map<String, String> defaultEnv = <String, String>{
'ANDROID_HOME': androidSdkRoot,
'ANDROID_SDK_ROOT': androidSdkRoot,
'ENABLE_ANDROID_EMBEDDING_V2': Platform.environment['ENABLE_ANDROID_EMBEDDING_V2'] ?? '',
};
if (subShard == 'gradle1') {
await _runDevicelabTest('gradle_plugin_light_apk_test', env: env);
await _runDevicelabTest('gradle_plugin_fat_apk_test', env: env);
await _runDevicelabTest('gradle_r8_test', env: env);
await _runDevicelabTest('gradle_non_android_plugin_test', env: env);
await _runDevicelabTest('gradle_jetifier_test', env: env);
await _runDevicelabTest('gradle_plugin_light_apk_test', env: defaultEnv);
await _runDevicelabTest('gradle_plugin_fat_apk_test', env: defaultEnv);
await _runDevicelabTest('gradle_r8_test', env: defaultEnv);
await _runDevicelabTest('gradle_non_android_plugin_test', env: defaultEnv);
await _runDevicelabTest('gradle_jetifier_test', env: defaultEnv);
}
if (subShard == 'gradle2') {
await _runDevicelabTest('gradle_plugin_bundle_test', env: env);
await _runDevicelabTest('module_test', env: env);
await _runDevicelabTest('module_host_with_custom_build_test', env: env);
await _runDevicelabTest('build_aar_module_test', env: env);
await _runDevicelabTest('gradle_plugin_bundle_test', env: defaultEnv);
await _runDevicelabTest('module_test', env: defaultEnv);
await _runDevicelabTest('module_host_with_custom_build_test', env: defaultEnv);
await _runDevicelabTest('build_aar_module_test', env: defaultEnv);
await _runDevicelabTest('plugin_test', env: defaultEnv);
}
}

View File

@@ -13,6 +13,8 @@ import 'package:path/path.dart' as path;
final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
final String gradlewExecutable = Platform.isWindows ? gradlew : './$gradlew';
final bool useAndroidEmbeddingV2 = Platform.environment['ENABLE_ANDROID_EMBEDDING_V2'] == 'true';
/// Tests that the Android app containing a Flutter module can be built when
/// it has custom build types and flavors.
Future<void> main() async {
@@ -53,7 +55,14 @@ Future<void> main() async {
final Directory hostAppDir = Directory(path.join(tempDir.path, 'hello_host_app_with_custom_build'));
mkdir(hostAppDir);
recursiveCopy(
Directory(path.join(flutterDirectory.path, 'dev', 'integration_tests', 'module_host_with_custom_build')),
Directory(
path.join(
flutterDirectory.path,
'dev',
'integration_tests',
useAndroidEmbeddingV2 ? 'module_host_with_custom_build_v2_embedding' : 'module_host_with_custom_build',
),
),
hostAppDir,
);
copy(

View File

@@ -13,9 +13,12 @@ import 'package:path/path.dart' as path;
final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
final String gradlewExecutable = Platform.isWindows ? gradlew : './$gradlew';
final bool useAndroidEmbeddingV2 = Platform.environment['ENABLE_ANDROID_EMBEDDING_V2'] == 'true';
/// Tests that the Flutter module project template works and supports
/// adding Flutter to an existing Android app.
Future<void> main() async {
print(useAndroidEmbeddingV2);
await task(() async {
section('Find Java');
@@ -143,7 +146,14 @@ Future<void> main() async {
final Directory hostApp = Directory(path.join(tempDir.path, 'hello_host_app'));
mkdir(hostApp);
recursiveCopy(
Directory(path.join(flutterDirectory.path, 'dev', 'integration_tests', 'android_host_app')),
Directory(
path.join(
flutterDirectory.path,
'dev',
'integration_tests',
useAndroidEmbeddingV2 ? 'android_host_app_v2_embedding' : 'android_host_app',
),
),
hostApp,
);
copy(

View File

@@ -38,7 +38,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.android_embedding_2"
applicationId "com.example.android_embedding_v2_smoke_test"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()

View File

@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android_embedding_2">
package="com.example.android_embedding_v2_smoke_test">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->

View File

@@ -1,4 +1,4 @@
package com.example.android_embedding_2
package com.example.android_embedding_v2_smoke_test
import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant

View File

@@ -0,0 +1,67 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.android_embedding_v2_smoke_test"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

View File

@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android_embedding_2">
package="com.example.android_embedding_v2_smoke_test">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->

View File

@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android_embedding_2">
package="com.example.android_embedding_v2_smoke_test">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
@@ -7,7 +7,7 @@
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="android_embedding_2">
android:label="android_embedding_v2_smoke_test">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"

View File

@@ -0,0 +1,12 @@
package com.example.android_embedding_v2_smoke_test
import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}

View File

@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android_embedding_v2_smoke_test">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@@ -1,4 +1,4 @@
name: android_embedding_2
name: android_embedding_v2_smoke_test
description: A new Flutter project.
# The following defines the version and build number for your application.

View File

@@ -0,0 +1,8 @@
# Android host app
Android host app for a Flutter module created using
```
$ flutter create -t module hello
```
and placed in a sibling folder to (a clone of) the host app.
Used by the `module_test.dart` device lab test.

View File

@@ -0,0 +1,23 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
defaultConfig {
applicationId "io.flutter.add2app"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
dependencies {
implementation project(':flutter')
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="io.flutter.add2app">
<application android:allowBackup="false"
tools:ignore="GoogleAppIndexingWarning,MissingApplicationIcon">
<activity android:name=".MainActivity" />
</application>
</manifest>

View File

@@ -0,0 +1,13 @@
package io.flutter.add2app;
import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}

View File

@@ -0,0 +1,20 @@
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

View File

@@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true

View File

@@ -0,0 +1,6 @@
#Mon Jun 25 14:13:36 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

View File

@@ -0,0 +1,3 @@
include ':app'
setBinding(new Binding([gradle: this]))
evaluate(new File(settingsDir.parentFile, 'hello/.android/include_flutter.groovy'))

View File

@@ -0,0 +1,13 @@
package io.flutter.add2app;
import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}

View File

@@ -0,0 +1,8 @@
# Android host app
Android host app for a Flutter module created using
```
$ flutter create -t module hello
```
and placed in a sibling folder to (a clone of) the host app.
Used by the `module_host_with_custom_build_test.dart` device lab test.

View File

@@ -0,0 +1,42 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
defaultConfig {
applicationId "io.flutter.addtoapp"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
// Test build types.
buildTypes {
staging {
initWith debug
// This is required because the `:flutter` project doesn't define this custom build type.
// Without the fallback, the Android plugin will make Gradle exit with the following error:
// `Unable to find a matching variant of project :flutter`
matchingFallbacks = ['debug']
}
prod {
initWith release
matchingFallbacks = ['release']
}
}
// Test flavors.
flavorDimensions "version"
productFlavors {
demo {
dimension "version"
}
}
}
dependencies {
implementation project(':flutter')
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="io.flutter.addtoapp">
<application android:allowBackup="false"
tools:ignore="GoogleAppIndexingWarning,MissingApplicationIcon">
<activity android:name=".MainActivity" />
</application>
</manifest>

View File

@@ -0,0 +1,13 @@
package io.flutter.add2app;
import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}

View File

@@ -0,0 +1,20 @@
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

View File

@@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true

View File

@@ -0,0 +1,6 @@
#Mon Jun 25 14:13:36 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

View File

@@ -0,0 +1,3 @@
include ':app'
setBinding(new Binding([gradle: this]))
evaluate(new File(settingsDir.parentFile, 'hello/.android/include_flutter.groovy'))