Remove android directory from platform_channel_swift example project (#50213)
This commit is contained in:
parent
a0665aba49
commit
13e30aaec6
@ -225,7 +225,7 @@ String _generateLicense(String prefix) {
|
|||||||
Future<void> verifyNoMissingLicense(String workingDirectory, { bool checkMinimums = true }) async {
|
Future<void> verifyNoMissingLicense(String workingDirectory, { bool checkMinimums = true }) async {
|
||||||
final int overrideMinimumMatches = checkMinimums ? null : 0;
|
final int overrideMinimumMatches = checkMinimums ? null : 0;
|
||||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'dart', overrideMinimumMatches ?? 2000, _generateLicense('// '));
|
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, 'h', overrideMinimumMatches ?? 30, _generateLicense('// '));
|
||||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'm', overrideMinimumMatches ?? 30, _generateLicense('// '));
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'm', overrideMinimumMatches ?? 30, _generateLicense('// '));
|
||||||
await _verifyNoMissingLicenseForExtension(workingDirectory, 'swift', overrideMinimumMatches ?? 10, _generateLicense('// '));
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'swift', overrideMinimumMatches ?? 10, _generateLicense('// '));
|
||||||
|
@ -282,13 +282,6 @@ Future<void> _runToolTests() async {
|
|||||||
await selectSubshard(subshards);
|
await selectSubshard(subshards);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example apps that should not be built by _runBuildTests`
|
|
||||||
const List<String> _excludedExampleApplications = <String>[
|
|
||||||
// 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
|
/// 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
|
/// 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
|
/// in the devicelab. This is just a smoke-test. In particular, this will verify
|
||||||
@ -300,14 +293,19 @@ Future<void> _runBuildTests() async {
|
|||||||
if (fileEntity is! Directory) {
|
if (fileEntity is! Directory) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (_excludedExampleApplications.any(fileEntity.path.endsWith)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final String examplePath = fileEntity.path;
|
final String examplePath = fileEntity.path;
|
||||||
await _flutterBuildAot(examplePath);
|
if (Directory(path.join(examplePath, 'android')).existsSync()) {
|
||||||
await _flutterBuildApk(examplePath);
|
await _flutterBuildAot(examplePath);
|
||||||
|
await _flutterBuildApk(examplePath);
|
||||||
|
} else {
|
||||||
|
print('Example project ${path.basename(examplePath)} has no android directory, skipping aot and apk');
|
||||||
|
}
|
||||||
if (Platform.isMacOS) {
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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'
|
|
||||||
}
|
|
@ -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<MainActivity> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -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. -->
|
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="com.example.platformchannel">
|
|
||||||
|
|
||||||
<!-- The INTERNET permission is required for development. Specifically,
|
|
||||||
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"/>
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
|
||||||
|
|
||||||
<application android:name="io.flutter.app.FlutterApplication" android:label="@string/app_name">
|
|
||||||
<activity android:name=".MainActivity"
|
|
||||||
android:launchMode="singleTop"
|
|
||||||
android:theme="@android:style/Theme.Black.NoTitleBar"
|
|
||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
|
||||||
android:hardwareAccelerated="true"
|
|
||||||
android:windowSoftInputMode="adjustResize">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<!-- Don't delete the meta-data below.
|
|
||||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
|
||||||
<meta-data
|
|
||||||
android:name="flutterEmbedding"
|
|
||||||
android:value="2" />
|
|
||||||
</application>
|
|
||||||
</manifest>
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +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. -->
|
|
||||||
|
|
||||||
<resources>
|
|
||||||
<string name="app_name">Platform Channel</string>
|
|
||||||
<string name="title">Flutter Application</string>
|
|
||||||
</resources>
|
|
@ -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
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
org.gradle.jvmargs=-Xmx1536M
|
|
||||||
android.useAndroidX=true
|
|
||||||
android.enableJetifier=true
|
|
||||||
android.enableR8=true
|
|
@ -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
|
|
@ -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
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user