Skip to content

Commit 2e2c044

Browse files
committed
Merge branch 'master' of https://github.com/pauldemarco/flutter_blue into pauldemarco-master
# Conflicts: # android/build.gradle # pubspec.yaml
2 parents 50a1e7b + 7c7a86c commit 2e2c044

32 files changed

+1548
-1603
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.8.0
2+
* Migrate the plugin to null safety.
3+
14
## 0.7.3
25
* Fix Android project template files to be compatible with protobuf-lite.
36
* Add experimental support for MacOS.

README.md

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,6 @@ Using the FlutterBlue instance, you can scan for and connect to nearby devices (
2727
Once connected to a device, the BluetoothDevice object can discover services ([BluetoothService](lib/src/bluetooth_service.dart)), characteristics ([BluetoothCharacteristic](lib/src/bluetooth_characteristic.dart)), and descriptors ([BluetoothDescriptor](lib/src/bluetooth_descriptor.dart)).
2828
The BluetoothDevice object is then used to directly interact with characteristics and descriptors.
2929

30-
## Setup
31-
### Change the minSdkVersion for Android
32-
33-
Flutter_blue is compatible only from version 19 of Android SDK so you should change this in **android/app/build.gradle**:
34-
```dart
35-
Android {
36-
defaultConfig {
37-
minSdkVersion: 19
38-
```
39-
### Add permissions for Bluetooth
40-
We need to add the permission to use Bluetooth and access location:
41-
42-
#### **Android**
43-
In the **android/app/src/main/AndroidManifest.xml** let’s add:
44-
45-
```dart
46-
<uses-permission android:name="android.permission.BLUETOOTH" />
47-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
48-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
49-
<application
50-
```
51-
#### **IOS**
52-
In the **ios/Runner/Info.plist** let’s add:
53-
54-
```dart
55-
<dict>
56-
<key>NSBluetoothAlwaysUsageDescription</key>
57-
<string>Need BLE permission</string>
58-
<key>NSBluetoothPeripheralUsageDescription</key>
59-
<string>Need BLE permission</string>
60-
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
61-
<string>Need Location permission</string>
62-
<key>NSLocationAlwaysUsageDescription</key>
63-
<string>Need Location permission</string>
64-
<key>NSLocationWhenInUseUsageDescription</key>
65-
<string>Need Location permission</string>
66-
```
67-
68-
For location permissions on iOS see more at: [https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services](https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services)
6930
## Usage
7031
### Obtain an instance
7132
```dart
@@ -147,6 +108,47 @@ await device.requestMtu(512);
147108
```
148109
Note that iOS will not allow requests of MTU size, and will always try to negotiate the highest possible MTU (iOS supports up to MTU size 185)
149110

111+
## Getting Started
112+
### Change the minSdkVersion for Android
113+
114+
Flutter_blue is compatible only from version 19 of Android SDK so you should change this in **android/app/build.gradle**:
115+
```dart
116+
Android {
117+
defaultConfig {
118+
minSdkVersion: 19
119+
```
120+
### Add permissions for Bluetooth
121+
We need to add the permission to use Bluetooth and access location:
122+
123+
#### **Android**
124+
In the **android/app/src/main/AndroidManifest.xml** let’s add:
125+
126+
```xml
127+
<uses-permission android:name="android.permission.BLUETOOTH" />
128+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
129+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
130+
<application
131+
```
132+
#### **IOS**
133+
In the **ios/Runner/Info.plist** let’s add:
134+
135+
```dart
136+
<dict>
137+
<key>NSBluetoothAlwaysUsageDescription</key>
138+
<string>Need BLE permission</string>
139+
<key>NSBluetoothPeripheralUsageDescription</key>
140+
<string>Need BLE permission</string>
141+
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
142+
<string>Need Location permission</string>
143+
<key>NSLocationAlwaysUsageDescription</key>
144+
<string>Need Location permission</string>
145+
<key>NSLocationWhenInUseUsageDescription</key>
146+
<string>Need Location permission</string>
147+
```
148+
149+
For location permissions on iOS see more at: [https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services](https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services)
150+
151+
150152
## Reference
151153
### FlutterBlue API
152154
| | Android | iOS | Description |
@@ -182,6 +184,6 @@ Note that iOS will not allow requests of MTU size, and will always try to negoti
182184
| write | :white_check_mark: | :white_check_mark: | Writes the value of the descriptor. |
183185

184186
## Troubleshooting
185-
### Scanning for service UUID's doesn't return any results
187+
### When I scan using a service UUID filter, it doesn't find any devices.
186188
Make sure the device is advertising which service UUID's it supports. This is found in the advertisement
187189
packet as **UUID 16 bit complete list** or **UUID 128 bit complete list**.

android/build.gradle

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
def PLUGIN = "flutter_blue";
2-
def ANDROIDX_WARNING = "flutterPluginsAndroidXWarning";
3-
gradle.buildFinished { buildResult ->
4-
if (buildResult.failure && !rootProject.ext.has(ANDROIDX_WARNING)) {
5-
println ' *********************************************************'
6-
println 'WARNING: This version of ' + PLUGIN + ' will break your Android build if it or its dependencies aren\'t compatible with AndroidX.'
7-
println ' See https://goo.gl/CP92wY for more information on the problem and how to fix it.'
8-
println ' This warning prints for all Android build failures. The real root cause of the error may be unrelated.'
9-
println ' *********************************************************'
10-
rootProject.ext.set(ANDROIDX_WARNING, true);
11-
}
12-
}
13-
141
group 'com.pauldemarco.flutter_blue'
15-
version '1.0-SNAPSHOT'
2+
version '1.0'
163

174
buildscript {
185
repositories {
@@ -21,8 +8,8 @@ buildscript {
218
}
229

2310
dependencies {
24-
classpath 'com.android.tools.build:gradle:3.5.2'
25-
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.13'
11+
classpath 'com.android.tools.build:gradle:4.1.0'
12+
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.15'
2613
}
2714
}
2815

@@ -37,14 +24,10 @@ apply plugin: 'com.android.library'
3724
apply plugin: 'com.google.protobuf'
3825

3926
android {
40-
compileSdkVersion 28
27+
compileSdkVersion 30
4128

4229
defaultConfig {
4330
minSdkVersion 19
44-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
45-
}
46-
lintOptions {
47-
disable 'InvalidPackage'
4831
}
4932
sourceSets {
5033
main {
@@ -56,7 +39,6 @@ android {
5639
}
5740

5841
protobuf {
59-
// Configure the protoc executable
6042
protoc {
6143
// Download from repositories
6244
artifact = 'com.google.protobuf:protoc:3.9.1'
@@ -78,6 +60,10 @@ protobuf {
7860

7961

8062
dependencies {
63+
<<<<<<< HEAD
8164
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
8265
implementation 'androidx.core:core:1.2.0'
66+
=======
67+
implementation 'com.google.protobuf:protobuf-javalite:3.11.4'
68+
>>>>>>> 7c7a86c95a3a2537bfb7e3c368716cdb26cf66b0
8369
}

android/gradle.properties

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

android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

android/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.pauldemarco.flutter_blue">
3-
<uses-permission android:name="android.permission.BLUETOOTH" />
4-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
5-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
3+
<uses-permission android:name="android.permission.BLUETOOTH" />
4+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
5+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
66
</manifest>

example/android/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ 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

example/android/app/build.gradle

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,29 @@ apply plugin: 'com.android.application'
2525
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2626

2727
android {
28-
compileSdkVersion 29
29-
30-
lintOptions {
31-
disable 'InvalidPackage'
32-
}
28+
compileSdkVersion 30
3329

3430
defaultConfig {
31+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3532
applicationId "com.pauldemarco.flutter_blue_example"
3633
minSdkVersion 19
37-
targetSdkVersion 29
34+
targetSdkVersion 30
3835
versionCode flutterVersionCode.toInteger()
3936
versionName flutterVersionName
40-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4137
}
4238

4339
buildTypes {
4440
release {
4541
// TODO: Add your own signing config for the release build.
4642
// Signing with the debug keys for now, so `flutter run --release` works.
4743
signingConfig signingConfigs.debug
44+
// FIXME: Work-around for https://github.com/pauldemarco/flutter_blue/issues/772
45+
shrinkResources false
46+
minifyEnabled false
4847
}
4948
}
5049
}
5150

5251
flutter {
5352
source '../..'
5453
}
55-
56-
dependencies {
57-
testImplementation 'junit:junit:4.12'
58-
androidTestImplementation 'androidx.test:runner:1.2.0'
59-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
60-
}

example/android/app/src/androidTest/java/com/pauldemarco/flutter_blue/EmbeddingV1ActivityTest.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

example/android/app/src/androidTest/java/com/pauldemarco/flutter_blue/FlutterActivityTest.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

example/android/app/src/main/AndroidManifest.xml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.pauldemarco.flutter_blue_example">
3-
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
4-
calls FlutterMain.startInitialization(this); in its onCreate method.
5-
In most cases you can leave this as-is, but you if you want to provide
6-
additional functionality it is fine to subclass or reimplement
7-
FlutterApplication and put your custom class here. -->
8-
<application
9-
android:name="io.flutter.app.FlutterApplication"
3+
<application
104
android:label="flutter_blue_example"
115
android:icon="@mipmap/ic_launcher">
126
<activity
13-
android:name="io.flutter.embedding.android.FlutterActivity"
7+
android:name=".MainActivity"
148
android:launchMode="singleTop"
159
android:theme="@style/LaunchTheme"
16-
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
10+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1711
android:hardwareAccelerated="true"
1812
android:windowSoftInputMode="adjustResize">
19-
<!-- This keeps the window background of the activity showing
20-
until Flutter renders its first frame. It can be removed if
21-
there is no splash screen (such as the default splash screen
22-
defined in @style/LaunchTheme). -->
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. -->
2317
<meta-data
24-
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
25-
android:value="true" />
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. -->
26+
<meta-data
27+
android:name="io.flutter.embedding.android.SplashScreenDrawable"
28+
android:resource="@drawable/launch_background"
29+
/>
2630
<intent-filter>
2731
<action android:name="android.intent.action.MAIN"/>
2832
<category android:name="android.intent.category.LAUNCHER"/>
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.pauldemarco.flutter_blue_example;
22

33
import android.os.Bundle;
4-
import dev.flutter.plugins.e2e.E2EPlugin;
54
import io.flutter.app.FlutterActivity;
65
import com.pauldemarco.flutter_blue.FlutterBluePlugin;
76

@@ -10,6 +9,5 @@ public class EmbeddingV1Activity extends FlutterActivity {
109
protected void onCreate(Bundle savedInstanceState) {
1110
super.onCreate(savedInstanceState);
1211
FlutterBluePlugin.registerWith(registrarFor("com.pauldemarco.flutter_blue.FlutterBluePlugin"));
13-
E2EPlugin.registerWith(registrarFor("dev.flutter.plugins.e2e.E2EPlugin"));
1412
}
1513
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.pauldemarco.flutter_blue_example;
2+
3+
import io.flutter.embedding.android.FlutterActivity;
4+
5+
public class MainActivity extends FlutterActivity {
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="?android:colorBackground" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
4+
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
5+
<!-- Show a splash screen on the activity. Automatically removed when
6+
Flutter draws its first frame -->
7+
<item name="android:windowBackground">@drawable/launch_background</item>
8+
</style>
9+
<!-- Theme applied to the Android Window as soon as the process has started.
10+
This theme determines the color of the Android Window while your
11+
Flutter UI initializes, as well as behind your Flutter UI while its
12+
running.
13+
14+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
15+
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
16+
<item name="android:windowBackground">?android:colorBackground</item>
17+
</style>
18+
</resources>

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.5.0'
8+
classpath 'com.android.tools.build:gradle:4.1.0'
99
}
1010
}
1111

example/android/gradle.properties

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

example/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

0 commit comments

Comments
 (0)