Skip to content

Commit 2f8e6a1

Browse files
Merge pull request #319 from objectbox/example-updates
Examples: fix Android build, resolve warnings
2 parents f8eca24 + 73dc57d commit 2f8e6a1

19 files changed

+134
-114
lines changed

objectbox/example/flutter/objectbox_demo/android/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ gradle-wrapper.jar
55
/gradlew.bat
66
/local.properties
77
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
12+
**/*.keystore
13+
**/*.jks

objectbox/example/flutter/objectbox_demo/android/app/build.gradle

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,27 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

2828
android {
29-
compileSdkVersion 28
29+
compileSdkVersion 29
3030

31-
sourceSets {
32-
main.java.srcDirs += 'src/main/kotlin'
31+
compileOptions {
32+
sourceCompatibility JavaVersion.VERSION_1_8
33+
targetCompatibility JavaVersion.VERSION_1_8
34+
}
35+
36+
kotlinOptions {
37+
jvmTarget = '1.8'
3338
}
3439

35-
lintOptions {
36-
disable 'InvalidPackage'
40+
sourceSets {
41+
main.java.srcDirs += 'src/main/kotlin'
3742
}
3843

3944
defaultConfig {
4045
applicationId "com.example.objectbox_demo"
4146
minSdkVersion 16
42-
targetSdkVersion 28
47+
targetSdkVersion 29
4348
versionCode flutterVersionCode.toInteger()
4449
versionName flutterVersionName
45-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4650
}
4751

4852
buildTypes {
@@ -60,7 +64,4 @@ flutter {
6064

6165
dependencies {
6266
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
63-
testImplementation 'junit:junit:4.12'
64-
androidTestImplementation 'androidx.test:runner:1.1.1'
65-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
6667
}

objectbox/example/flutter/objectbox_demo/android/app/src/main/AndroidManifest.xml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,39 @@
33
<application
44
android:label="objectbox_demo"
55
android:icon="@mipmap/ic_launcher">
6-
7-
<meta-data
8-
android:name="flutterEmbedding"
9-
android:value="2" />
10-
116
<activity
127
android:name=".MainActivity"
138
android:launchMode="singleTop"
149
android:theme="@style/LaunchTheme"
1510
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1611
android:hardwareAccelerated="true"
1712
android:windowSoftInputMode="adjustResize">
18-
<!-- Specify that the launch screen should continue being displayed -->
19-
<!-- until Flutter renders its first frame. -->
13+
<!-- Specifies an Android theme to apply to this Activity as soon as
14+
the Android process has started. This theme is visible to the user
15+
while the Flutter UI initializes. After that, this theme continues
16+
to determine the Window background behind the Flutter UI. -->
2017
<meta-data
21-
android:name="io.flutter.embedding.android.SplashScreenDrawable"
22-
android:resource="@drawable/launch_background" />
23-
24-
<!-- Theme to apply as soon as Flutter begins rendering frames -->
18+
android:name="io.flutter.embedding.android.NormalTheme"
19+
android:resource="@style/NormalTheme"
20+
/>
21+
<!-- Displays an Android View that continues showing the launch screen
22+
Drawable until Flutter paints its first frame, then this splash
23+
screen fades out. A splash screen is useful to avoid any visual
24+
gap between the end of Android's launch screen and the painting of
25+
Flutter's first frame. -->
2526
<meta-data
26-
android:name="io.flutter.embedding.android.NormalTheme"
27-
android:resource="@style/NormalTheme" />
27+
android:name="io.flutter.embedding.android.SplashScreenDrawable"
28+
android:resource="@drawable/launch_background"
29+
/>
2830
<intent-filter>
2931
<action android:name="android.intent.action.MAIN"/>
3032
<category android:name="android.intent.category.LAUNCHER"/>
3133
</intent-filter>
3234
</activity>
35+
<!-- Don't delete the meta-data below.
36+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
37+
<meta-data
38+
android:name="flutterEmbedding"
39+
android:value="2" />
3340
</application>
3441
</manifest>

objectbox/example/flutter/objectbox_demo/android/build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,25 @@ buildscript {
22
ext.kotlin_version = '1.3.50'
33
repositories {
44
google()
5-
jcenter()
5+
mavenCentral()
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.5.0'
9+
classpath 'com.android.tools.build:gradle:4.1.0'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
}
1212
}
1313

1414
allprojects {
1515
repositories {
1616
google()
17-
jcenter()
17+
mavenCentral()
1818
}
1919
}
2020

2121
rootProject.buildDir = '../build'
2222
subprojects {
2323
project.buildDir = "${rootProject.buildDir}/${project.name}"
24-
}
25-
subprojects {
2624
project.evaluationDependsOn(':app')
2725
}
2826

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
org.gradle.jvmargs=-Xmx1536M
2-
android.enableR8=true
32
android.useAndroidX=true
43
android.enableJetifier=true

objectbox/example/flutter/objectbox_demo/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
include ':app'
22

3-
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
3+
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4+
def properties = new Properties()
45

5-
def plugins = new Properties()
6-
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
7-
if (pluginsFile.exists()) {
8-
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
9-
}
6+
assert localPropertiesFile.exists()
7+
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
108

11-
plugins.each { name, path ->
12-
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
13-
include ":$name"
14-
project(":$name").projectDir = pluginDirectory
15-
}
9+
def flutterSdkPath = properties.getProperty("flutter.sdk")
10+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11+
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

objectbox/example/flutter/objectbox_demo/lib/main.dart

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ class Note {
2222
String get dateFormat => DateFormat('dd.MM.yyyy hh:mm:ss').format(date);
2323
}
2424

25-
void main() => runApp(MyApp());
25+
void main() => runApp(const MyApp());
2626

2727
class MyApp extends StatelessWidget {
28+
const MyApp({Key? key}) : super(key: key);
29+
2830
@override
2931
Widget build(BuildContext context) => MaterialApp(
3032
title: 'OB Example',
3133
theme: ThemeData(primarySwatch: Colors.blue),
32-
home: MyHomePage(title: 'OB Example'),
34+
home: const MyHomePage(title: 'OB Example'),
3335
);
3436
}
3537

3638
class MyHomePage extends StatefulWidget {
37-
MyHomePage({Key? key, required this.title}) : super(key: key);
39+
const MyHomePage({Key? key, required this.title}) : super(key: key);
3840

3941
final String title;
4042

@@ -100,28 +102,28 @@ class _MyHomePageState extends State<MyHomePage> {
100102
children: <Widget>[
101103
Expanded(
102104
child: Container(
103-
decoration: BoxDecoration(
105+
decoration: const BoxDecoration(
104106
border:
105107
Border(bottom: BorderSide(color: Colors.black12))),
106108
child: Padding(
107-
padding: EdgeInsets.symmetric(
109+
padding: const EdgeInsets.symmetric(
108110
vertical: 18.0, horizontal: 10.0),
109111
child: Column(
110112
crossAxisAlignment: CrossAxisAlignment.start,
111113
children: <Widget>[
112114
Text(
113115
notes[index].text,
114-
style: TextStyle(
116+
style: const TextStyle(
115117
fontSize: 15.0,
116118
),
117119
// Provide a Key for the integration test
118120
key: Key('list_item_$index'),
119121
),
120122
Padding(
121-
padding: EdgeInsets.only(top: 5.0),
123+
padding: const EdgeInsets.only(top: 5.0),
122124
child: Text(
123125
'Added on ${notes[index].dateFormat}',
124-
style: TextStyle(
126+
style: const TextStyle(
125127
fontSize: 12.0,
126128
),
127129
),
@@ -142,24 +144,24 @@ class _MyHomePageState extends State<MyHomePage> {
142144
),
143145
body: Column(children: <Widget>[
144146
Padding(
145-
padding: EdgeInsets.all(20.0),
147+
padding: const EdgeInsets.all(20.0),
146148
child: Row(
147149
children: <Widget>[
148150
Expanded(
149151
child: Column(
150152
children: <Widget>[
151153
Padding(
152-
padding: EdgeInsets.symmetric(horizontal: 10.0),
154+
padding: const EdgeInsets.symmetric(horizontal: 10.0),
153155
child: TextField(
154156
decoration:
155-
InputDecoration(hintText: 'Enter a new note'),
157+
const InputDecoration(hintText: 'Enter a new note'),
156158
controller: _noteInputController,
157159
onSubmitted: (value) => _addNote(),
158160
// Provide a Key for the integration test
159-
key: Key('input'),
161+
key: const Key('input'),
160162
),
161163
),
162-
Padding(
164+
const Padding(
163165
padding: EdgeInsets.only(top: 10.0, right: 10.0),
164166
child: Align(
165167
alignment: Alignment.centerRight,
@@ -183,17 +185,17 @@ class _MyHomePageState extends State<MyHomePage> {
183185
stream: _listController.stream,
184186
builder: (context, snapshot) => ListView.builder(
185187
shrinkWrap: true,
186-
padding: EdgeInsets.symmetric(horizontal: 20.0),
188+
padding: const EdgeInsets.symmetric(horizontal: 20.0),
187189
itemCount: snapshot.hasData ? snapshot.data!.length : 0,
188190
itemBuilder: _itemBuilder(snapshot.data ?? []))))
189191
]),
190192
// We need a separate submit button because flutter_driver integration
191193
// test doesn't support submitting a TextField using "enter" key.
192194
// See https://github.com/flutter/flutter/issues/9383
193195
floatingActionButton: FloatingActionButton(
194-
key: Key('submit'),
196+
key: const Key('submit'),
195197
onPressed: _addNote,
196-
child: Icon(Icons.add),
198+
child: const Icon(Icons.add),
197199
),
198200
);
199201
}

objectbox/example/flutter/objectbox_demo/windows/flutter/generated_plugin_registrant.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Generated file. Do not edit.
33
//
44

5+
// clang-format off
6+
57
#include "generated_plugin_registrant.h"
68

79
#include <objectbox_flutter_libs/objectbox_flutter_libs_plugin.h>

objectbox/example/flutter/objectbox_demo/windows/flutter/generated_plugin_registrant.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Generated file. Do not edit.
33
//
44

5+
// clang-format off
6+
57
#ifndef GENERATED_PLUGIN_REGISTRANT_
68
#define GENERATED_PLUGIN_REGISTRANT_
79

objectbox/example/flutter/objectbox_demo_sync/android/app/build.gradle

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,27 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

2828
android {
29-
compileSdkVersion 28
29+
compileSdkVersion 29
3030

31-
sourceSets {
32-
main.java.srcDirs += 'src/main/kotlin'
31+
compileOptions {
32+
sourceCompatibility JavaVersion.VERSION_1_8
33+
targetCompatibility JavaVersion.VERSION_1_8
34+
}
35+
36+
kotlinOptions {
37+
jvmTarget = '1.8'
3338
}
3439

35-
lintOptions {
36-
disable 'InvalidPackage'
40+
sourceSets {
41+
main.java.srcDirs += 'src/main/kotlin'
3742
}
3843

3944
defaultConfig {
4045
applicationId "com.example.objectbox_demo"
4146
minSdkVersion 21
42-
targetSdkVersion 28
47+
targetSdkVersion 29
4348
versionCode flutterVersionCode.toInteger()
4449
versionName flutterVersionName
45-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4650
}
4751

4852
buildTypes {
@@ -60,7 +64,4 @@ flutter {
6064

6165
dependencies {
6266
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
63-
testImplementation 'junit:junit:4.12'
64-
androidTestImplementation 'androidx.test:runner:1.1.1'
65-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
6667
}

objectbox/example/flutter/objectbox_demo_sync/android/app/src/main/AndroidManifest.xml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,39 @@
33
<application
44
android:label="objectbox_demo"
55
android:icon="@mipmap/ic_launcher">
6-
7-
<meta-data
8-
android:name="flutterEmbedding"
9-
android:value="2" />
10-
116
<activity
127
android:name=".MainActivity"
138
android:launchMode="singleTop"
149
android:theme="@style/LaunchTheme"
1510
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1611
android:hardwareAccelerated="true"
1712
android:windowSoftInputMode="adjustResize">
18-
<!-- Specify that the launch screen should continue being displayed -->
19-
<!-- until Flutter renders its first frame. -->
13+
<!-- Specifies an Android theme to apply to this Activity as soon as
14+
the Android process has started. This theme is visible to the user
15+
while the Flutter UI initializes. After that, this theme continues
16+
to determine the Window background behind the Flutter UI. -->
2017
<meta-data
21-
android:name="io.flutter.embedding.android.SplashScreenDrawable"
22-
android:resource="@drawable/launch_background" />
23-
24-
<!-- Theme to apply as soon as Flutter begins rendering frames -->
18+
android:name="io.flutter.embedding.android.NormalTheme"
19+
android:resource="@style/NormalTheme"
20+
/>
21+
<!-- Displays an Android View that continues showing the launch screen
22+
Drawable until Flutter paints its first frame, then this splash
23+
screen fades out. A splash screen is useful to avoid any visual
24+
gap between the end of Android's launch screen and the painting of
25+
Flutter's first frame. -->
2526
<meta-data
26-
android:name="io.flutter.embedding.android.NormalTheme"
27-
android:resource="@style/NormalTheme" />
27+
android:name="io.flutter.embedding.android.SplashScreenDrawable"
28+
android:resource="@drawable/launch_background"
29+
/>
2830
<intent-filter>
2931
<action android:name="android.intent.action.MAIN"/>
3032
<category android:name="android.intent.category.LAUNCHER"/>
3133
</intent-filter>
3234
</activity>
35+
<!-- Don't delete the meta-data below.
36+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
37+
<meta-data
38+
android:name="flutterEmbedding"
39+
android:value="2" />
3340
</application>
3441
</manifest>

0 commit comments

Comments
 (0)