From 1262a975ee61fbd010d005a1d702ce46b1765641 Mon Sep 17 00:00:00 2001 From: Hu Shenghao Date: Sun, 18 Jun 2023 10:06:40 +0800 Subject: [PATCH 1/3] Support target Android U Migrate to androidx Provider lib proguard rules --- .idea/.gitignore | 11 +++++ .idea/compiler.xml | 6 +++ .idea/gradle.xml | 4 +- .idea/jarRepositories.xml | 45 ------------------- .idea/misc.xml | 2 +- .idea/modules.xml | 10 +++-- .idea/runConfigurations.xml | 12 ----- app/build.gradle | 8 ++-- app/src/main/AndroidManifest.xml | 4 +- gradle.properties | 2 + gradlew | 0 library/build.gradle | 4 +- library/proguard-rules.pro | 2 + .../java/me/weishu/reflection/Reflection.java | 9 ++++ 14 files changed, 50 insertions(+), 69 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml delete mode 100644 .idea/jarRepositories.xml delete mode 100644 .idea/runConfigurations.xml mode change 100755 => 100644 gradlew diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..1e2d8f1 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,11 @@ +# Default ignored files +/shelf/ +/inspectionProfiles +/libraries +/modules +androidTestResultsUserPreferences.xml +encodings.xml +jarRepositories.xml +workspace.xml +assetWizardSettings.xml +deploymentTargetDropDown.xml \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index ec2010d..66b5f52 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,9 +1,10 @@ + diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 376307e..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 0d45e8d..58918f5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index cf1b6b5..a75ac0c 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,11 +2,15 @@ - + + + + - - + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 1f4d086..fec67c3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 + compileSdkVersion 33 defaultConfig { applicationId "me.weishu.freereflection.app" minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 'UpsideDownCake' versionCode 1 versionName "1.0" @@ -25,6 +25,6 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(":library") - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation 'androidx.appcompat:appcompat:1.0.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0f4927e..56b01e3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,9 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/gradle.properties b/gradle.properties index aac7c9b..9e6fce1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,8 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 diff --git a/library/build.gradle b/library/build.gradle index fdbb7ba..84c92ba 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,7 +8,7 @@ android { versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' externalNativeBuild { cmake { @@ -16,6 +16,8 @@ android { arguments '-DANDROID_STL=c++_static' } } + // provider proguard-rules + consumerProguardFile 'proguard-rules.pro' } buildTypes { diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro index f1b4245..efb0c69 100644 --- a/library/proguard-rules.pro +++ b/library/proguard-rules.pro @@ -19,3 +19,5 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile + +-keep class me.weishu.reflection.BootstrapClass { *; } \ No newline at end of file diff --git a/library/src/main/java/me/weishu/reflection/Reflection.java b/library/src/main/java/me/weishu/reflection/Reflection.java index 9161812..f2b3305 100644 --- a/library/src/main/java/me/weishu/reflection/Reflection.java +++ b/library/src/main/java/me/weishu/reflection/Reflection.java @@ -55,6 +55,15 @@ private static boolean unsealByDexFile(Context context) { fos.write(bytes); } + // Support target Android U. + // https://developer.android.com/about/versions/14/behavior-changes-14#safer-dynamic-code-loading + try { + //noinspection ResultOfMethodCallIgnored + code.setReadOnly(); + } catch (Throwable ignore) { + } + + @SuppressWarnings("deprecation") DexFile dexFile = new DexFile(code); // This class is hardcoded in the dex, Don't use BootstrapClass.class to reference it // it maybe obfuscated!! From 61f43e52bd75da74a1d74e4772e1a415cb5a01e2 Mon Sep 17 00:00:00 2001 From: Hu Shenghao Date: Sun, 18 Jun 2023 10:46:54 +0800 Subject: [PATCH 2/3] Clean up library --- library/build.gradle | 2 ++ library/src/main/res/values/strings.xml | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 library/src/main/res/values/strings.xml diff --git a/library/build.gradle b/library/build.gradle index 84c92ba..74328bd 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -20,6 +20,8 @@ android { consumerProguardFile 'proguard-rules.pro' } + packageBuildConfig = false + buildTypes { release { minifyEnabled false diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml deleted file mode 100644 index e78d2f7..0000000 --- a/library/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - Lib - From db7be382e6631104f7580ae811dbdb01279ae1e7 Mon Sep 17 00:00:00 2001 From: Hu Shenghao Date: Sun, 18 Jun 2023 11:04:07 +0800 Subject: [PATCH 3/3] Disable android Jetifier --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9e6fce1..c5a1121 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,11 +9,11 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -android.enableJetifier=true -android.useAndroidX=true org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true +#android.enableJetifier=true +android.useAndroidX=true