Philology
Philology copied to clipboard
Appcompat version 1.2.0 breaks resource interception
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
@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
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
- 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))
}
}
- Remove
attachBaseContext
override from Activity - Override
getDelegate
in Activity
private var baseContextWrappingDelegate: AppCompatDelegate? = null
override fun getDelegate() =
baseContextWrappingDelegate ?: BaseContextWrappingDelegate(super.getDelegate()).apply {
baseContextWrappingDelegate = this
}
- Profit!
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
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.
No answer from any maintainer :(
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
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
- 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)) } }
- Remove
attachBaseContext
override from Activity- Override
getDelegate
in Activityprivate var baseContextWrappingDelegate: AppCompatDelegate? = null override fun getDelegate() = baseContextWrappingDelegate ?: BaseContextWrappingDelegate(super.getDelegate()).apply { baseContextWrappingDelegate = this }
- 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.
Seems like the solution above is not working on AppCompat 1.3.0.