Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 12+ - README if you get a crash or attempt to use the fork. #185

Open
andrewcharnley opened this issue Jul 5, 2023 · 2 comments

Comments

@andrewcharnley
Copy link

andrewcharnley commented Jul 5, 2023

Hi all,

After many hours....

  1. the fork enables jetifier, and I got argument mismatch on the function call that I couldn't resolve. I made the modifications to support v31 and Androidx manually to the non-fork code.

  2. the no.nordic.dfu library hard crashes unless you get permissions spot on. I think they have them incorrect in the manifest, or the ble lib you're using does. The best approach is to completely ignore every sodding bluetooth permission in all the sodding manifests and force your own in the master manifest. After much trial and error these are great for my use case (ble only, no location).

Finally DFU is working again!

<uses-permission android:name="android.permission.INTERNET" />

    <!--
      HACK: this permission should not be needed on android 12+ devices anymore,
      but in fact some manufacturers still need it for BLE to properly work : 
      https://stackoverflow.com/a/72370969
    -->
    <uses-permission android:name="android.permission.BLUETOOTH" android:usesPermissionFlags="neverForLocation" android:maxSdkVersion="31" tools:replace="android:maxSdkVersion" tools:remove="android:minSdkVersion" />
    <!--
      should normally only be needed on android < 12 if you want to:
      - activate bluetooth programmatically
      - discover local BLE devices
      see: https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#discover-local-devices.
      Same as above, may still be wrongly needed by some manufacturers on android 12+.
     -->
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:usesPermissionFlags="neverForLocation" android:maxSdkVersion="30" tools:replace="android:maxSdkVersion" tools:remove="android:minSdkVersion" />

    <!-- Android 9 (API28) and below require course location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="28" tools:replace="android:maxSdkVersion" tools:remove="android:minSdkVersion" />
    <!-- Android 10 and 11 (API29,30) require fine location -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:minSdkVersion="29" android:maxSdkVersion="30" tools:replace="android:maxSdkVersion,android:minSdkVersion" />

    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" tools:remove="android:maxSdkVersion,android:minSdkVersion" />

    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" android:usesPermissionFlags="neverForLocation" tools:remove="android:maxSdkVersion,android:minSdkVersion" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" tools:remove="android:maxSdkVersion,android:minSdkVersion" />

    <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

...

And then you need all the runtime permissions as well...

      const permissions = [
        PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
        PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT
      ];
      // shouldn't be needed on 31 but some manufacturers still require
      if (Platform.Version <= 31) {
        permissions.push(PermissionsAndroid.PERMISSIONS.BLUETOOTH);
      }
      if (Platform.Version <= 30) {
        permissions.push(PermissionsAndroid.PERMISSIONS.BLUETOOTH_ADMIN);
      }
      if (Platform.Version <= 28) {
        permissions.push(PermissionsAndroid.PERMISSIONS.ACCESS_COURSE_LOCATION);
      } else if ([29.30].includes(Platform.Version)) {
        permissions.push(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION);
      }
      await PermissionsAndroid.requestMultiple(permissions);
    }
@andrewcharnley andrewcharnley changed the title Android 12+ - README if you get a crash, or try the fork. Android 12+ - README if you get a crash or attempt to use the fork. Jul 5, 2023
@manualexSP
Copy link

@andrewcharnley Hi, I'm from the README fork, I just created an new example based on a new react-native project. And is included in the setup as well. Let me know if I can add anything in there :D

@andrewcharnley
Copy link
Author

Just remove the useJetifier argument I think, this rewrote the function and I got argument mismatch error - it took me all day to work it out! It may not be obvious until you clear metro cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants