SecurityException during app:installDebug Task while attempting to run react-native app on MI MAX 2 android device

AndroidReact NativeGradle

Android Problem Overview


Running npx react-native run-android is working on the android emulator, and also on a Samsung device I have. But when connecting a MI MAX 2 device, I get the following:

> Task :app:installDebug
Installing APK 'app-debug.apk' on 'MI MAX 2 - 7.1.1' for app:debug

> Task :app:installDebug FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
847 actionable tasks: 2 executed, 845 up-to-date
Unable to install /Users/[....]/android/app/build/outputs/apk/debug/app-debug.apk
com.android.ddmlib.InstallException: Unknown failure: Error: java.lang.SecurityException: You need the android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS permission to use the PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS flag
        at com.android.ddmlib.internal.DeviceImpl.installRemotePackage(DeviceImpl.java:1224)
        at com.android.ddmlib.internal.DeviceImpl.installPackage(DeviceImpl.java:1050)
        at com.android.ddmlib.internal.DeviceImpl.installPackage(DeviceImpl.java:1026)
        at com.android.ddmlib.internal.DeviceImpl.installPackage(DeviceImpl.java:1015)
        at ... etc, etc, etc

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> java.util.concurrent.ExecutionException: com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Unknown failure: Error: java.lang.SecurityException: You need the android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS permission to use the PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS flag

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 30s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=4105
Unable to install /Users/[....]/android/app/build/outputs/apk/debug/app-debug.apk

Note: I tried adding the following to my AndroidManifest.xml but it didn't appear to make a difference:

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

Any ideas?

Android Solutions


Solution 1 - Android

Ensure that all three

  1. Developer Options -> USB debugging
  2. Developer Options -> USB debugging (Security settings)
  3. Developer Options -> Install via USB

are turned on

Solution 2 - Android

I could fix it on a MI POCO F2 Pro enabling Developer Options -> USB debugging (Security settings) option.

Solution 3 - Android

On my Xiaomi Redmi Note 7, I had to turn on another option which is called "USB Debugging (Security Settings)".

It's located not far below the "USB Debugging" option.

Solution 4 - Android

Enable the USB debugging (Security settings) from developer option. It will ask you to insert SIM card if the phone doesn't have a SIM inserted.

Solution 5 - Android

The problem came for me after I removed the SIM card from my MI device. I can't accept the USB debugging (Security settings) anymore since that..

Solution 6 - Android

Solution: I have tried this , I had my Sim inserted and Developer Options -> USB debugging (Security settings) and USB Debugging- Both Turned ON but in my device i was still facing the same issue then i activated : Install Via USB - Turned ON. Now Its working fine i guess my REDMI device had this additional option other phone might not have.

This webpage has all related capabilities for running Appium : http://appium.io/docs/en/writing-running-appium/caps/index.html In my capabilities section i also added 2 new capabilities for Actual device and imported a library saying:

import io.appium.java_client.android.appmanagement.*;
    DesiredCapabilities cap= new DesiredCapabilities();
    cap.setCapability("autoGrantPermissions", "true");
    cap.setCapability("enforceAppInstall", "true");

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaniel LoitertonView Question on Stackoverflow
Solution 1 - AndroidMuhammed Yasir MTView Answer on Stackoverflow
Solution 2 - AndroidLeo2705View Answer on Stackoverflow
Solution 3 - AndroidAnthonyView Answer on Stackoverflow
Solution 4 - AndroidKiran AntonyView Answer on Stackoverflow
Solution 5 - AndroidMade in MoonView Answer on Stackoverflow
Solution 6 - AndroidAvishek DharView Answer on Stackoverflow