Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d1f446e5
Unverified
Commit
d1f446e5
authored
Aug 04, 2018
by
Mikkel Nygaard Ravn
Committed by
GitHub
Aug 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support flutter run/build of module on Android (#20197)
parent
ddd7e4ea
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
313 additions
and
34 deletions
+313
-34
module_test.dart
dev/devicelab/bin/tasks/module_test.dart
+28
-4
gradle.dart
packages/flutter_tools/lib/src/android/gradle.dart
+3
-2
project.dart
packages/flutter_tools/lib/src/project.dart
+6
-1
build.gradle.tmpl
...tools/templates/module/android/app.tmpl/build.gradle.tmpl
+35
-0
AndroidManifest.xml.tmpl
...module/android/app.tmpl/src/main/AndroidManifest.xml.tmpl
+39
-0
MainActivity.java.tmpl
...c/main/java/androidIdentifier/host/MainActivity.java.tmpl
+13
-0
launch_background.xml
...roid/app.tmpl/src/main/res/drawable/launch_background.xml
+12
-0
ic_launcher.png
...android/app.tmpl/src/main/res/mipmap-hdpi/ic_launcher.png
+0
-0
styles.xml
...es/module/android/app.tmpl/src/main/res/values/styles.xml
+8
-0
settings.gradle.tmpl
...utter_tools/templates/module/android/settings.gradle.tmpl
+1
-0
main.dart.tmpl
.../flutter_tools/templates/module/common/lib/main.dart.tmpl
+168
-26
pubspec.yaml.tmpl
...s/flutter_tools/templates/module/common/pubspec.yaml.tmpl
+0
-1
No files found.
dev/devicelab/bin/tasks/module_test.dart
View file @
d1f446e5
...
...
@@ -31,7 +31,7 @@ Future<Null> main() async {
);
});
section
(
'Build
Android .aar
'
);
section
(
'Build
Flutter module library archive
'
);
await
inDirectory
(
new
Directory
(
path
.
join
(
directory
.
path
,
'hello'
,
'.android'
)),
()
async
{
await
exec
(
...
...
@@ -56,6 +56,30 @@ Future<Null> main() async {
return
new
TaskResult
.
failure
(
'Failed to build .aar'
);
}
section
(
'Build ephemeral host app'
);
await
inDirectory
(
new
Directory
(
path
.
join
(
directory
.
path
,
'hello'
)),
()
async
{
await
flutter
(
'build'
,
options:
<
String
>[
'apk'
],
);
});
final
bool
apkBuilt
=
exists
(
new
File
(
path
.
join
(
directory
.
path
,
'hello'
,
'build'
,
'host'
,
'outputs'
,
'apk'
,
'release'
,
'app-release.apk'
,
)));
if
(!
apkBuilt
)
{
return
new
TaskResult
.
failure
(
'Failed to build ephemeral host .apk'
);
}
section
(
'Add to Android app'
);
final
Directory
hostApp
=
new
Directory
(
path
.
join
(
directory
.
path
,
'hello_host_app'
));
...
...
@@ -81,7 +105,7 @@ Future<Null> main() async {
);
});
final
bool
a
ppBuilt
=
exists
(
new
File
(
path
.
join
(
final
bool
existingA
ppBuilt
=
exists
(
new
File
(
path
.
join
(
hostApp
.
path
,
'app'
,
'build'
,
...
...
@@ -91,8 +115,8 @@ Future<Null> main() async {
'app-debug.apk'
,
)));
if
(!
a
ppBuilt
)
{
return
new
TaskResult
.
failure
(
'Failed to build .apk'
);
if
(!
existingA
ppBuilt
)
{
return
new
TaskResult
.
failure
(
'Failed to build
existing app
.apk'
);
}
return
new
TaskResult
.
success
(
null
);
}
catch
(
e
)
{
...
...
packages/flutter_tools/lib/src/android/gradle.dart
View file @
d1f446e5
...
...
@@ -43,8 +43,6 @@ final RegExp ndkMessageFilter = new RegExp(r'^(?!NDK is missing a ".*" directory
r'|If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning'
r'|If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to .*)'
);
FlutterPluginVersion
getFlutterPluginVersion
(
AndroidProject
project
)
{
final
File
plugin
=
project
.
directory
.
childFile
(
fs
.
path
.
join
(
'buildSrc'
,
'src'
,
'main'
,
'groovy'
,
'FlutterPlugin.groovy'
));
...
...
@@ -62,6 +60,9 @@ FlutterPluginVersion getFlutterPluginVersion(AndroidProject project) {
if
(
line
.
contains
(
new
RegExp
(
r'apply from: .*/flutter.gradle'
)))
{
return
FlutterPluginVersion
.
managed
;
}
if
(
line
.
contains
(
"def flutterPluginVersion = 'managed'"
))
{
return
FlutterPluginVersion
.
managed
;
}
}
}
return
FlutterPluginVersion
.
none
;
...
...
packages/flutter_tools/lib/src/project.dart
View file @
d1f446e5
...
...
@@ -76,7 +76,12 @@ class FlutterProject {
IosProject
get
ios
=>
new
IosProject
(
directory
.
childDirectory
(
'ios'
));
/// The Android sub project of this project.
AndroidProject
get
android
=>
new
AndroidProject
(
directory
.
childDirectory
(
'android'
));
AndroidProject
get
android
{
if
(
manifest
.
isModule
)
{
return
new
AndroidProject
(
directory
.
childDirectory
(
'.android'
));
}
return
new
AndroidProject
(
directory
.
childDirectory
(
'android'
));
}
/// The generated AndroidModule sub project of this module project.
AndroidModuleProject
get
androidModule
=>
new
AndroidModuleProject
(
directory
.
childDirectory
(
'.android'
));
...
...
packages/flutter_tools/templates/module/android/app.tmpl/build.gradle.tmpl
0 → 100644
View file @
d1f446e5
def flutterPluginVersion = 'managed'
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "{{androidIdentifier}}.host"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.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
}
}
}
buildDir = new File(rootProject.projectDir, "../build/host")
dependencies {
implementation project(':flutter')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
packages/flutter_tools/templates/module/android/app.tmpl/src/main/AndroidManifest.xml.tmpl
0 → 100644
View file @
d1f446e5
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"{{androidIdentifier}}.host"
>
<!-- 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"
/>
<!-- 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
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name=
"io.flutter.app.FlutterApplication"
android:icon=
"@mipmap/ic_launcher"
>
<activity
android:name=
".MainActivity"
android:launchMode=
"singleTop"
android:theme=
"@style/LaunchTheme"
android:configChanges=
"orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated=
"true"
android:windowSoftInputMode=
"adjustResize"
>
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name=
"io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value=
"true"
/>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
packages/flutter_tools/templates/module/android/app.tmpl/src/main/java/androidIdentifier/host/MainActivity.java.tmpl
0 → 100644
View file @
d1f446e5
package
{{
androidIdentifier
}}.
host
;
import
android
.
os
.
Bundle
;
import
io
.
flutter
.
app
.
FlutterActivity
;
import
io
.
flutter
.
plugins
.
GeneratedPluginRegistrant
;
public
class
MainActivity
extends
FlutterActivity
{
@
Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
GeneratedPluginRegistrant
.
registerWith
(
this
);
}
}
packages/flutter_tools/templates/module/android/app.tmpl/src/main/res/drawable/launch_background.xml
0 → 100644
View file @
d1f446e5
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item
android:drawable=
"@android:color/white"
/>
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
packages/flutter_tools/templates/module/android/app.tmpl/src/main/res/mipmap-hdpi/ic_launcher.png
0 → 100644
View file @
d1f446e5
This diff was suppressed by a .gitattributes entry.
packages/flutter_tools/templates/module/android/app.tmpl/src/main/res/values/styles.xml
0 → 100644
View file @
d1f446e5
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style
name=
"LaunchTheme"
parent=
"@android:style/Theme.Black.NoTitleBar"
>
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item
name=
"android:windowBackground"
>
@drawable/launch_background
</item>
</style>
</resources>
packages/flutter_tools/templates/module/android/settings.gradle.tmpl
View file @
d1f446e5
// Generated file. Do not edit.
include ':app'
rootProject.name = 'android_generated'
setBinding(new Binding([gradle: this]))
...
...
packages/flutter_tools/templates/module/common/lib/main.dart.tmpl
View file @
d1f446e5
import 'package:flutter/material.dart';
{{#withDriverTest}}
import 'package:flutter_driver/driver_extension.dart';
{{/withDriverTest}}
{{#withPluginHook}}
import 'dart:async';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:package_info/package_info.dart';
import 'package:flutter/services.dart';
import 'package:{{pluginProjectName}}/{{pluginProjectName}}.dart';
{{/withPluginHook}}
Future<void> main() async {
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
runApp(Directionality(textDirection: TextDirection.ltr, child: Router(packageInfo)));
{{^withDriverTest}}
void main() => runApp(new MyApp());
{{/withDriverTest}}
{{#withDriverTest}}
void main() {
// Enable integration testing with the Flutter Driver extension.
// See https://flutter.io/testing/ for more info.
enableFlutterDriverExtension();
runApp(new MyApp());
}
{{/withDriverTest}}
{{^withPluginHook}}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or press Run > Flutter Hot Reload in IntelliJ). Notice that the
// counter didn't reset back to zero; the application is not restarted.
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
class Router extends StatelessWidget {
Router(this.packageInfo);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
final PackageInfo packageInfo;
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
final String route = window.defaultRouteName;
switch (route) {
case 'route1':
return Container(
child: Center(child: Text('Route 1\n${packageInfo.appName}')),
color: Colors.green,
);
case 'route2':
return Container(
child: Center(child: Text('Route 2\n${packageInfo.packageName}')),
color: Colors.blue,
);
default:
return Container(
child: Center(child: Text('Unknown route: $route')),
color: Colors.red,
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return new Scaffold(
appBar: new AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: new Text(widget.title),
),
body: new Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: new Column(
// Column is also layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug paint" (press "p" in the console where you ran
// "flutter run", or select "Toggle Debug Paint" from the Flutter tool
// window in IntelliJ) to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(
'You have pushed the button this many times:',
),
new Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: new FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: new Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
{{/withPluginHook}}
{{#withPluginHook}}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await {{pluginDartClass}}.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Plugin example app'),
),
body: new Center(
child: new Text('Running on: $_platformVersion\n'),
),
),
);
}
}
{{/withPluginHook}}
packages/flutter_tools/templates/module/common/pubspec.yaml.tmpl
View file @
d1f446e5
...
...
@@ -3,7 +3,6 @@ description: {{description}}
version: 1.0.0+1
dependencies:
package_info:
flutter:
sdk: flutter
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment