question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Appcompat version 1.2.0 breaks resource interception

See original GitHub issue

Describe the bug I think the interception broke again with AppCompat 1.2.0. My libraries versions:

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0-alpha02'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'androidx.navigation:navigation-fragment:2.3.0'
    implementation 'androidx.navigation:navigation-ui:2.3.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
    implementation 'androidx.preference:preference-ktx:1.1.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.browser:browser:1.2.0'
    implementation 'androidx.webkit:webkit:1.3.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'

I tried the configChanges workaround from #23, but it seems to not help this time around.

To Reproduce

  • Update appcompat to 1.2.0
  • Default app strings are used instead

Expected behavior

  • Injection works

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:8

github_iconTop GitHub Comments

5reactions
Maraguescommented, Oct 28, 2020

After trying to understand what’s going on, it looks like AppCompat 1.2.0 changes how context wrapping is done, even tho I don’t see any official notes documenting it

After a lot of investigation and time wasted, this answer provided the solution

Steps to make it work on AppCompat 1.2.0

  1. Create BaseContextWrappingDelegate, and apply context wrapping there
class BaseContextWrappingDelegate(private val superDelegate: AppCompatDelegate) : AppCompatDelegate() {
    [...]

    private fun wrap(context: Context): Context {
        return ViewPumpContextWrapper.wrap(Philology.wrap(context))
    }
}
  1. Remove attachBaseContext override from Activity
  2. Override getDelegate in Activity
private var baseContextWrappingDelegate: AppCompatDelegate? = null

override fun getDelegate() =
        baseContextWrappingDelegate ?: BaseContextWrappingDelegate(super.getDelegate()).apply {
            baseContextWrappingDelegate = this
        }
  1. Profit!
0reactions
nglaubercommented, May 26, 2022

Seems like the solution above is not working on AppCompat 1.3.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Activity - Android Developers
The BackHandler will now properly intercept back presses in the event that the Activity is ... Version 1.2.0-rc01 contains these commits.
Read more >
How OkCredit Android App improves UX writing by changing ...
Like most apps, OkCredit app uses a lot of XML string resources, ... Appcompat version 1.2.0 breaks resource interception · Issue #35 ...
Read more >
How is the Resource class correctly overwritten to implement ...
@arekolek in my case it is androidx.appcompat:appcompat:1.2.0 which breaks Lokalise. Must use 1.1.0 instead. Thanks for your tip so that I ...
Read more >
androidx.appcompat:appcompat 1.1.0 crashes webview when ...
The issue is a bug in old versions of WebView (most of which are installed in API 21-22ish), which AppCompat doesn't have any...
Read more >
Change Log - Coil
Downgrade androidx.appcompat:appcompat-resources to 1.4.2 to work around #1423. ... Coil 2.0.0 is a major iteration of the library and includes breaking ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found