简体   繁体   中英

Qt Android app crashes with “Unable to start activity GrantPermissionsActivity”

I am developing an Android app with Qt. It has built and run successfully before under Android. Now after some code changes (adding a camera view, mostly), the same build process leads to these symptoms:

  • With the exact same code, the application builds and runs fine as a desktop application.

  • The application builds and installs under Android, but at application startup it shows a dialog "Unfortunately, Package installer has stopped" and closes.

  • The crash at application startup is accompanied by the following log messages seen in the adb logcat output (abbreviated for clarity):

I ActivityManager: START u0 {
    act=android.content.pm.action.REQUEST_PERMISSIONS 
    pkg=com.google.android.packageinstaller 
    cmp=com.google.android.packageinstaller/
      com.android.packageinstaller.permission.ui.GrantPermissionsActivity 
      (has extras)
  } from uid 10178 on display 0
I ActivityManager: Start proc 21696:com.google.android.packageinstaller/u0a27 
  for activity com.google.android.packageinstaller/
  com.android.packageinstaller.permission.ui.GrantPermissionsActivity
W System: ClassLoader referenced unknown path: 
  /system/priv-app/GooglePackageInstaller/lib/arm
D AndroidRuntime: Shutting down VM
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.google.android.packageinstaller, PID: 21696
E AndroidRuntime: java.lang.RuntimeException: 
  Unable to start activity ComponentInfo{
    com.google.android.packageinstaller/
    com.android.packageinstaller.permission.ui.GrantPermissionsActivity
  }: java.lang.NullPointerException: Attempt to get length of null array
E AndroidRuntime: 
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
  [...]
E AndroidRuntime: Caused by: 
  java.lang.NullPointerException: Attempt to get length of null array
E AndroidRuntime: 
  at com.android.packageinstaller.permission.ui.GrantPermissionsActivity.
  computePermissionGrantState(GrantPermissionsActivity.java:293)
  [...]
W ActivityManager: Force finishing activity com.google.android.packageinstaller/
  com.android.packageinstaller.permission.ui.GrantPermissionsActivity

Where to look for fixing this?

These exact symptoms happens when any Android app does not declare one or more app permissions that it needs to run.

As long as an app does not need any special permission, it will run under Android without declaring any permission. But when adding code that requires an additional permission (such as accessing the camera) and not declaring that permission in the AndroidManifest.xml file, then it will crash at startup with the symptoms shown.

As you're using Qt for Android development, you can let Qt generate the correct permission list for you as follows: make sure that AndroidManifest.xml contains the string <!-- %%INSERT_PERMISSIONS --> just inside the <manifest> tag:

<?xml version="1.0"?>
<manifest ... >
    <!-- ...more code... -->

    <!-- %%INSERT_PERMISSIONS -->

    <!-- ...more code... -->
</manifest>

Now, androiddeployqt will derive the permissions from the application's Qt library dependencies an insert them in that place while building the Android APK file. Alternatively you could also put the list of permissions into the same place manually, and omit the <!-- %%INSERT_PERMISSIONS --> .

Other causes are not likely. Especially, the fact that you're seeing this error at all proves that your custom AndroidManifest.xml is already in use – because if not, Qt's template for AndroidManifest.xml would be used, which already contains the <!-- %%INSERT_PERMISSIONS --> (see ${QT_BASE_DIR}/${QT_VARIANT_DIR}/src/android/templates/ ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM