akexorcist / Localization

[Android] In-app language changing library
Apache License 2.0
983 stars 154 forks source link

Caused by java.lang.UnsupportedOperationException Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1} #93

Closed kyh8496 closed 3 years ago

kyh8496 commented 3 years ago

I'm using 1.2.7 version override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(getResId(), container, false) <<<< error line }

An error occurs when creating a customAlertDialogFragment. I guess the theme was influenced.

It doesn't happen if I downgrade to 1.2.6 version.

kyh8496 commented 3 years ago

https://github.com/akexorcist/Localization/pull/83

Because of the above issue, 1.2.7 should be used. When can the issue be fixed?

akexorcist commented 3 years ago

83 already included in 1.2.7

Let me try to create the custom alert dialog fragment in my test project. Would be great if you provide more about code in your custom alert dialog fragment.

akexorcist commented 3 years ago

With my simple testing. Everything seem work fine. See https://github.com/akexorcist/Localization/commit/ec60f45295e925f8e248cd20b65f7e8a71085c14

Issue might caused by some implementation in your custom dialog fragment. Please show me your code if you can or paste the full error message from crashing

kyh8496 commented 3 years ago

full error message Caused by java.lang.UnsupportedOperationException Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1} myproject.common.CommonAlertDialogFragment.onCreateView android.content.res.TypedArray.getColorStateList (TypedArray.java:546) android.widget.TextView.readTextAppearance (TextView.java:3888) android.widget.TextView. (TextView.java:1223) android.widget.TextView. (TextView.java:1112) androidx.appcompat.widget.AppCompatTextView. (AppCompatTextView.java:100) androidx.appcompat.widget.AppCompatTextView. (AppCompatTextView.java:95) androidx.appcompat.app.AppCompatViewInflater.createTextView (AppCompatViewInflater.java:194) androidx.appcompat.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:115) androidx.appcompat.app.AppCompatDelegateImpl.createView (AppCompatDelegateImpl.java:1551) androidx.appcompat.app.AppCompatDelegateImpl.onCreateView (AppCompatDelegateImpl.java:1602) android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:811) android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:769) android.view.LayoutInflater.rInflate (LayoutInflater.java:902) android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:863) android.view.LayoutInflater.rInflate (LayoutInflater.java:905) android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:863) android.view.LayoutInflater.inflate (LayoutInflater.java:554) android.view.LayoutInflater.inflate (LayoutInflater.java:461) myproject.view.common.CommonAlertDialogFragment.onCreateView (CommonAlertDialogFragment.java:77) androidx.fragment.app.Fragment.performCreateView (Fragment.java:2698) androidx.fragment.app.FragmentStateManager.createView (FragmentStateManager.java:310) androidx.fragment.app.FragmentManager.moveToState (FragmentManager.java:1185) androidx.fragment.app.FragmentManager.moveToState (FragmentManager.java:1354) androidx.fragment.app.FragmentManager.moveFragmentToExpectedState (FragmentManager.java:1432) androidx.fragment.app.FragmentManager.moveToState (FragmentManager.java:1495) androidx.fragment.app.BackStackRecord.executeOps (BackStackRecord.java:447) androidx.fragment.app.FragmentManager.executeOps (FragmentManager.java:2167) androidx.fragment.app.FragmentManager.executeOpsTogether (FragmentManager.java:1990) androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute (FragmentManager.java:1945) androidx.fragment.app.FragmentManager.execPendingActions (FragmentManager.java:1847) androidx.fragment.app.FragmentManager$4.run (FragmentManager.java:413) android.os.Handler.handleCallback (Handler.java:873) android.os.Handler.dispatchMessage (Handler.java:99) android.os.Looper.loop (Looper.java:214) android.app.ActivityThread.main (ActivityThread.java:7063) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:964)

kyh8496 commented 3 years ago

I made the sample project

https://github.com/kimyounghoons/PopupTest

MainActivity -> SecondActivity -> Back MainActivity -> Show Popup -> Crash!!

It doesn't die without a webview.

and the Issue is occurs on specific devices.

Galaxy J7 , Galaxy J5 , Galaxy Note 8, Galaxy Note 9, Galaxy S10 5G , Galaxy A9 (2018), LG G6 ...etc

The sample project also does not occur when downgrading to 1.2.6.

kyh8496 commented 3 years ago

Have you seen the sample project?

akexorcist commented 3 years ago

@kyh8496 Just crashing on my LG Nexus 5X (but works fine on Google Pixel 2 and Samsung Galaxy Z Fold 2). Thank you for your sample project to reproduce this issue. The problem is specific happen on Android 8.0 (API Level 26)

Let me check it more for a while.

akexorcist commented 3 years ago

@kyh8496 This seems surprising to me. WebView in another activity make the dialog fragment crashing in API 26 only!

Because I changed how to update the resource's locale in 1.2.7

// LocalizationActivityDelegate.getResources(resources: Resources)
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
    val config = Configuration().apply {
        setLocale(locale)
        setLocales(localeList)
        setLayoutDirection(locale)
    }
    activity.createConfigurationContext(config).resources
}

I don't know how it happen. But I will directly update the locale in resource's configuration instead of creating new configuration when device running on API 26

Build.VERSION.SDK_INT > Build.VERSION_CODES.O -> {
    val config = Configuration().apply {
        setLocale(locale)
        setLocales(localeList)
        setLayoutDirection(locale)
    }
    activity.createConfigurationContext(config).resources
}
Build.VERSION.SDK_INT == Build.VERSION_CODES.O -> {
    resources.configuration.apply {
        setLocale(locale)
        setLocales(localeList)
        setLayoutDirection(locale)
    }
    resources
}
kyh8496 commented 3 years ago

Most of the issues posted on Firebase Crashlytics were Android 8 or 9.

akexorcist commented 3 years ago

@kyh8496 Thanks for your information

akexorcist commented 3 years ago

@kyh8496 v2.1.9 is live including fixes this issue .

kyh8496 commented 3 years ago

Oh~ Thank you very much, you're a great developer!! I'll test this issue

akexorcist commented 3 years ago

One more thing. I moved v1.2.9 to MavenCentral.

kyh8496 commented 3 years ago

okay! I will upload it using version 1.2.9 and track if it crashes. thanks ~!

akexorcist commented 3 years ago

Feel free to reopen this issue again if you still has this problem