Android : Android complains about missing permission defined in library

on Tuesday, July 8, 2014


My Android project is built in Android Studio and has two main modules: an SDK and a GUI.


The GUI has a dependency on the SDK. The SDK declares the ACCESS_WIFI_STATE and CHANGE_WIFI_STATE permissions in its manifest, as well as the BLUETOOTH and BLUETOOTH_ADMIN ones. See below for the exact XML. The GUI manifest does not redeclare these permissions, but its build.gradle correctly requires the SDK module (see below).


The Bluetooth features work fine, but when I check at runtime for the ACCESS_WIFI_STATE permission, the response is false. The response is true if I add that permission to the GUI module manifest (hence declaring it twice in total).



PackageDetector.hasSystemFeature(context, Manifest.permission.ACCESS_WIFI_STATE)


I don't see why the WiFi permissions aren't recognized unless I redeclare them, and yet the Bluetooth ones are fine even if declared just in the SDK.


Various people mention this online, sometimes quite directly, and the general consensus is that because Gradle in Studio merges manifests by default, the idea of importing permissions from a library module should be fine (as I see with other permissions including INTERNET and ACCESS_COARSE_LOCATION).


What is causing this behaviour, and is it something I can fix? I would really prefer to keep the permissions in just one place, the SDK manifest.


SDK AndroidManifest.xml snippet



<!-- For wifi sensor -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>

<!-- For ble sensor -->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>


GUI module build.gradle snippet



dependencies {
...
compile project(':ExampleSdk')
...
}

0 comments:

Post a Comment