From 13e30aaec6b8f415dbb7c2e024f7780a8a3ccd48 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 6 Feb 2020 11:39:55 -0800 Subject: [PATCH] Remove android directory from platform_channel_swift example project (#50213) --- dev/bots/analyze.dart | 2 +- dev/bots/test.dart | 24 ++--- .../android/app/build.gradle | 64 ----------- .../ExampleInstrumentedTest.java | 96 ----------------- .../android/app/src/main/AndroidManifest.xml | 33 ------ .../example/platformchannel/MainActivity.java | 102 ------------------ .../app/src/main/res/values/strings.xml | 8 -- .../android/build.gradle | 33 ------ .../android/gradle.properties | 4 - .../gradle/wrapper/gradle-wrapper.properties | 6 -- .../android/settings.gradle | 19 ---- 11 files changed, 12 insertions(+), 379 deletions(-) delete mode 100644 examples/platform_channel_swift/android/app/build.gradle delete mode 100644 examples/platform_channel_swift/android/app/src/androidTest/java/com/example/platformchannel/ExampleInstrumentedTest.java delete mode 100644 examples/platform_channel_swift/android/app/src/main/AndroidManifest.xml delete mode 100644 examples/platform_channel_swift/android/app/src/main/java/com/example/platformchannel/MainActivity.java delete mode 100644 examples/platform_channel_swift/android/app/src/main/res/values/strings.xml delete mode 100644 examples/platform_channel_swift/android/build.gradle delete mode 100644 examples/platform_channel_swift/android/gradle.properties delete mode 100644 examples/platform_channel_swift/android/gradle/wrapper/gradle-wrapper.properties delete mode 100644 examples/platform_channel_swift/android/settings.gradle diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart index 325666ecd2c..3bfb5c033f6 100644 --- a/dev/bots/analyze.dart +++ b/dev/bots/analyze.dart @@ -225,7 +225,7 @@ String _generateLicense(String prefix) { Future verifyNoMissingLicense(String workingDirectory, { bool checkMinimums = true }) async { final int overrideMinimumMatches = checkMinimums ? null : 0; await _verifyNoMissingLicenseForExtension(workingDirectory, 'dart', overrideMinimumMatches ?? 2000, _generateLicense('// ')); - await _verifyNoMissingLicenseForExtension(workingDirectory, 'java', overrideMinimumMatches ?? 40, _generateLicense('// ')); + await _verifyNoMissingLicenseForExtension(workingDirectory, 'java', overrideMinimumMatches ?? 39, _generateLicense('// ')); await _verifyNoMissingLicenseForExtension(workingDirectory, 'h', overrideMinimumMatches ?? 30, _generateLicense('// ')); await _verifyNoMissingLicenseForExtension(workingDirectory, 'm', overrideMinimumMatches ?? 30, _generateLicense('// ')); await _verifyNoMissingLicenseForExtension(workingDirectory, 'swift', overrideMinimumMatches ?? 10, _generateLicense('// ')); diff --git a/dev/bots/test.dart b/dev/bots/test.dart index 315c2346e87..8759ba2163e 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -282,13 +282,6 @@ Future _runToolTests() async { await selectSubshard(subshards); } -// Example apps that should not be built by _runBuildTests` -const List _excludedExampleApplications = [ - // This application contains no platform code and cannot be built, except for - // as a part of a '--fast-start' Android application. - 'splash', -]; - /// Verifies that AOT, APK, and IPA (if on macOS) builds the examples apps /// without crashing. It does not actually launch the apps. That happens later /// in the devicelab. This is just a smoke-test. In particular, this will verify @@ -300,14 +293,19 @@ Future _runBuildTests() async { if (fileEntity is! Directory) { continue; } - if (_excludedExampleApplications.any(fileEntity.path.endsWith)) { - continue; - } final String examplePath = fileEntity.path; - await _flutterBuildAot(examplePath); - await _flutterBuildApk(examplePath); + if (Directory(path.join(examplePath, 'android')).existsSync()) { + await _flutterBuildAot(examplePath); + await _flutterBuildApk(examplePath); + } else { + print('Example project ${path.basename(examplePath)} has no android directory, skipping aot and apk'); + } if (Platform.isMacOS) { - await _flutterBuildIpa(examplePath); + if (Directory(path.join(examplePath, 'ios')).existsSync()) { + await _flutterBuildIpa(examplePath); + } else { + print('Example project ${path.basename(examplePath)} has no ios directory, skipping ipa'); + } } } diff --git a/examples/platform_channel_swift/android/app/build.gradle b/examples/platform_channel_swift/android/app/build.gradle deleted file mode 100644 index d388981b18a..00000000000 --- a/examples/platform_channel_swift/android/app/build.gradle +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - -android { - compileSdkVersion 28 - - lintOptions { - disable 'InvalidPackage' - } - - defaultConfig { - applicationId "io.flutter.examples.platform_channel_swift" - minSdkVersion 16 - 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 { - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' -} diff --git a/examples/platform_channel_swift/android/app/src/androidTest/java/com/example/platformchannel/ExampleInstrumentedTest.java b/examples/platform_channel_swift/android/app/src/androidTest/java/com/example/platformchannel/ExampleInstrumentedTest.java deleted file mode 100644 index 10eab0fbc8d..00000000000 --- a/examples/platform_channel_swift/android/app/src/androidTest/java/com/example/platformchannel/ExampleInstrumentedTest.java +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2014 The Flutter 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 com.example.platformchannel; - -import static org.junit.Assert.*; - -import android.app.Instrumentation; -import android.graphics.Bitmap; -import android.support.test.InstrumentationRegistry; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; -import io.flutter.view.FlutterView; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Rule - public ActivityTestRule activityRule = - new ActivityTestRule<>(MainActivity.class); - - - @Test - public void testBitmap() { - final Instrumentation instr = InstrumentationRegistry.getInstrumentation(); - final BitmapPoller poller = new BitmapPoller(5); - instr.runOnMainSync(new Runnable() { - public void run() { - final FlutterView flutterView = activityRule.getActivity().getFlutterView(); - - // Call onPostResume to start the engine's renderer even if the activity - // is paused in the test environment. - flutterView.onPostResume(); - - poller.start(flutterView); - } - }); - - Bitmap bitmap = null; - try { - bitmap = poller.waitForBitmap(); - } catch (InterruptedException e) { - fail(e.getMessage()); - } - - assertNotNull(bitmap); - assertTrue(bitmap.getWidth() > 0); - assertTrue(bitmap.getHeight() > 0); - - // Check that a pixel matches the default Material background color. - assertTrue(bitmap.getPixel(bitmap.getWidth() - 1, bitmap.getHeight() - 1) == 0xFFFAFAFA); - } - - // Waits on a FlutterView until it is able to produce a bitmap. - private class BitmapPoller { - private int triesPending; - private int waitMsec; - private FlutterView flutterView; - private Bitmap bitmap; - private CountDownLatch latch = new CountDownLatch(1); - - private final int delayMsec = 1000; - - BitmapPoller(int tries) { - triesPending = tries; - waitMsec = delayMsec * tries + 100; - } - - void start(FlutterView flutterView) { - this.flutterView = flutterView; - flutterView.postDelayed(checkBitmap, delayMsec); - } - - Bitmap waitForBitmap() throws InterruptedException { - latch.await(waitMsec, TimeUnit.MILLISECONDS); - return bitmap; - } - - private Runnable checkBitmap = new Runnable() { - public void run() { - bitmap = flutterView.getBitmap(); - triesPending--; - if (bitmap != null || triesPending == 0) { - latch.countDown(); - } else { - flutterView.postDelayed(checkBitmap, delayMsec); - } - } - }; - } -} diff --git a/examples/platform_channel_swift/android/app/src/main/AndroidManifest.xml b/examples/platform_channel_swift/android/app/src/main/AndroidManifest.xml deleted file mode 100644 index 4093abb597a..00000000000 --- a/examples/platform_channel_swift/android/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/examples/platform_channel_swift/android/app/src/main/java/com/example/platformchannel/MainActivity.java b/examples/platform_channel_swift/android/app/src/main/java/com/example/platformchannel/MainActivity.java deleted file mode 100644 index 2f71bd19a3e..00000000000 --- a/examples/platform_channel_swift/android/app/src/main/java/com/example/platformchannel/MainActivity.java +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2014 The Flutter 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 com.example.platformchannel; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.ContextWrapper; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.BatteryManager; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; -import android.os.Bundle; -import androidx.annotation.NonNull; -import io.flutter.embedding.android.FlutterActivity; -import io.flutter.embedding.engine.FlutterEngine; -import io.flutter.plugin.common.EventChannel; -import io.flutter.plugin.common.EventChannel.EventSink; -import io.flutter.plugin.common.EventChannel.StreamHandler; -import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugins.GeneratedPluginRegistrant; - -public class MainActivity extends FlutterActivity { - private static final String BATTERY_CHANNEL = "samples.flutter.io/battery"; - private static final String CHARGING_CHANNEL = "samples.flutter.io/charging"; - - @Override - public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { - GeneratedPluginRegistrant.registerWith(flutterEngine); - - new EventChannel(flutterEngine.getDartExecutor(), CHARGING_CHANNEL).setStreamHandler( - new StreamHandler() { - private BroadcastReceiver chargingStateChangeReceiver; - @Override - public void onListen(Object arguments, EventSink events) { - chargingStateChangeReceiver = createChargingStateChangeReceiver(events); - registerReceiver( - chargingStateChangeReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); - } - - @Override - public void onCancel(Object arguments) { - unregisterReceiver(chargingStateChangeReceiver); - chargingStateChangeReceiver = null; - } - } - ); - - new MethodChannel(flutterEngine.getDartExecutor(), BATTERY_CHANNEL).setMethodCallHandler( - new MethodCallHandler() { - @Override - public void onMethodCall(MethodCall call, Result result) { - if (call.method.equals("getBatteryLevel")) { - int batteryLevel = getBatteryLevel(); - - if (batteryLevel != -1) { - result.success(batteryLevel); - } else { - result.error("UNAVAILABLE", "Battery level not available.", null); - } - } else { - result.notImplemented(); - } - } - } - ); - } - - private BroadcastReceiver createChargingStateChangeReceiver(final EventSink events) { - return new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); - - if (status == BatteryManager.BATTERY_STATUS_UNKNOWN) { - events.error("UNAVAILABLE", "Charging status unavailable", null); - } else { - boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || - status == BatteryManager.BATTERY_STATUS_FULL; - events.success(isCharging ? "charging" : "discharging"); - } - } - }; - } - - private int getBatteryLevel() { - if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { - BatteryManager batteryManager = (BatteryManager) getSystemService(BATTERY_SERVICE); - return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); - } else { - Intent intent = new ContextWrapper(getApplicationContext()). - registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); - return (intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100) / - intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); - } - } -} diff --git a/examples/platform_channel_swift/android/app/src/main/res/values/strings.xml b/examples/platform_channel_swift/android/app/src/main/res/values/strings.xml deleted file mode 100644 index 1b56c58c71f..00000000000 --- a/examples/platform_channel_swift/android/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - Platform Channel - Flutter Application - diff --git a/examples/platform_channel_swift/android/build.gradle b/examples/platform_channel_swift/android/build.gradle deleted file mode 100644 index 7e89070e492..00000000000 --- a/examples/platform_channel_swift/android/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -buildscript { - repositories { - google() - jcenter() - } - - dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' - } -} - -allprojects { - repositories { - google() - jcenter() - } -} - -rootProject.buildDir = '../build' -subprojects { - project.buildDir = "${rootProject.buildDir}/${project.name}" -} -subprojects { - project.evaluationDependsOn(':app') -} - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/examples/platform_channel_swift/android/gradle.properties b/examples/platform_channel_swift/android/gradle.properties deleted file mode 100644 index 41672498af4..00000000000 --- a/examples/platform_channel_swift/android/gradle.properties +++ /dev/null @@ -1,4 +0,0 @@ -org.gradle.jvmargs=-Xmx1536M -android.useAndroidX=true -android.enableJetifier=true -android.enableR8=true \ No newline at end of file diff --git a/examples/platform_channel_swift/android/gradle/wrapper/gradle-wrapper.properties b/examples/platform_channel_swift/android/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 2819f022f1f..00000000000 --- a/examples/platform_channel_swift/android/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Fri Jun 23 08:50:38 CEST 2017 -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 diff --git a/examples/platform_channel_swift/android/settings.gradle b/examples/platform_channel_swift/android/settings.gradle deleted file mode 100644 index dbc3b58f36d..00000000000 --- a/examples/platform_channel_swift/android/settings.gradle +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -include ':app' - -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() - -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withInputStream { stream -> plugins.load(stream) } -} - -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":$name" - project(":$name").projectDir = pluginDirectory -}