Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appcompat version 1.2.0 breaks resource interception #35

Open
kar opened this issue Sep 7, 2020 · 8 comments
Open

Appcompat version 1.2.0 breaks resource interception #35

kar opened this issue Sep 7, 2020 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@kar
Copy link

kar commented Sep 7, 2020

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 kar added the bug Something isn't working label Sep 7, 2020
@Maragues
Copy link

@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
Copy link

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
Copy link

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

@lucifer222
Copy link

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.

@Maragues
Copy link

No answer from any maintainer :(

@gunjan-jha
Copy link

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

@Wrakor
Copy link

Wrakor commented Jun 1, 2021

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.

@nglauber
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants