How does android reference @ hide (hidden) classes, methods, and constants?

Source: Internet
Author: User

How does android reference @ hide (hidden) classes, methods, and constants?

Recently, when processing SD card read/write issues, when the local Elipse program that can run is submitted to the server, an error is reported, the import class cannot be found, and some methods cannot be found, I searched the source code using sourceInsight and found that all classes and Methods marked with @ hide are used.

 

/** * Description of a storage volume and its capabilities, including the * filesystem path where it may be mounted. * * @hide */public class StorageVolume implements Parcelable {

First, explain why this mark appears in the android source code. @ Hide drops some classes and methods because these classes are under development or are unstable, you may not be able to find these classes or methods after the next SDK update. At this time, the stability and compatibility of the program will be very high.

 

When we need to use these methods in our program to implement our functions, we can implement them in three ways.

1. Remove the @ hide tag and replace the re-compiled android. jar package;

However, it is strongly recommended that you do not do this. The classes or methods hidden by others are definitely not safe. If you release @ hide, some unexpected program errors may occur.

 

 

2. Use the reflection mechanism to use the @ hide method. This method is good and easy to understand on the Internet. You need to search for it on the Internet.

Www.bkjia.com

 

 

3. Modify system files

3.1 modify the android. mk File

LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE_TAGS := optionalLOCAL_STATIC_JAVA_LIBRARIES := android-support-v13LOCAL_STATIC_JAVA_LIBRARIES += android-ex-camera2-portabilityLOCAL_STATIC_JAVA_LIBRARIES += xmp_toolkitLOCAL_STATIC_JAVA_LIBRARIES += glideLOCAL_SRC_FILES := $(call all-java-files-under, src)LOCAL_SRC_FILES += $(call all-java-files-under, src_pd)LOCAL_SRC_FILES += $(call all-java-files-under, src_pd_gcam)LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/res $(LOCAL_PATH)/res_pinclude $(LOCAL_PATH)/version.mkLOCAL_AAPT_FLAGS :=         --auto-add-overlay         --version-name $(version_name_package)         --version-code $(version_code_package) LOCAL_PACKAGE_NAME := Camera2#LOCAL_SDK_VERSION := currentLOCAL_CERTIFICATE := platformLOCAL_PROGUARD_FLAG_FILES := proguard.flagsLOCAL_PROGUARD_ENABLED := disabledLOCAL_JNI_SHARED_LIBRARIES := libjni_tinyplanet libjni_jpegutilinclude $(BUILD_PACKAGE)include $(call all-makefiles-under, $(LOCAL_PATH))
Comment out the red ones. LOCAL_SDK_VERSION is used to specify the SDK version required by the APK project. current represents the current android source code version. If commented out, the application can access the @ hide api.

 

3.2 comment out LOCAL_SDK_VERSION and mention that a code obfuscation error occurs during server compilation. In this case, add LOCAL_PROGUARD_ENABLED: = disabled in the android. mk file. LOCAL_PROGUARD_ENABLED: = disabled does not use code obfuscation tools for code obfuscation. If this parameter is not set, LOCAL_PROGUARD_ENABLED: = full is used by default. All project code will be obfuscated.

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.