Skip to content

Commit 6fa2354

Browse files
authored
Merge pull request #24 from wuba/magpie_androidx_hxin
修改模版适配1.17.3
2 parents da2bc1d + 39eec8c commit 6fa2354

File tree

8 files changed

+127
-41
lines changed

8 files changed

+127
-41
lines changed

template/module/android_magpie/Flutter/src/main/AndroidManifest.xml

+4
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@
77
<meta-data
88
android:name="flutterProjectType"
99
android:value="module" />
10+
11+
<meta-data
12+
android:name="flutterEmbedding"
13+
android:value="2" />
1014
</application>
1115
</manifest>

template/module/android_magpie/app/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@ buildDir = new File(rootProject.projectDir, "../build/host")
6161
dependencies {
6262
implementation project(':flutter')
6363
implementation fileTree(dir: 'libs', include: ['*.jar'])
64+
implementation 'androidx.appcompat:appcompat:1.0.2'
65+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
6466
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.test113.host">
4+
5+
<!-- The INTERNET permission is required for development. Specifically,
6+
flutter needs it to communicate with the running application
7+
to allow setting breakpoints, to provide hot reload, etc.
8+
-->
9+
<uses-permission android:name="android.permission.INTERNET"/>
10+
11+
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
12+
calls FlutterMain.startInitialization(this); in its onCreate method.
13+
In most cases you can leave this as-is, but you if you want to provide
14+
additional functionality it is fine to subclass or reimplement
15+
FlutterApplication and put your custom class here. -->
16+
<application
17+
android:name="io.flutter.app.FlutterApplication"
18+
android:label="test113"
19+
android:icon="@mipmap/ic_launcher">
20+
<activity
21+
android:name=".MainActivity"
22+
android:launchMode="singleTop"
23+
android:theme="@style/LaunchTheme"
24+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
25+
android:hardwareAccelerated="true"
26+
android:windowSoftInputMode="adjustResize">
27+
<!-- This keeps the window background of the activity showing
28+
until Flutter renders its first frame. It can be removed if
29+
there is no splash screen (such as the default splash screen
30+
defined in @style/LaunchTheme). -->
31+
<meta-data
32+
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
33+
android:value="true" />
34+
<intent-filter>
35+
<action android:name="android.intent.action.MAIN"/>
36+
<category android:name="android.intent.category.LAUNCHER"/>
37+
</intent-filter>
38+
</activity>
39+
<!-- Don't delete the meta-data below.
40+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
41+
<meta-data
42+
android:name="flutterEmbedding"
43+
android:value="2" />
44+
</application>
45+
</manifest>

template/module/android_magpie/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ allprojects {
1717
google()
1818
jcenter()
1919
mavenCentral()
20+
maven {
21+
url 'http://download.flutter.io'
22+
}
2023
}
2124
}
2225

Original file line numberDiff line numberDiff line change
@@ -1,38 +1,20 @@
1-
// Generated file. Do not edit.
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
24

35
def scriptFile = getClass().protectionDomain.codeSource.location.toURI()
4-
print('scriptFile:${scriptFile}')
56
def flutterProjectRoot = new File(scriptFile).parentFile.parentFile
67

7-
gradle.include ':flutter'
8-
//gradle.project(':flutter').projectDir = new File(flutterProjectRoot, '.android/Flutter')
9-
gradle.project(':flutter').projectDir = new File(flutterProjectRoot, 'android_magpie/Flutter')
8+
gradle.include ":flutter"
9+
gradle.project(":flutter").projectDir = new File(flutterProjectRoot, ".android/Flutter")
1010

11+
def localPropertiesFile = new File(flutterProjectRoot, ".android/local.properties")
12+
def properties = new Properties()
1113

12-
def plugins = new Properties()
13-
def pluginsFile = new File(flutterProjectRoot, '.flutter-plugins')
14-
if (pluginsFile.exists()) {
15-
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
16-
}
14+
assert localPropertiesFile.exists(), "❗️The Flutter module doesn't have a `$localPropertiesFile` file." +
15+
"\nYou must run `flutter pub get` in `$flutterProjectRoot`."
16+
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
1717

18-
plugins.each { name, path ->
19-
def pluginDirectory = flutterProjectRoot.toPath().resolve(path).resolve('android').toFile()
20-
gradle.include ":$name"
21-
gradle.project(":$name").projectDir = pluginDirectory
22-
}
23-
24-
gradle.getGradle().projectsLoaded { g ->
25-
g.rootProject.beforeEvaluate { p ->
26-
_mainModuleName = binding.variables['mainModuleName']
27-
if (_mainModuleName != null && !_mainModuleName.empty) {
28-
p.ext.mainModuleName = _mainModuleName
29-
}
30-
}
31-
g.rootProject.afterEvaluate { p ->
32-
p.subprojects { sp ->
33-
if (sp.name != 'flutter') {
34-
sp.evaluationDependsOn(':flutter')
35-
}
36-
}
37-
}
38-
}
18+
def flutterSdkPath = properties.getProperty("flutter.sdk")
19+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
20+
gradle.apply from: "$flutterSdkPath/packages/flutter_tools/gradle/module_plugin_loader.gradle"

template/module/android_magpie/settings.gradle

100644100755
File mode changed.

template/module/lib/main.dart

100644100755
+58-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:magpie/magpie.dart';
23

34
void main() => runApp(MyApp());
45

@@ -38,11 +39,63 @@ class MyHomePage extends StatefulWidget {
3839

3940
final String title;
4041

42+
43+
4144
@override
4245
_MyHomePageState createState() => _MyHomePageState();
4346
}
4447

4548
class _MyHomePageState extends State<MyHomePage> {
49+
50+
@override
51+
void initState() {
52+
// TODO: implement initState
53+
super.initState();
54+
Magpie.singleton.registerPageBuilders({
55+
'flutterPage': (String pageName, Map<String, dynamic> params, String _) {
56+
print("flutterPage params:$params");
57+
return MyTestRouteWidget();
58+
},
59+
});
60+
}
61+
62+
void _onRoutePushed(
63+
String pageName,
64+
String uniqueId,
65+
Map<String, dynamic> params,
66+
Route<dynamic> route,
67+
Future<dynamic> _,
68+
) {}
69+
70+
@override
71+
Widget build(BuildContext context) {
72+
73+
74+
return MaterialApp(
75+
title: 'magpie example',
76+
builder: Magpie.init(postPush: _onRoutePushed),
77+
home: Container(color:Colors.white));
78+
79+
// This method is rerun every time setState is called, for instance as done
80+
// by the _incrementCounter method above.
81+
//
82+
// The Flutter framework has been optimized to make rerunning build methods
83+
// fast, so that you can just rebuild anything that needs updating rather
84+
// than having to individually change instances of widgets.
85+
86+
}
87+
}
88+
89+
90+
class MyTestRouteWidget extends StatefulWidget {
91+
92+
@override
93+
State<StatefulWidget> createState() => MyRoute();
94+
95+
}
96+
97+
class MyRoute extends State<MyTestRouteWidget> {
98+
4699
int _counter = 0;
47100

48101
void _incrementCounter() {
@@ -58,17 +111,11 @@ class _MyHomePageState extends State<MyHomePage> {
58111

59112
@override
60113
Widget build(BuildContext context) {
61-
// This method is rerun every time setState is called, for instance as done
62-
// by the _incrementCounter method above.
63-
//
64-
// The Flutter framework has been optimized to make rerunning build methods
65-
// fast, so that you can just rebuild anything that needs updating rather
66-
// than having to individually change instances of widgets.
67114
return Scaffold(
68115
appBar: AppBar(
69116
// Here we take the value from the MyHomePage object that was created by
70117
// the App.build method, and use it to set our appbar title.
71-
title: Text(widget.title),
118+
title: Text("hxin"),
72119
),
73120
body: Center(
74121
// Center is a layout widget. It takes a single child and positions it
@@ -91,7 +138,7 @@ class _MyHomePageState extends State<MyHomePage> {
91138
mainAxisAlignment: MainAxisAlignment.center,
92139
children: <Widget>[
93140
Text(
94-
'You have pushed the button this many times:',
141+
'You have pushed the button this many times now:',
95142
),
96143
Text(
97144
'$_counter',
@@ -107,4 +154,6 @@ class _MyHomePageState extends State<MyHomePage> {
107154
), // This trailing comma makes auto-formatting nicer for build methods.
108155
);
109156
}
110-
}
157+
158+
159+
}

template/module/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dependencies:
3030
magpie:
3131
git:
3232
url: https://github.com/wuba/magpie_sdk.git
33+
ref: dev_androidx_0.0.1
3334

3435
dev_dependencies:
3536
flutter_test:
@@ -85,6 +86,6 @@ flutter:
8586
# They also do not have any bearing on your native host application's
8687
# identifiers, which may be completely independent or the same as these.
8788
module:
88-
androidX: false
89+
androidX: true
8990
androidPackage: com.example.wb_flutter_module
9091
iosBundleIdentifier: com.example.wbFlutterModule

0 commit comments

Comments
 (0)