Skip to content

Commit abdc3c1

Browse files
authored
Use latest protobuf compiler (pauldemarco#676)
* checkPermission fixes * remove appcompat * remove static instance which overrides a activity field * Switch to new protobuf compiler
1 parent f0853cb commit abdc3c1

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

android/build.gradle

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ buildscript {
2222

2323
dependencies {
2424
classpath 'com.android.tools.build:gradle:3.5.2'
25-
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
25+
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.13'
2626
}
2727
}
2828

@@ -59,25 +59,20 @@ protobuf {
5959
// Configure the protoc executable
6060
protoc {
6161
// Download from repositories
62-
artifact = 'com.google.protobuf:protoc:3.9.1'
63-
}
64-
plugins {
65-
javalite {
66-
// The codegen for lite comes as a separate artifact
67-
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
68-
}
62+
artifact = 'com.google.protobuf:protoc:3.13.0'
6963
}
7064
generateProtoTasks {
7165
all().each { task ->
72-
task.plugins {
73-
javalite { }
66+
task.builtins {
67+
java {
68+
option "lite"
69+
}
7470
}
7571
}
7672
}
7773
}
7874

7975
dependencies {
80-
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
81-
implementation 'androidx.appcompat:appcompat:1.0.0'
82-
api 'androidx.core:core:1.0.1'
76+
implementation 'com.google.protobuf:protobuf-javalite:3.11.0'
77+
implementation 'androidx.core:core:1.2.0'
8378
}

android/src/main/java/com/pauldemarco/flutter_blue/FlutterBluePlugin.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
/** FlutterBluePlugin */
6464
public class FlutterBluePlugin implements FlutterPlugin, ActivityAware, MethodCallHandler, RequestPermissionsResultListener {
6565
private static final String TAG = "FlutterBluePlugin";
66-
private static FlutterBluePlugin instance;
6766
private Object initializationLock = new Object();
6867
private Context context;
6968
private MethodChannel channel;
@@ -91,9 +90,7 @@ public class FlutterBluePlugin implements FlutterPlugin, ActivityAware, MethodCa
9190

9291
/** Plugin registration. */
9392
public static void registerWith(Registrar registrar) {
94-
if (instance == null) {
95-
instance = new FlutterBluePlugin();
96-
}
93+
FlutterBluePlugin instance = new FlutterBluePlugin();
9794
Activity activity = registrar.activity();
9895
Application application = null;
9996
if (registrar.context() != null) {
@@ -151,6 +148,7 @@ private void setup(
151148
Log.i(TAG, "setup");
152149
this.activity = activity;
153150
this.application = application;
151+
this.context = application;
154152
channel = new MethodChannel(messenger, NAMESPACE + "/methods");
155153
channel.setMethodCallHandler(this);
156154
stateChannel = new EventChannel(messenger, NAMESPACE + "/state");
@@ -240,10 +238,10 @@ public void onMethodCall(MethodCall call, Result result) {
240238

241239
case "startScan":
242240
{
243-
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION)
241+
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
244242
!= PackageManager.PERMISSION_GRANTED) {
245243
ActivityCompat.requestPermissions(
246-
activity,
244+
activityBinding.getActivity(),
247245
new String[] {
248246
Manifest.permission.ACCESS_FINE_LOCATION
249247
},
@@ -308,9 +306,9 @@ public void onMethodCall(MethodCall call, Result result) {
308306
// New request, connect and add gattServer to Map
309307
BluetoothGatt gattServer;
310308
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
311-
gattServer = device.connectGatt(activity, options.getAndroidAutoConnect(), mGattCallback, BluetoothDevice.TRANSPORT_LE);
309+
gattServer = device.connectGatt(context, options.getAndroidAutoConnect(), mGattCallback, BluetoothDevice.TRANSPORT_LE);
312310
} else {
313-
gattServer = device.connectGatt(activity, options.getAndroidAutoConnect(), mGattCallback);
311+
gattServer = device.connectGatt(context, options.getAndroidAutoConnect(), mGattCallback);
314312
}
315313
mDevices.put(deviceId, new BluetoothDeviceCache(gattServer));
316314
result.success(null);
@@ -728,13 +726,13 @@ public void onReceive(Context context, Intent intent) {
728726
public void onListen(Object o, EventChannel.EventSink eventSink) {
729727
sink = eventSink;
730728
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
731-
activity.registerReceiver(mReceiver, filter);
729+
context.registerReceiver(mReceiver, filter);
732730
}
733731

734732
@Override
735733
public void onCancel(Object o) {
736734
sink = null;
737-
activity.unregisterReceiver(mReceiver);
735+
context.unregisterReceiver(mReceiver);
738736
}
739737
};
740738

0 commit comments

Comments
 (0)