From 3d784e1ec1f49c6f9a960eb2a672e653dd1c1412 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 31 Aug 2024 16:41:06 +0800 Subject: [PATCH 1/2] Keep TokenCompleteTextView generic types for R8 fullMode Fixes ``` java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType at com.tokenautocomplete.TokenCompleteTextView.reifyParameterizedTypeClass(SourceFile:96) at android.view.View.dispatchSaveInstanceState(View.java:22847) at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4029) at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4029) at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4029) at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4029) at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4029) at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4029) at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4029) at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4029) at android.view.View.saveHierarchyState(View.java:22830) ``` --- README.md | 3 +++ library/src/main/resources/META-INF/proguard/autocomplete.pro | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 library/src/main/resources/META-INF/proguard/autocomplete.pro diff --git a/README.md b/README.md index ccfa8a2..0595d7d 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,9 @@ If you would like to get the most recent code in a jar, clone the project and ru You may also add the library as an Android Library to your project. All the library files live in ```library```. +### R8 / ProGuard +The specific rules are [already bundled](library/src/main/resources/META-INF/proguard/autocomplete.pro) into the JAR which can be interpreted by R8 automatically. + Creating your auto complete view -------------------------------- diff --git a/library/src/main/resources/META-INF/proguard/autocomplete.pro b/library/src/main/resources/META-INF/proguard/autocomplete.pro new file mode 100644 index 0000000..d6e59d6 --- /dev/null +++ b/library/src/main/resources/META-INF/proguard/autocomplete.pro @@ -0,0 +1,3 @@ +# Keep generic types for R8 fullMode. +-keep,allowobfuscation,allowshrinking class com.tokenautocomplete.TokenCompleteTextView +-keep,allowobfuscation,allowshrinking class * extends com.tokenautocomplete.TokenCompleteTextView \ No newline at end of file From f325772c0935d41988c161202ac03f7a21d1433f Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 31 Aug 2024 16:45:09 +0800 Subject: [PATCH 2/2] Enable R8 fullMode in example for testing --- example/build.gradle | 6 +++++- gradle.properties | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/example/build.gradle b/example/build.gradle index 47e7fce..c5e84c1 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -23,8 +23,12 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { + all { + signingConfig signingConfigs.debug + } release { - minifyEnabled false + minifyEnabled true + proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), 'proguard-rules.pro' } } compileOptions { diff --git a/gradle.properties b/gradle.properties index 973d43e..9c65764 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,4 +31,6 @@ POM_DEVELOPER_ID=mgod POM_DEVELOPER_NAME=Marshall Weir android.useAndroidX=true android.enableJetifier=false +# Enable R8 full mode. +android.enableR8.fullMode=true org.gradle.jvmargs=-Xmx4096m "-XX:MaxMetaspaceSize=512m"