├── lib ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── guolei │ │ │ └── lib │ │ │ └── pcompat │ │ │ ├── PCompat.java │ │ │ └── ReflectHelper.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── guolei │ │ │ └── lib │ │ │ └── pcompat │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── guolei │ │ └── lib │ │ └── pcompat │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── lib_method_1 ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── guolei │ │ │ └── support_p_java │ │ │ └── PCompat.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── guolei │ │ │ └── support_p_java │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── guolei │ │ └── support_p_java │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── lib_method_2 ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ ├── jniLibs │ │ │ ├── x86 │ │ │ │ └── libvHook.so │ │ │ ├── armeabi │ │ │ │ └── libvHook.so │ │ │ └── armeabi-v7a │ │ │ │ └── libvHook.so │ │ ├── java │ │ │ └── com │ │ │ │ └── guolei │ │ │ │ └── support_p_native │ │ │ │ └── PCompat.java │ │ └── cpp │ │ │ ├── v_hook.h │ │ │ └── native.cpp │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── guolei │ │ │ └── support_p_native │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── guolei │ │ └── support_p_native │ │ └── ExampleInstrumentedTest.java ├── CMakeLists.txt ├── proguard-rules.pro └── build.gradle ├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── jniLibs │ │ │ ├── x86 │ │ │ │ ├── libtest2.so │ │ │ │ └── libsubstrate.so │ │ │ └── armeabi-v7a │ │ │ │ ├── libtest2.so │ │ │ │ └── libsubstrate.so │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── support_p │ │ │ │ ├── ReflectionHelper.java │ │ │ │ └── MainActivity.java │ │ └── cpp │ │ │ ├── native-lib.cpp │ │ │ └── substrate.h │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── support_p │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── support_p │ │ └── ExampleInstrumentedTest.java ├── CMakeLists.txt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── art ├── diff_main_c.png ├── toclass_符号.png ├── diff_fake_dlfcn.png ├── setclassloader_符号.png ├── create_from_artmethod.png ├── class_getdeclaredfield.png └── GetDeclaredMethodInternal.png ├── .gitmodules ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── caches │ └── build_file_checksums.ser ├── markdown-navigator │ └── profiles_settings.xml ├── vcs.xml ├── runConfigurations.xml ├── checkstyle-idea.xml ├── gradle.xml ├── misc.xml ├── codeStyles │ └── Project.xml └── markdown-navigator.xml ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.MD └── gradlew /lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /lib_method_1/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /lib_method_2/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | .externalNativeBuild/ 3 | 4 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':lib' 2 | 3 | //':lib_method_1', ':lib_method_2', 4 | -------------------------------------------------------------------------------- /art/diff_main_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/diff_main_c.png -------------------------------------------------------------------------------- /art/toclass_符号.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/toclass_符号.png -------------------------------------------------------------------------------- /lib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | lib 3 | 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Native_Hook"] 2 | path = Native_Hook 3 | url = https://github.com/Guolei1130/Native_Hook 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | support_p 3 | 4 | -------------------------------------------------------------------------------- /art/diff_fake_dlfcn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/diff_fake_dlfcn.png -------------------------------------------------------------------------------- /art/setclassloader_符号.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/setclassloader_符号.png -------------------------------------------------------------------------------- /art/create_from_artmethod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/create_from_artmethod.png -------------------------------------------------------------------------------- /lib_method_1/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | lib_method_1 3 | 4 | -------------------------------------------------------------------------------- /lib_method_2/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | lib_method_2 3 | 4 | -------------------------------------------------------------------------------- /art/class_getdeclaredfield.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/class_getdeclaredfield.png -------------------------------------------------------------------------------- /art/GetDeclaredMethodInternal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/GetDeclaredMethodInternal.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86/libtest2.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/jniLibs/x86/libtest2.so -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86/libsubstrate.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/jniLibs/x86/libsubstrate.so -------------------------------------------------------------------------------- /lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi-v7a/libtest2.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/jniLibs/armeabi-v7a/libtest2.so -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /lib_method_1/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /lib_method_2/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /lib_method_2/src/main/jniLibs/x86/libvHook.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/lib_method_2/src/main/jniLibs/x86/libvHook.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi-v7a/libsubstrate.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/jniLibs/armeabi-v7a/libsubstrate.so -------------------------------------------------------------------------------- /lib_method_2/src/main/jniLibs/armeabi/libvHook.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/lib_method_2/src/main/jniLibs/armeabi/libvHook.so -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /lib_method_2/src/main/jniLibs/armeabi-v7a/libvHook.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/lib_method_2/src/main/jniLibs/armeabi-v7a/libvHook.so -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Sep 14 14:39:11 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /lib_method_2/src/main/java/com/guolei/support_p_native/PCompat.java: -------------------------------------------------------------------------------- 1 | package com.guolei.support_p_native; 2 | 3 | /** 4 | * Created by Android Studio. 5 | * User: guolei 6 | * Email: 1120832563@qq.com 7 | * Date: 2018/10/6 8 | * Time: 2:30 PM 9 | * Desc: 10 | */ 11 | public class PCompat { 12 | 13 | static { 14 | System.loadLibrary("native_hook"); 15 | } 16 | 17 | public native void nativeHook(String fullPath); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/support_p/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.support_p; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | 14 | @Test 15 | public void addition_isCorrect() { 16 | assertEquals(4, 2 + 2); 17 | } 18 | } -------------------------------------------------------------------------------- /lib/src/test/java/com/guolei/lib/pcompat/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.guolei.lib.pcompat; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /lib_method_1/src/test/java/com/guolei/support_p_java/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.guolei.support_p_java; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /lib_method_2/src/test/java/com/guolei/support_p_native/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.guolei.support_p_native; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /lib_method_2/src/main/cpp/v_hook.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by vipkid on 2018/9/19. 3 | // 4 | 5 | #ifndef VK_HOOK_V_HOOK_H 6 | #define VK_HOOK_V_HOOK_H 7 | 8 | #include 9 | 10 | #define _extern extern "C" __attribute__((__visibility__("default"))) 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern void *v_dlopen(const char *filename, int flags); 17 | extern void *v_dlsym(void *handle, const char *symbol); 18 | extern int v_dlclose(void *handle); 19 | extern void v_hook_function(void *symbol, void *replace, void **result); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /lib_method_2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | 4 | file(GLOB cpp_source_files "src/main/cpp/*.cpp") 5 | file(GLOB c_source_files "src/main/cpp/*.c") 6 | file(GLOB h_source_files "src/main/cpp/*.hpp") 7 | 8 | add_library( # Sets the name of the library. 9 | native_hook 10 | 11 | # Sets the library as a shared library. 12 | SHARED 13 | 14 | # Provides a relative path to your source file(s). 15 | ${c_source_files} 16 | ${cpp_source_files} 17 | ${hpp_source_files} 18 | ) 19 | 20 | find_library( 21 | log-lib 22 | log ) 23 | 24 | 25 | target_link_libraries( # Specifies the target library. 26 | native_hook 27 | ${log-lib} 28 | ) -------------------------------------------------------------------------------- /app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | cmake_minimum_required(VERSION 3.4.1) 3 | set(libs_DIR src/main/jniLibs/${ANDROID_ABI}) 4 | link_directories(${libs_DIR}) 5 | 6 | add_library( # Sets the name of the library. 7 | native-lib 8 | 9 | # Sets the library as a shared library. 10 | SHARED 11 | 12 | src/main/cpp/native-lib.cpp ) 13 | 14 | target_link_libraries( # Specifies the target library. 15 | native-lib 16 | substrate 17 | test2 18 | ) 19 | 20 | find_library( # Sets the name of the path variable. 21 | log-lib 22 | log ) 23 | 24 | 25 | target_link_libraries( # Specifies the target library. 26 | native-lib 27 | ${log-lib} 28 | ) -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /lib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /lib_method_1/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /lib_method_2/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/support_p/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.support_p; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getTargetContext(); 24 | 25 | assertEquals("com.example.support_p", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib_method_1/src/main/java/com/guolei/support_p_java/PCompat.java: -------------------------------------------------------------------------------- 1 | package com.guolei.support_p_java; 2 | 3 | 4 | import android.os.Build; 5 | 6 | import java.lang.reflect.Field; 7 | 8 | /** 9 | * Author: guolei 10 | * Email: 1120832563@qq.com 11 | * Date: 2018/10/6 12 | * Time: 2:09 PM 13 | * Desc: 14 | */ 15 | public class PCompat { 16 | 17 | public static void compat(Class reflectionHelperClz) { 18 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 19 | try { 20 | Class classClz = Class.class; 21 | Field classLoaderField = classClz.getDeclaredField("classLoader"); 22 | classLoaderField.setAccessible(true); 23 | classLoaderField.set(reflectionHelperClz, null); 24 | } catch (Exception e) { 25 | e.printStackTrace(); 26 | } 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /lib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 19 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/androidTest/java/com/guolei/lib/pcompat/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.guolei.lib.pcompat; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.guolei.lib.pcompat.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib_method_1/src/androidTest/java/com/guolei/support_p_java/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.guolei.support_p_java; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.guolei.support_p_java.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib_method_2/src/androidTest/java/com/guolei/support_p_native/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.guolei.support_p_native; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.guolei.support_p_native.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib_method_1/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 19 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | 30 | implementation 'com.android.support:appcompat-v7:28.0.0' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 34 | } 35 | -------------------------------------------------------------------------------- /lib_method_2/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 19 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | externalNativeBuild { 26 | cmake { 27 | path "CMakeLists.txt" 28 | } 29 | } 30 | 31 | } 32 | 33 | dependencies { 34 | implementation fileTree(dir: 'libs', include: ['*.jar']) 35 | 36 | implementation 'com.android.support:appcompat-v7:28.0.0' 37 | testImplementation 'junit:junit:4.12' 38 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 39 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/support_p/ReflectionHelper.java: -------------------------------------------------------------------------------- 1 | package com.example.support_p; 2 | 3 | import android.util.Log; 4 | import java.lang.reflect.Field; 5 | import java.lang.reflect.Method; 6 | 7 | public class ReflectionHelper { 8 | 9 | private static final String TAG = ReflectionHelper.class.getSimpleName(); 10 | 11 | public static void testMethod() { 12 | try { 13 | Class clz = Class.forName("android.app.ActivityThread"); 14 | Method method = clz.getDeclaredMethod("getIntentBeingBroadcast"); 15 | method.setAccessible(true); 16 | method.invoke(null); 17 | Log.e(TAG, "testMethod: 反射成功"); 18 | } catch (Exception e) { 19 | e.printStackTrace(); 20 | Log.e(TAG, "testMethod: 反射失败"); 21 | } 22 | } 23 | 24 | public static void testField() { 25 | try { 26 | Class clz = Class.forName("android.app.ActivityThread"); 27 | Field field = clz.getDeclaredField("TAG"); 28 | field.setAccessible(true); 29 | field.get(null); 30 | Log.e(TAG, "testField: 反射成功"); 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | Log.e(TAG, "testField: 反射失败"); 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/src/main/java/com/guolei/lib/pcompat/PCompat.java: -------------------------------------------------------------------------------- 1 | package com.guolei.lib.pcompat; 2 | 3 | import android.os.Build; 4 | 5 | import java.lang.reflect.Field; 6 | 7 | /** 8 | * Created by Android Studio. 9 | * User: guolei 10 | * Email: 1120832563@qq.com 11 | * Date: 2019/2/17 12 | * Time: 10:25 AM 13 | * Desc: 14 | */ 15 | public class PCompat { 16 | public static void compat(Class reflectionHelperClz) { 17 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 18 | try { 19 | Class classClz = Class.class; 20 | Field classLoaderField = classClz.getDeclaredField("classLoader"); 21 | classLoaderField.setAccessible(true); 22 | classLoaderField.set(reflectionHelperClz, null); 23 | } catch (Exception e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | } 28 | 29 | public static void useDefaultReflectHelperClass() { 30 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 31 | try { 32 | Class classClz = Class.class; 33 | Field classLoaderField = classClz.getDeclaredField("classLoader"); 34 | classLoaderField.setAccessible(true); 35 | classLoaderField.set(ReflectHelper.class, null); 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 20 | 21 |