WAI
Status Update
Comments
il...@google.com <il...@google.com> #2
The default theme does not have an app defined attribute ?attr/selectableItemBackground (as Fragment has no dependency on AppCompat, MDC, etc)
It sounds like you should be passing the correct theme to FragmentScenario:
launchFragmentInContainer<PollHomeFragment>(themeResId = R.style.Theme_YourTheme)
It sounds like you should be passing the correct theme to FragmentScenario:
launchFragmentInContainer<PollHomeFragment>(themeResId = R.style.Theme_YourTheme)
Description
When running the test I get this error: `android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class <unknown>`. See full stacktrace attached.
Removing `android:background="?attr/selectableItemBackground"` from the TextView resolves the issue.
I also posted this to stackoverflow with my finding:
I guess the question is, what should be the workaround? I would prefer to not have to remove ?attr/selectableItemBackground from all my layouts...
Here's the code:
Test:
@RunWith(AndroidJUnit4::class)
class PollHomeFragmentTest {
@Test
fun foo() {
...
launchFragmentInContainer<PollHomeFragment>()
...
}
}
Fragment:
import androidx.fragment.app.Fragment
...
class PollHomeFragment : Fragment() {
...
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_poll_home, container, false) // Crash occurs here
...
return view
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
xmlns:tools="
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".poll.PollActivity">
<TextView
android:id="@+id/tvEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="asdf@asdf.com" />
<TextView <!-- This is line 16 -->
android:id="@+id/tvViewPoll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:minHeight="48dp"
android:text="View Poll" />
<TextView
android:id="@+id/tvCreatePoll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:minHeight="48dp"
android:text="Create Poll" />
</LinearLayout>
Build: AI-191.8026.42.35.5977832, 201910302259,
AI-191.8026.42.35.5977832, JRE 1.8.0_202-release-1483-b49-5587405x64 JetBrains s.r.o, OS Mac OS X(x86_64) v10.14.6, screens 1440x900, 1920x1200; Retina
AS: 3.5.2; Android Gradle Plugin: 3.5.2; Gradle: 5.4.1; NDK: from local.properties: (not specified), latest from SDK: (not found); LLDB: pinned revision 3.1 not found, latest from SDK: LLDB 2.3 (revision: 2.3.3614996); CMake: from local.properties: (not specified), latest from SDK: 3.6.0-rc2, from PATH: (unable to invoke cmake)Source: user_sentiment_feedback
IMPORTANT: Please read