Adapt mPaaS for targetSdkVersion 28

更新时间:
复制 MD 格式

Starting from version 10.1.68.21, mPaaS supports targetSdkVersion 28. Upgrade the SDK and follow this guide to adapt your code and verify affected components.

Older mPaaS baselines support targetSdkVersion up to 26. Starting from version 10.1.68.21, mPaaS supports targetSdkVersion 28. To upgrade, use the mPaaS plugin to update the SDK to version 10.1.68.21 or later, then follow this guide to adapt your code and perform regression testing.

Adapt for targetSdkVersion 28

Modify targetSdkVersion

AAR integration method

In the build.gradle file of the project's main module, change the `targetSdkVersion` property to 28.

Portal & Bundle integration method

  • In the build.gradle file of the Portal project's main module, change the `targetSdkVersion` property to 28.

  • The `targetSdkVersion` in the Bundle project does not need to be changed, but it must not be higher than the `targetSdkVersion` of the Portal project.

General configurations

AAR integration method

In the project's AndroidManifest.xml file, add the following code under the `application` node:

<uses-library android:name="org.apache.http.legacy" android:required="false"/>

Portal & Bundle integration method

In the Portal project's AndroidManifest.xml file, make the following changes:

  • Add the following code under the `application` node:

    <uses-library android:name="org.apache.http.legacy" android:required="false"/>
  • Remove the following property from `LauncherActivity`. The SDK now sets this property programmatically.

    android:screenOrientation="portrait"

Other configurations

Allow HTTP requests

Android 9.0 and later allow only HTTPS requests by default. Setting targetSdkVersion to 28 enforces this restriction on devices running Android 9.0 or later. To allow HTTP requests, including those in miniapps, configure networkSecurityConfig.

  • In the res/xml directory of your project, create a network_security_config.xml file with the following content. For the Portal & Bundle integration method, create this file in the Portal project.

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
      <base-config cleartextTrafficPermitted="true">
          <trust-anchors>
              <certificates src="system" />
          </trust-anchors>
      </base-config>
    </network-security-config>
  • In your project's AndroidManifest.xml file, add the following property to the `application` node. For the Portal & Bundle integration method, modify the file in the Portal project.

    android:networkSecurityConfig="@xml/network_security_config"

For more information, see the official Google documentation.

Crash when setting screen orientation for an activity with a transparent background

Android 8.0 has a system bug: an app crashes if its targetSdkVersion is higher than 26 and it opens an activity that has both a transparent background and a fixed screen orientation. The crash is triggered when both of the following conditions are met:

  • The windowIsTranslucent or windowIsFloating attribute in the Activity theme is set to true.

  • The screenOrientation attribute is set in AndroidManifest.xml, or the setRequestedOrientation method is called.

Check all activities for these conditions. Some common system themes also meet the criteria, such as:

@android:style/Theme.Translucent.NoTitleBar
@android:style/Theme.Dialog

Recommended solution:

  1. For the Activity whose theme meets the condition, delete the screenOrientation attribute in AndroidManifest.xml and call the setRequestedOrientation method instead.

  2. Override the setRequestedOrientation method in the corresponding Activity or parent class, with try catch super.setRequestedOrientation() as the ground rule:

     @Override
     public void setRequestedOrientation(int requestedOrientation) {
         try {
             super.setRequestedOrientation(requestedOrientation);
         } catch (Exception ignore) {
    
         }
     }
  3. The mPaaS classes BaseActivity, BaseFragmentActivity, and BaseAppCompatActivtiy already override setRequestedOrientation with this try-catch approach.

  4. This workaround prevents the crash. However, the screen orientation lock may still fail on Android 8.0 devices. Ensure your Activity does not cause exceptions when the screen rotates, such as a lifecycle restart that results in null member variables.

Related Android 8.0 system source code:

android 8.0 bug

Regression testing

Regression testing must include devices running Android 9.0 or later. For the transparent activity crash issue, also test on Android 8.0 devices.

If you use any of the following components, pay close attention to the listed features during regression testing:

Component

Validation items

Mobile Gateway

Hotpatching

Check if hotpatching takes effect.

Scan

  • Check if scanning with the standard UI is successful.

  • Check if opening the phone's photo album, taking photos, and previewing them works correctly with the standard UI.

  • Check if scanning with a custom UI is successful. If you use a custom UI, you must adapt to some new interfaces.

Unified Storage

Share

Check if sharing to Sina Weibo and QQ is successful.