Philology icon indicating copy to clipboard operation
Philology copied to clipboard

Appcompat version 1.2.0 breaks resource interception

Open kar opened this issue 4 years ago • 8 comments

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

kar avatar Sep 07 '20 15:09 kar

@JcMinarro @kar do you have any clue of what might be going wrong? This is a release blocker for us and we could help with a PR. But, some guidance would be appreciated

Maragues avatar Oct 28 '20 09:10 Maragues

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!

Maragues avatar Oct 28 '20 15:10 Maragues

Btw, I tried to build the library in order to contribute but dependencies are very broken & outdated :-/

It should be very easy to provide an AppCompatDelegate and update the readme

Maragues avatar Oct 28 '20 15:10 Maragues

Btw, I tried to build the library in order to contribute but dependencies are very broken & outdated :-/

It should be very easy to provide an AppCompatDelegate and update the readme

Hi Maragues, How about this question? I met same issues.

lucifer222 avatar Jan 21 '21 02:01 lucifer222

No answer from any maintainer :(

Maragues avatar Jan 21 '21 07:01 Maragues

Hi @pr0t3us i am not able to update the text of Action bar using philology library will you please help me how to solve that

gunjan-jha avatar May 21 '21 13:05 gunjan-jha

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!

That worked, thanks. What about custom views? The ViewTransformer doesn't seem to be working anymore as well, it doesnt' fetch the strings from the PhilologyRepository.

Wrakor avatar Jun 01 '21 14:06 Wrakor

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

nglauber avatar May 26 '22 23:05 nglauber