Android App is compatible with 10.0 System

Beijing time on March 14, 2019 Google officially released Android Q Beta 1 and Preview SDK, which means that Android developers was about to usher in a new version of the annual adaptation work. Android Q for developers who bring many new features, such as folding overlay screen enhanced items, a new network connection API, new media decoder, camera, new features, NNAPI expansion, Vulkan 1.1 graphics support  and so on.

1. Add rights

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"/> 
<uses-permission android:name="android.permission.CAMERA" />         
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
 

2. Modify the compiled version and the target version

compileSdkVersion 29 (28+)

targetSdkVersion 29(28+)

 

3. Select permission problems album picture

Add the next label application

android:requestLegacyExternalStorage =“true”

4. Get folder path

String savePAth = Environment.getExternalStorageDirectory() + “/DownFile/”;

The above method to be replaced following the acquisition will otherwise fail
String savePAth = getExternalCacheDir () + " / DownFile /";

 

5. Android Q behavior change: all applications

The official part of these documents independent of changes in behavior Q: all applications to introduce, because this is part of a large and important, the largest of which is to update users' privacy rights change. Specific permission to change is as follows:

Competence Affected applications How to enable (sphere of influence)
Storage rights Application access and shared external storage device files adb shell sm set-isolated-storage on (described below)
Positioning rights Application access user location information request in the background This permission policy on the Android Q is always enabled
Activity started from the background It does not require user interaction to start the application of Activity Close allows the system to perform background activity options to enable developers to limit
Device identifier (deviceId) Access equipment serial number or IMEI applications Application of the device mounted on the mounting Android Q
Wireless Scan Privileges WLAN API application using Bluetooth API and the With Android Q for the target platform

Fewer changes affect the start Activity permissions and wireless scanning permission from the background two permissions, this article describes do not, you can view the details, please refer to the official document: https: //developer.android.com/preview/privacy/background-activity- starts
start Activity permission from the background changes only for no interaction with the user on the situation to start an Activity, (such as micro-channel landing authorization).

This article will focus on storage rights, permissions and change and adaptation positioning device identifier three permission.

1. Change of user storage rights

Android Q in the external storage device provides a "sandbox isolated storage" (e.g., / sdcard) for each application. Any other application can not directly access the sandbox file your application. Since the file is a private file your application, so you do not need any permissions to access and save their files in an external storage device. This change will make it easier to ensure the privacy of user files, and helps reduce the number of permissions required by the application.
Google officially recommended application file is stored in the address sandbox for the Context.getExternalFilesDir()files in the folder. For example, to store a picture should be placed Context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)in.

Address of the target file the following will describe how to access adaptation:

  1. Access your files: Q with more granular media specific permission replaced and canceled  READ_EXTERNAL_STORAGEand  WRITE_EXTERNAL_STORAGEauthority, and does not need specific permission, applications can access their own files in the sandbox.

  2. Access to the system media files: Q introduces a new definition of a shared set of media files, if you want to access the media sharing files outside the sandbox, such as photos, music, videos, etc., need to apply for a new media rights: READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, READ_MEDIA_AUDIO, to apply the same the original store permissions.

  3. Download the file system access: access to the download folder system, temporary restrictions do not, however, access to which files in other applications, the system must allow users to use the file chooser to select the application file.

  4. Access other applications sandboxed file: If your application needs to use a file created in other applications in the sandbox, click on the file using other applications, this article does not describe.

So please judge when the application is running on the Q platform, cancel the application of the two READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions. And replaced with a new media-specific permissions.

When each of the following conditions are satisfied, the open compatible mode, i.e. not open the storage device changes the permissions Q:

  1. Application targetSDK <= P.
  2. Application installed on Android P to upgrade from Android Q devices.

When applied to reinstall (update), will not re-open the compatibility mode, store permissions changes will take effect.
Therefore, according to the official document said, regardless of whether targetSDK Q, must apply for permission to change the storage adapter.
In the test, when targetSDK <= P, two applications on the old right Q Beat1 Edition automatically changed to apply three new rights, the application does not affect the normal use, but when targetSDK == Q, the application will fail old right and affect the normal use of applications.

2. The authority to change the positioning of users

To give users more control over application access to location information, Android Q introduces the new location permissions  ACCESS_BACKGROUND_LOCATION.

Existing  ACCESS_FINE_LOCATIONand  ACCESS_COARSE_LOCATIONpermissions, the new permissions will only affect access to the location information of the applications running in the background. Activity application unless a visible or application is running front desk, otherwise the application will be considered in the background.

Like with iOS system, Q also added background location authority ACCESS_BACKGROUND_LOCATION, if the application is also required to obtain user location (such as drops) in the background, you need to dynamically apply ACCESS_BACKGROUND_LOCATIONaccess.

Of course, if it is not needed, the application without any changes, and Google will make a different treatment in accordance with the application of targetSDK:
targetSDK <= P application if the request ACCESS_FINE_LOCATIONor  ACCESS_COARSE_LOCATIONpermission, Q device will automatically help you apply for ACCESS_BACKGROUND_LOCATIONpermission.

3. Change the unique identifier of the device

Starting Android Q, the application must have a  READ_PRIVILEGED_PHONE_STATEnon-resettable identifier (IMEI and serial number included) Signed permission to access the device.
If your application without this permission, but you still try to query identifier information, it will return a null value or an error.
Device unique identifier needs special attention, the original READ_PHONE_STATEauthority has been unable to obtain IMEI and serial.

To obtain the device by using the following code on the device ID Q

((TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId()
  • 1

The above code is executed to return a null value (targetSDK <= P) or error (targetSDK == Q). And the official said READ_PRIVILEGED_PHONE_STATEpermission is only available to system app, so this method not work.

Google official gave a device unique ID best practices, but this method given variable ID, can be resolved in accordance with the specific needs of specific. This article gives a substantially constant and repeatable method UUID:

public static String getUUID() {
    String serial = null;
    String m_szDevIDShort = "35" +
        Build.BOARD.length() % 10 + Build.BRAND.length() % 10 +
        Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 +
        Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 +
        Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 +
        Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 +
        Build.TAGS.length() % 10 + Build.TYPE.length() % 10 +
        Build.USER.length() % 10; //13 位

    try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                serial = android.os.Build.getSerial();
            } else {
                serial = Build.SERIAL;
            }
            //API>=9 使用serial号
            return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
        } catch (Exception exception) {
            //serial需要一个初始化
            serial = "serial"; // 随便一个初始化
      }
    //使用硬件信息拼凑出来的15位号码
    return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
}

Although the change will lead to a unique identifier authority android.os.Build.getSerial () returns unknown, but because the fight is m_szDevIDShort hardware information out, so still ensure the uniqueness and durability UUID.
Test output results are as follows
Here Insert Picture Description

The above method has been tested in exactly the same when it may be repeated, online as well as other programs such as androidID, but androidID may return null models due reasons, so much to choose between two ways to think. Get a version of the device ID is tougher than a version, if there is a good method welcome that.

4. About minSDK warning

In Android Q, when a user first runs with Android 6.0 (API level 23) the following versions for any application target platform, Android platform will issue a warning to the user.

If the application requires the user to grant permission, the system will first provide users with the opportunity to adjust the application permission before allowing this application is first run.


6. Android Q behavior change: The Android Q for the target platform applications

Non-limiting Interface SDK

Non-limiting interface SDK been proposed in the Android P, Q, however, the interface is restricted to large changes classification.

Introduction of non-Interface SDK

In order to ensure the stability and application compatibility, Android platform began to limit your application can use the interface in which non-SDK in Android 9 (API level 28). Non-restricted SDK interface list includes the updated Android Q (based on internal testing and the latest collaboration between developers and Android).
Non-limiting interface SDK is some private method in the SDK, such as private methods, you obtain call by the Java reflection and the like, then the call will target> = P or target> = Q is limited to use on the device, when you use these methods, we will complain

Acquisition method Error Messages
Dalvik instruction referencing a field NoSuchFieldError thrown
Dalvik instruction referencing a method NoSuchMethodError thrown
Reflection via Class.getDeclaredField() or Class.getField() NoSuchFieldException thrown
Reflection via Class.getDeclaredMethod(), Class.getMethod() NoSuchMethodException thrown
Reflection via Class.getDeclaredFields(), Class.getFields() Non-SDK members not in results
Reflection via Class.getDeclaredMethods(), Class.getMethods() Non-SDK members not in results
JNI via env->GetFieldID() NULL returned,NoSuchFieldError thrown
JNI via env->GetMethodID() NULL returned,NoSuchMethodError thrown

Find a non-Interface SDK

If you are unsure whether your application uses a non-SDK interface, you can test the application to confirm. When you call a non-SDK interface will be similar Accessing hidden XXX log:

Accessing hidden field Landroid/os/Message;->flags:I (light greylist, JNI)
  • 1

But in the end a big project where the use of these methods rely on the code and review the log to see is certainly not realistic, Google official also provided official inspector veridex used to detect a apk where the use of non-SDK interface. veridex Download: https://android.googlesource.com/platform/prebuilts/runtime/+/master/appcompat
including windows, linux and mac version, the corresponding download. Must extract to the line cd veridex directory using ./appcompat.sh --dex-file = Q.apk automatically scan. Q.apk absolute path for the package, if the package and the package veridex input file name directly in the same directory. Scan results divided into two parts, part of the non-call interfaces SDK position, another portion of the number of non-SDK interface statistics.

Non-SDK interface adapter

If your application relies on non-SDK interface, you should start planning to migrate to alternative SDK. If you can not find an alternative to using non-SDK interface is a function of the application, you should request a new public API.

Official requirements targetSDK> = P application does not use these methods, and to look for other alternatives to these non-public API SDK interfaces, if not, you can apply to Google, request a new public API: https: // developer. android.com/distribute/best-practices/develop/restrictions-non-sdk-interfaces#feature-request

There are two projects using non-SDK interface to a high probability:

  1. Custom View in the process used for convenience to modify a parameter reflecting.
  2. In the use of non-party SDK SDK interfaces (such cases more).

The first is a good solution, after all, is to write our own code. The second headache, only to update to the latest version of the tripartite SDK, or mention the work order, through the bank (also the largest part of the whole process of adaptation work).


7. Android upgrade project encountered problems

Simulator X86, SO project library v7

  • Find so library source code, compiled into x86
  • If so the library just to use a feature point, no major overall impact APP on, so you can block specific library functions or skip test
  • If so the library is the core library project must be loaded, can also be measured using Tencent cloud, there is Google own son Q version of the above. Tencent cloud measurements have adb connect remote debugging capabilities (I have not succeeded). adb Rom does not matter, is directly installed on the line, the cloud may be measured directly look at the log.
  • As I tried houdini inter studied, so theoretically it can be installed in the library compiled v7 x86 emulator, but due to the relatively small introduction to houdini also older, we proposed time is not sufficient, then do not study.

Requires development platform Q but this is a release platform.

Q is due to the current preview version, so targetSDK == Q application can only run on Q device.

INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2

This error is due to compression so the library packaged caused by specific reasons seen: https: //issuetracker.google.com/issues/37045367
join in the application of AndroidManifest.xml node android:extractNativeLibs="true"
may have been added above the code or not, in app / defaultConfig node is added under build.gradle

packagingOptions{ 
      doNotStrip "/armeabi/.so" doNotStrip "/armeabi-v7a/.so" doNotStrip "/x86/.so" }
  • 1
  • 2

Didn’t find class “org.apache.http.client.methods.HttpPost"

Was added at the application node AndroidManifest.xml

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

If your project does not fit through the android O or P, then you need to pay attention

android O read an installed application permissions (automatically updated influential within the application)
the default android P prohibit access to the API http

 

 

Documents in this article:

Android Q Beta Developer Documentation link :: https://developer.android.com/preview

Android Q Beta mirror Download Link: https://developer.android.com/preview/download

Android Q Beta 发布 blog:https://android-developers.googleblog.com/2019/03/introducing-android-q-beta.html

Non-SDK Interface: https://juejin.im/post/5afe50eef265da0b70262463
 

Published 39 original articles · won praise 19 · views 60000 +

Guess you like

Origin blog.csdn.net/u010090644/article/details/105226196