Skip to content

Commit

Permalink
Use latest protobuf compiler (pauldemarco#676)
Browse files Browse the repository at this point in the history
* checkPermission fixes

* remove appcompat

* remove static instance which overrides a activity field

* Switch to new protobuf compiler
  • Loading branch information
ened authored Nov 9, 2020
1 parent f0853cb commit abdc3c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
21 changes: 8 additions & 13 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.13'
}
}

Expand Down Expand Up @@ -59,25 +59,20 @@ protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.9.1'
}
plugins {
javalite {
// The codegen for lite comes as a separate artifact
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
artifact = 'com.google.protobuf:protoc:3.13.0'
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite { }
task.builtins {
java {
option "lite"
}
}
}
}
}

dependencies {
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
implementation 'androidx.appcompat:appcompat:1.0.0'
api 'androidx.core:core:1.0.1'
implementation 'com.google.protobuf:protobuf-javalite:3.11.0'
implementation 'androidx.core:core:1.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
/** FlutterBluePlugin */
public class FlutterBluePlugin implements FlutterPlugin, ActivityAware, MethodCallHandler, RequestPermissionsResultListener {
private static final String TAG = "FlutterBluePlugin";
private static FlutterBluePlugin instance;
private Object initializationLock = new Object();
private Context context;
private MethodChannel channel;
Expand Down Expand Up @@ -91,9 +90,7 @@ public class FlutterBluePlugin implements FlutterPlugin, ActivityAware, MethodCa

/** Plugin registration. */
public static void registerWith(Registrar registrar) {
if (instance == null) {
instance = new FlutterBluePlugin();
}
FlutterBluePlugin instance = new FlutterBluePlugin();
Activity activity = registrar.activity();
Application application = null;
if (registrar.context() != null) {
Expand Down Expand Up @@ -151,6 +148,7 @@ private void setup(
Log.i(TAG, "setup");
this.activity = activity;
this.application = application;
this.context = application;
channel = new MethodChannel(messenger, NAMESPACE + "/methods");
channel.setMethodCallHandler(this);
stateChannel = new EventChannel(messenger, NAMESPACE + "/state");
Expand Down Expand Up @@ -240,10 +238,10 @@ public void onMethodCall(MethodCall call, Result result) {

case "startScan":
{
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION)
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
activity,
activityBinding.getActivity(),
new String[] {
Manifest.permission.ACCESS_FINE_LOCATION
},
Expand Down Expand Up @@ -308,9 +306,9 @@ public void onMethodCall(MethodCall call, Result result) {
// New request, connect and add gattServer to Map
BluetoothGatt gattServer;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
gattServer = device.connectGatt(activity, options.getAndroidAutoConnect(), mGattCallback, BluetoothDevice.TRANSPORT_LE);
gattServer = device.connectGatt(context, options.getAndroidAutoConnect(), mGattCallback, BluetoothDevice.TRANSPORT_LE);
} else {
gattServer = device.connectGatt(activity, options.getAndroidAutoConnect(), mGattCallback);
gattServer = device.connectGatt(context, options.getAndroidAutoConnect(), mGattCallback);
}
mDevices.put(deviceId, new BluetoothDeviceCache(gattServer));
result.success(null);
Expand Down Expand Up @@ -728,13 +726,13 @@ public void onReceive(Context context, Intent intent) {
public void onListen(Object o, EventChannel.EventSink eventSink) {
sink = eventSink;
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
activity.registerReceiver(mReceiver, filter);
context.registerReceiver(mReceiver, filter);
}

@Override
public void onCancel(Object o) {
sink = null;
activity.unregisterReceiver(mReceiver);
context.unregisterReceiver(mReceiver);
}
};

Expand Down

0 comments on commit abdc3c1

Please sign in to comment.