Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 4d861b8

Browse files
Merge pull request #21 from thermoworks/android_12
Allows for android 12 location permissions
2 parents 99e481e + b8e8c72 commit 4d861b8

File tree

6 files changed

+370
-270
lines changed

6 files changed

+370
-270
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@
1111

1212
FlutterBlue is a bluetooth plugin for [Flutter](http://www.flutter.io), a new mobile SDK to help developers build modern apps for iOS and Android.
1313

14+
## Setup
15+
16+
## Android
17+
18+
This app contains *most* but not all of the permissions you'll need to get up and running with bluetooth. For android you'll need to consider whether or not your scan will derive location. If you it does not, you must add this line to your manifest:
19+
20+
```xml
21+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
22+
android:usesPermissionFlags="neverForLocation" />
23+
```
24+
25+
In the case you do derive physical location, you'll need to add this:
26+
27+
```xml
28+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
29+
```
30+
31+
At runtime, you'll also need to request the appropriate permissions for bluetooth and location. You can do this with the [permission_handler](https://pub.dev/packages/permission_handler) package.
32+
33+
If you haven't taken any of the previous steps, you'll likely get an error or recieve no scan results.
34+
1435
## Alpha version
1536

1637
This library is actively developed alongside production apps, and the API will evolve as we continue our way to version 1.0.

android/build.gradle

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,58 @@
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 {
196
google()
20-
jcenter()
7+
mavenCentral()
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

2916
rootProject.allprojects {
3017
repositories {
3118
google()
32-
jcenter()
19+
mavenCentral()
3320
}
3421
}
3522

3623
apply plugin: 'com.android.library'
3724
apply plugin: 'com.google.protobuf'
3825

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

4229
defaultConfig {
4330
minSdkVersion 21
4431
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4532
}
46-
lintOptions {
47-
disable 'InvalidPackage'
33+
34+
compileOptions {
35+
// Use Java 8 language features and APIs
36+
// https://developer.android.com/studio/write/java8-support
37+
// Flag to enable support for the new language APIs
38+
coreLibraryDesugaringEnabled true
39+
// Sets Java compatibility to Java 8
40+
sourceCompatibility JavaVersion.VERSION_1_8
41+
targetCompatibility JavaVersion.VERSION_1_8
4842
}
43+
4944
sourceSets {
5045
main {
5146
proto {
5247
srcDir '../protos'
5348
}
54-
java {
55-
srcDir '../protos'
56-
}
5749
}
5850
}
5951
}
6052

6153
protobuf {
62-
// Configure the protoc executable
6354
protoc {
64-
// Download from repositories
65-
artifact = 'com.google.protobuf:protoc:3.13.0'
66-
}
67-
plugins {
68-
javalite {
69-
// The codegen for lite comes as a separate artifact
70-
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
71-
}
55+
artifact = 'com.google.protobuf:protoc:3.17.3'
7256
}
7357
generateProtoTasks {
7458
all().each { task ->
@@ -82,6 +66,6 @@ protobuf {
8266
}
8367

8468
dependencies {
85-
implementation 'com.google.protobuf:protobuf-javalite:3.11.0'
86-
implementation 'androidx.core:core:1.2.0'
69+
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
70+
implementation 'com.google.protobuf:protobuf-javalite:3.17.3'
8771
}
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
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"/>
6-
</manifest>
3+
<!-- New Bluetooth permissions in Android 12
4+
https://developer.android.com/about/versions/12/features/bluetooth-permissions
5+
-->
6+
<!-- Include "neverForLocation" only if you can strongly assert that
7+
your app never derives physical location from Bluetooth scan results. -->
8+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
9+
android:usesPermissionFlags="neverForLocation" />
10+
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
11+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
12+
13+
<!-- Request legacy Bluetooth permissions on older devices. -->
14+
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
15+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
16+
</manifest>

0 commit comments

Comments
 (0)