Search code examples
androidpermissions

Cannot get WAKE_LOCK permission on Android 8 Oreo


My app has <uses-permission android:name="android.permission.WAKE_LOCK" /> added to the AndroidManifest.xml. However calls to acquire the lock PowerManager.PARTIAL_WAKE_LOCK crash the app on Oreo devices.

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: java.lang.SecurityException: Neither user 10094 nor current process has android.permission.WAKE_LOCK.

Solution

  • Your app is probably using a new version of ACRA library. In the new version, they added <uses-permission android:name="android.permission.WAKE_LOCK" android:maxSdkVersion="25" /> to the library's AndroidManifest.xml file. The android:maxSdkVersion="25" is silently merged into the main app's AndroidManifest.xml file. Hence, the app doesn't have the WAKE_LOCK permission on Oreo devices. The solution is to add tools:node="replace" to your uses-permission declaration.

    For example <uses-permission android:name="android.permission.WAKE_LOCK" tools:node="replace" />.

    Update: in recent versions of the ACRA library, that unfortunate "feature" has been removed.