From 4739800db932b71e8be03e8de93873c16bed64ea Mon Sep 17 00:00:00 2001 From: Dmitriy Voronin Date: Tue, 4 Feb 2020 19:47:05 +0300 Subject: [PATCH 1/2] workaround shrinked resources --- docs/content/test/TestMinimized.md | 27 +++++++++++++++++++ .../android-test/test-app/build.gradle.kts | 2 +- .../test-app/src/main/res/raw/keep.xml | 3 +++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 subprojects/android-test/test-app/src/main/res/raw/keep.xml diff --git a/docs/content/test/TestMinimized.md b/docs/content/test/TestMinimized.md index a17ba1f24c..370f7fd6f6 100644 --- a/docs/content/test/TestMinimized.md +++ b/docs/content/test/TestMinimized.md @@ -24,3 +24,30 @@ However we could miss some bugs, because debug(not release) sources included, so ## Sample You can check configuration in `:test-app` module. + +## If you still have problems + +Keeper can't do all the work here, so if you still can't run test, check these: + +### Dynamically referenced resources + +You can see in `PageObjectTest`, that we referenced `R.layout.page_object_1`, dynamically creating layout.\ +These layouts referenced nowhere in app code, so if `shrinkResources` enabled you will face strange error: + +```text +error inflating class x +Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.x" on path: DexPathList +``` + +What it really hides, `R.layout.page_object_1` got shrinked to: + +```xml + +``` + +If this is your case, add these resources to `res/raw/keep.xml` like this: + +```xml + +``` diff --git a/subprojects/android-test/test-app/build.gradle.kts b/subprojects/android-test/test-app/build.gradle.kts index c06e65b2c2..2b0765a970 100644 --- a/subprojects/android-test/test-app/build.gradle.kts +++ b/subprojects/android-test/test-app/build.gradle.kts @@ -55,7 +55,7 @@ android { setMatchingFallbacks("debug") isMinifyEnabled = true - isShrinkResources = false + isShrinkResources = true proguardFiles(getDefaultProguardFile(ProguardFile.DONT_OPTIMIZE.fileName), "proguard-rules.pro") } diff --git a/subprojects/android-test/test-app/src/main/res/raw/keep.xml b/subprojects/android-test/test-app/src/main/res/raw/keep.xml new file mode 100644 index 0000000000..995684f8bd --- /dev/null +++ b/subprojects/android-test/test-app/src/main/res/raw/keep.xml @@ -0,0 +1,3 @@ + + From 8933cf5a1d94e0c0558eb1d8c73dde8daba48ffa Mon Sep 17 00:00:00 2001 From: Dmitriy Voronin Date: Wed, 5 Feb 2020 15:53:43 +0300 Subject: [PATCH 2/2] use new r8 version, add doc about it --- build.gradle.kts | 11 +++++ docs/content/test/TestMinimized.md | 42 +++++++++++++++++-- gradle.properties | 1 + .../android-test/test-app/build.gradle.kts | 3 ++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 76f4ea438e..85f4dd926e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,6 +5,17 @@ import com.android.build.gradle.BaseExtension import com.android.build.gradle.LibraryPlugin import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +buildscript { + val r8Version: String by project + + repositories { + maven { setUrl("http://storage.googleapis.com/r8-releases/raw") } + } + dependencies { + classpath("com.android.tools:r8:$r8Version") + } +} + plugins { id("org.jetbrains.kotlin.jvm") apply false id("com.android.application") apply false diff --git a/docs/content/test/TestMinimized.md b/docs/content/test/TestMinimized.md index 370f7fd6f6..951b973175 100644 --- a/docs/content/test/TestMinimized.md +++ b/docs/content/test/TestMinimized.md @@ -25,9 +25,7 @@ However we could miss some bugs, because debug(not release) sources included, so You can check configuration in `:test-app` module. -## If you still have problems - -Keeper can't do all the work here, so if you still can't run test, check these: +## Known issues ### Dynamically referenced resources @@ -51,3 +49,41 @@ If this is your case, add these resources to `res/raw/keep.xml` like this: ``` + +### Try latest stable version of R8 + +Some issues probably solved in new version of r8. For example: ["already has a mapping" one](https://issuetracker.google.com/issues/122924648) + +By default, r8 bundled with android gradle plugin, but you can override it. + +```kotlin +buildscript { + val r8Version: String by project + + repositories { + maven { setUrl("http://storage.googleapis.com/r8-releases/raw") } + } + dependencies { + classpath("com.android.tools:r8:$r8Version") // < it should be added before android gradle plugin + } +} +``` + +{{< hint info>}} +For versions check tags here: [https://r8.googlesource.com/r8/](https://r8.googlesource.com/r8/) + +Seems like 1.5 versions bundled with agp 3.5.x\ +1.6 -> 3.6.x\ +and 2.0 -> 4.0.x +{{< /hint >}} + +{{< hint warning>}} +Don't forget to tell `keeper`, you are using different r8 version: + +```kotlin +dependencies { + keeperR8("com.android.tools:r8:$r8Version") +} +``` + +{{< /hint >}} diff --git a/gradle.properties b/gradle.properties index aa7cadd1e7..dec9e29251 100644 --- a/gradle.properties +++ b/gradle.properties @@ -39,6 +39,7 @@ truthVersion=1.0 jsonPathVersion=2.4.0 teamcityRestClientVersion=1.6.1 androidGradlePluginVersion=3.5.3 +r8Version=1.6.58 androidToolsVersion=26.2.0 antPatternMatcherVersion=1.0.0 mockitoKotlin2Version=2.0.0 diff --git a/subprojects/android-test/test-app/build.gradle.kts b/subprojects/android-test/test-app/build.gradle.kts index 2b0765a970..3ed4f3fa8c 100644 --- a/subprojects/android-test/test-app/build.gradle.kts +++ b/subprojects/android-test/test-app/build.gradle.kts @@ -22,6 +22,7 @@ val junitVersion: String by project val funktionaleVersion: String by project val gsonVersion: String by project val kotsonVersion: String by project +val r8Version: String by project android { @@ -80,6 +81,8 @@ android { } dependencies { + keeperR8("com.android.tools:r8:$r8Version") + implementation("com.google.android.gms:play-services-maps:17.0.0") implementation("androidx.appcompat:appcompat:$androidXVersion")