All Products
Search
Document Center

Adapt to targetsdkversion 28

Last Updated: Jun 01, 2021

Background

The mPaaS standard baseline only supports up to 26 for targetSdkVersion. If your app needs to upgrade targetSdkVersion to 28, please use custom baseline 10.1.68a and update the SDK and add configuration according to the following description and return to the relevant function.

Note: Baseline 10.1.68a has been tested but is still in beta phase, so please use with caution.

Update SDK

Update the SDK and related configuration with reference to mPaaS supports for multi-CPU architecture.

Adapt targetSdkVersion 28

Modify targetSdkVersion

Inside/AAR

Modify the attribute targetSdkVersion 28 in the build.gradle file under the main module of the project.

Portal&Bundle

  • Modify the attribute targetSdkVersion 28 in the build.gradle file under the main module of the Portal project.
  • The targetSdkVersion in the Bundle project may be left unchanged, but may not be later than that of the Portal project.

Universal configurations

Inside/AAR

Modify the project AndroidManifest.xml and add the following codes under the application node:

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

Portal&Bundle

Modify the Portal project AndroidManifest.xml:

  • Add the following codes under the application node:
       
    1. <uses-library android:name="org.apache.http.legacy" android:required="false"/>
  • Note that SDK has been changed to set through code. You need to remove the following attributes from the LauncherActivity:
       
    1. android:screenOrientation="portrait"

Other configurations

Allow HTTP requests

By default, the Android 9.0 network configuration disables HTTP requests and only allows HTTPS requests. Set targetSdkVersion 28 to enable the 9.0 network configuration on 9.0+ devices. If you still need to send HTTP requests, including in mini programs, you can enable it by configuring networkSecurityConfig.

  • Note that Portal & Bundle is a Portal project. Create a network_security_config.xml file under the res/xml directory of the project with the following contents:
       
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <network-security-config>
    3. <base-config cleartextTrafficPermitted="true">
    4. <trust-anchors>
    5. <certificates src="system" />
    6. </trust-anchors>
    7. </base-config>
    8. </network-security-config>
  • Note that Portal & Bundle is a Portal project. Add the following attributes to the application node in AndroidManifest.xml of the project:
       
    1. android:networkSecurityConfig="@xml/network_security_config"
    For more information about the configuration, please refer to the Official google documentation.

Crash occurs when setting screen orientation with transparent background Activity

This adaptation point is an Android 8.0 bug. On Android 8.0 devices, when the application targetSdkVersion > 26, opening an Activity with a transparent background will trigger a crash if the screen orientation is set. The specific trigger conditions are:

  • The attribute of windowIsTranslucent or windowIsFloating of the theme used by the Activity is true.
  • The screenOrientation attribute is set in AndroidManifest.xml, or the setRequestedOrientation method is called.

You need to check if all Activities meet the trigger conditions, and note that in addition to your custom style, some common system themes also meet the conditions, for example:

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

Recommended adaptation:

  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:

       
    1. @Override
    2. public void setRequestedOrientation(int requestedOrientation) {
    3. try {
    4. super.setRequestedOrientation(requestedOrientation);
    5. } catch (Exception ignore) {
    6. }
    7. }
  3. BaseActivity, BaseFragmentActivity, andBaseAppCompatActivtiy provided by mPaaS were overwritten, with setRequestedOrientation method as the ground rule.

  4. Make sure that your Activity does not have any exceptions due to screen rotation as this may prevent crashes but may still cause lock orientation to fail on Android 8.0 devices. For example, re-running the lifecycle will result in some member variables being empty.

Source code related to Android 8.0 system:

Android 8.0 bug

Regression test

The full regression test must include Android 9.0+ devices. For crash issue in Activity setting screen orientation against the transparent background, make specific tests on Android 8.0 models.

For regression test, you need to focus on the following component functions, if used:

Components Validation project
Mobile gateway - Whether the RPC call succeeds after enabling Signature validation.
- Whether the RPC call succeeds after enabling Data encryption.
Hotfix
- Whether Hotfix is in effect.
UC kernel - After HTML5 container uses UC kernel, whether the functions are normal or not.
- Whether Mini program, which must use UC kernel, functions well.
- Whether Mini program opening phone album, photo and preview functions well.
- Whether Mini program launches HTTP request is successful or not, if HTTP is forcibly enabled.
Scan - Whether the standard UI scans the code successfully.
- Whether the standard UI opens the phone album, takes photos and previews properly.
- If the custom UI is successful, you need to adapt part of the new API.
Unified data storage - Whether Database encrypted storage functions well.
- Whether File encrypted storage functions well.
Share - Whether Share on Sina Weibo and/or QQ functions well.