[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[package_info] Support the v2 Android embedder (with e2e tests) #2160

Merged
merged 55 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
85172df
Support the v2 Android embedder
collinjackson Oct 7, 2019
17bd422
Move to dev namespace
collinjackson Oct 7, 2019
fe8d3a8
Add enableR8
collinjackson Oct 7, 2019
83dd9f0
reformat
collinjackson Oct 7, 2019
0946eeb
Include testing
collinjackson Oct 7, 2019
ab5be52
Add a unit test and migrate to e2e test binding
collinjackson Oct 7, 2019
a4fc6ba
Fix bugs uncovered by e2e tests
collinjackson Oct 7, 2019
4cb7bf2
Convert to androidX, move some things around
collinjackson Oct 7, 2019
a9866da
Add a unit test
collinjackson Oct 7, 2019
0639c46
Rename test to be more descriptive
collinjackson Oct 7, 2019
55813be
Reformat
collinjackson Oct 7, 2019
e7d4f21
Update CHANGELOG
collinjackson Oct 7, 2019
ff1e2cf
Add an integration test of the example app
collinjackson Oct 7, 2019
1c6448c
Add e2e extension
collinjackson Oct 7, 2019
1e9cc06
Fix analyzer issues
collinjackson Oct 7, 2019
502e72f
reformat
collinjackson Oct 7, 2019
e3107bf
jetify
collinjackson Oct 7, 2019
2a0c3cc
Return exit code
collinjackson Oct 7, 2019
f7717af
enableR8
collinjackson Oct 7, 2019
f9c7d16
Update to point to e2e package
collinjackson Oct 7, 2019
7c928fc
Amir CR feedback
collinjackson Oct 7, 2019
a624929
Bump min version to 1.6.7
collinjackson Oct 7, 2019
6c996fb
Merge remote-tracking branch 'origin/master' into migrate_package_info
collinjackson Oct 8, 2019
45a6d9d
Move test location
collinjackson Oct 8, 2019
397395d
Fix analyzer failures
collinjackson Oct 8, 2019
c44fed0
reformat
collinjackson Oct 8, 2019
e276af0
Add copyrights
collinjackson Oct 8, 2019
ba5ea93
Remove backtick
collinjackson Oct 8, 2019
83db9b7
Test using plugin_tools from a branch
collinjackson Oct 14, 2019
fd15c6d
Fix package name
collinjackson Oct 14, 2019
6160d81
Update to new package conventions
collinjackson Oct 14, 2019
0bd7375
Add build.gradle
collinjackson Oct 14, 2019
2af8457
Fix package names
collinjackson Oct 14, 2019
0121e9e
Fix activity launch
collinjackson Oct 14, 2019
e5a370b
Update https checkout
collinjackson Oct 14, 2019
4f2ab2f
Update to point to latest e2e plugin, add E2E plugin to example, clea…
collinjackson Oct 15, 2019
ced1f8d
Fix temporary cirrus command
collinjackson Oct 15, 2019
054b1a0
Remove singleTop from AndroidManifest.xml
collinjackson Oct 15, 2019
91be486
Merge remote-tracking branch 'origin/master' into migrate_package_info
collinjackson Oct 15, 2019
265127f
Add missing import
collinjackson Oct 15, 2019
1e8f811
Revert cirrus changes
collinjackson Oct 15, 2019
e497d95
Add comment
collinjackson Oct 15, 2019
f21476a
reformat
collinjackson Oct 15, 2019
a2bca9c
Enable Firebase Test Lab test
collinjackson Oct 16, 2019
77d22f3
Revert file that shouldn’t have been modified
collinjackson Oct 16, 2019
a0c5273
Temporary commit to try out flutter_plugin_tools changes
collinjackson Oct 17, 2019
b6c0ceb
Set Firebase Test Lab key in .cirrus.yml
collinjackson Oct 17, 2019
d95a8c5
Add gcloud to Dockerfile
collinjackson Oct 17, 2019
d1b8e10
add some sudo
collinjackson Oct 17, 2019
881c1c9
Add gpg-agent package
collinjackson Oct 17, 2019
a42674b
reorder commands
collinjackson Oct 17, 2019
64e3352
Reorder commands again
collinjackson Oct 17, 2019
491234f
add more install commands
collinjackson Oct 17, 2019
a16cfd2
remove extraneous &&
collinjackson Oct 17, 2019
1e84ad0
Remove changes not intended to be landed
collinjackson Oct 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ task:
- flutter channel master
- flutter upgrade
- git fetch origin master
activate_script: pub global activate flutter_plugin_tools
activate_script:
# Remove before landing
- git clone https://github.com/collinjackson/plugin_tools.git flutter_plugin_tools
- pub global activate flutter_plugin_tools -s path
matrix:
- name: publishable
script: ./script/check_publish.sh
Expand Down
7 changes: 7 additions & 0 deletions packages/package_info/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.4.0+8

* Support the v2 Android embedder.
* Update to AndroidX.
* Add a unit test.
* Migrate to using the new e2e test binding.

## 0.4.0+7

* Update and migrate iOS example project.
Expand Down
25 changes: 25 additions & 0 deletions packages/package_info/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,28 @@ android {
disable 'InvalidPackage'
}
}

// TODO(amirh): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
afterEvaluate {
def containsEmbeddingDependencies = false
for (def configuration : configurations.all) {
for (def dependency : configuration.dependencies) {
if (dependency.group == 'io.flutter' &&
dependency.name.startsWith('flutter_embedding') &&
dependency.isTransitive())
{
containsEmbeddingDependencies = true
break
}
}
}
if (!containsEmbeddingDependencies) {
android {
dependencies {
def lifecycle_version = "2.1.0"
api "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
api "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
}
}
}
}
1 change: 1 addition & 0 deletions packages/package_info/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.gradle.jvmargs=-Xmx1536M
android.enableJetifier=true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the affect of adding this to a plugin's gradle file? Does this setting gets propagated to all apps who are using the plugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the name, I'm hoping that enableJetifier does not imply enableAndroidX, so it should reduce compilation errors without causing compilation errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has any meaning without enableAndroidX, and if it does I think it would also implicitly turn AndroidX on. If AndroidX is enabled and this flag is true, Gradle will attempt to run Jetifier to convert any support references to AndroidX ones. I'm not sure how Gradle handles just this flag with enableAndroidX being undefined.

I'm pretty sure that putting this here means that this subproject and only this subproject would be affected, but there may be some weirdness here on account of our build system.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
Expand All @@ -17,31 +19,45 @@
import java.util.Map;

/** PackageInfoPlugin */
public class PackageInfoPlugin implements MethodCallHandler {
private final Registrar mRegistrar;
public class PackageInfoPlugin implements MethodCallHandler, FlutterPlugin {
private Context applicationContext;
private MethodChannel methodChannel;

/** Plugin registration. */
public static void registerWith(Registrar registrar) {
final MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/package_info");
channel.setMethodCallHandler(new PackageInfoPlugin(registrar));
final PackageInfoPlugin instance = new PackageInfoPlugin();
instance.onAttachedToEngine(registrar.context(), registrar.messenger());
}

private PackageInfoPlugin(Registrar registrar) {
this.mRegistrar = registrar;
@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
onAttachedToEngine(
binding.getApplicationContext(), binding.getFlutterEngine().getDartExecutor());
}

private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger) {
this.applicationContext = applicationContext;
methodChannel = new MethodChannel(messenger, "plugins.flutter.io/package_info");
methodChannel.setMethodCallHandler(this);
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
applicationContext = null;
methodChannel.setMethodCallHandler(null);
methodChannel = null;
}

@Override
public void onMethodCall(MethodCall call, Result result) {
try {
Context context = mRegistrar.context();
if (call.method.equals("getAll")) {
PackageManager pm = context.getPackageManager();
PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
PackageManager pm = applicationContext.getPackageManager();
PackageInfo info = pm.getPackageInfo(applicationContext.getPackageName(), 0);

Map<String, String> map = new HashMap<>();
map.put("appName", info.applicationInfo.loadLabel(pm).toString());
map.put("packageName", context.getPackageName());
map.put("packageName", applicationContext.getPackageName());
map.put("version", info.versionName);
map.put("buildNumber", String.valueOf(getLongVersionCode(info)));

Expand Down
3 changes: 2 additions & 1 deletion packages/package_info/example/android/app/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
android.enableJetifier=true
android.useAndroidX=true
android.useAndroidX=true
android.enableR8=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.packageinfoexample;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class EmbedderV1ActivityTest {
@Rule public ActivityTestRule<EmbedderV1Activity> rule = new ActivityTestRule<>(EmbedderV1Activity.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.packageinfoexample;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class MainActivityTest {
@Rule public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<application android:name="io.flutter.app.FlutterApplication" android:label="package_info_example" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
Expand All @@ -15,5 +14,11 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".EmbedderV1Activity"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.packageinfoexample;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class EmbedderV1Activity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

package io.flutter.plugins.packageinfoexample;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import dev.flutter.plugins.e2e.E2EPlugin;
import io.flutter.plugins.packageinfo.PackageInfoPlugin;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
public void configureFlutterEngine(FlutterEngine flutterEngine) {
flutterEngine.getPlugins().add(new PackageInfoPlugin());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a TODO to remove this once the generated registrant for the v2 embedder is on stable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flutterEngine.getPlugins().add(new E2EPlugin());
}
}
3 changes: 3 additions & 0 deletions packages/package_info/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableJetifier=true
android.enableR8=true
android.useAndroidX=true
1 change: 1 addition & 0 deletions packages/package_info/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies:
sdk: flutter
package_info:
path: ../
e2e: "^0.2.1"

dev_dependencies:
flutter_driver:
Expand Down
31 changes: 0 additions & 31 deletions packages/package_info/example/test_driver/package_info.dart

This file was deleted.

51 changes: 51 additions & 0 deletions packages/package_info/example/test_driver/package_info_e2e.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
collinjackson marked this conversation as resolved.
Show resolved Hide resolved
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:e2e/e2e.dart';
import 'package:package_info/package_info.dart';
import 'package:package_info_example/main.dart';

void main() {
E2EWidgetsFlutterBinding.ensureInitialized();

testWidgets('fromPlatform', (WidgetTester tester) async {
final PackageInfo info = await PackageInfo.fromPlatform();
// These tests are based on the example app. The tests should be updated if any related info changes.
if (Platform.isAndroid) {
expect(info.appName, 'package_info_example');
expect(info.buildNumber, '1');
expect(info.packageName, 'io.flutter.plugins.packageinfoexample');
expect(info.version, '1.0');
} else if (Platform.isIOS) {
expect(info.appName, 'Package Info Example');
expect(info.buildNumber, '1');
expect(info.packageName, 'io.flutter.plugins.packageInfoExample');
expect(info.version, '1.0');
} else {
throw (UnsupportedError('platform not supported'));
}
});

testWidgets('example', (WidgetTester tester) async {
await tester.pumpWidget(MyApp());
await tester.pumpAndSettle();
if (Platform.isAndroid) {
expect(find.text('package_info_example'), findsOneWidget);
expect(find.text('1'), findsOneWidget);
expect(
find.text('io.flutter.plugins.packageinfoexample'), findsOneWidget);
expect(find.text('1.0'), findsOneWidget);
} else if (Platform.isIOS) {
expect(find.text('Package Info Example'), findsOneWidget);
expect(find.text('1'), findsOneWidget);
expect(
find.text('io.flutter.plugins.packageInfoExample'), findsOneWidget);
expect(find.text('1.0'), findsOneWidget);
} else {
throw (UnsupportedError('platform not supported'));
}
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:flutter_driver/flutter_driver.dart';

Future<void> main() async {
final FlutterDriver driver = await FlutterDriver.connect();
final String result =
await driver.requestData(null, timeout: const Duration(minutes: 1));
driver.close();
exit(result == 'pass' ? 0 : 1);
}
10 changes: 0 additions & 10 deletions packages/package_info/example/test_driver/package_info_test.dart

This file was deleted.

5 changes: 3 additions & 2 deletions packages/package_info/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for querying information about the application
package, such as CFBundleVersion on iOS or versionCode on Android.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/package_info
version: 0.4.0+7
version: 0.4.0+8

flutter:
plugin:
Expand All @@ -21,7 +21,8 @@ dev_dependencies:
flutter_driver:
sdk: flutter
test: any
e2e: "^0.2.1"

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=1.5.0 <2.0.0"
flutter: ">=1.6.7 <2.0.0"
Loading