Daniele B
02/14/2021, 3:52 PMjava.lang.NoClassDefFoundError: Failed resolution of: Landroidx/activity/compose/LocalOnBackPressedDispatcherOwner;
at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:83)
at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:59)
at myapp.android.NavigationKt.Navigation(Navigation.kt:22)
any idea?Ian Lake
02/14/2021, 3:53 PMDaniele B
02/14/2021, 3:59 PMjim
02/14/2021, 4:01 PMDaniele B
02/14/2021, 4:08 PMimplementation("androidx.activity:activity-ktx:1.2.0")
implementation("androidx.activity:activity-compose:1.3.0-alpha02")
do I need both?Ian Lake
02/14/2021, 4:14 PMactivity-compose
has activity-ktx
as a transitive dependency, so you definitely don't need both of those (just activity-compose
is enough)Daniele B
02/14/2021, 4:19 PMIan Lake
02/14/2021, 4:20 PMactivity-ktx
will already give you core-ktx:1.1.0
(so the question is do you specifically want extensions from the newer version? Only then do you need to declare what specific version you want) and a pure compose app with no Views whatsoever doesn't need material
or appcompat
either (as those are primarily View focused dependencies)AppCompatActivity
for whatever reason, then you should use appcompat:1.3.0-beta01
as it is the 1.3 releases that populate the ViewTree APIs compose depends on (if you're only using ComponentActivity
, then you're fine - that potential issue only applies specifically to AppCompatActivity
)Daniele B
02/14/2021, 4:49 PMclass MainActivity : AppCompatActivity() {
private val appViewModel: AppViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyAppTheme(appViewModel.KMPModel) {
Navigation(appViewModel.KMPModel)
}
}
}
}
I didn’t know about ComponentActivity
, is it new?Ian Lake
02/14/2021, 5:02 PMAppCompatActivity
and FragmentActivity
for a year and a half or so nowDaniele B
02/14/2021, 5:15 PMComponentActivity
!
The code snippet on JetpackCompose tutorial page uses: AppCompatActivity
https://developer.android.com/jetpack/compose/tutorial
I have just replaced AppCompatActivity
with ComponentActivity
in my app and it seems to work correctly. So, can I safely use it?Ian Lake
02/14/2021, 7:07 PMComponentActivity
should be enoughAppCompatActivity
makes more sense as a general recommendation that will give you a working solution in Compose without having to make changes later if you end up needing an AndroidView
that assumes AppCompat, Material, etc. is availableDaniele B
02/14/2021, 8:34 PMIan Lake
02/14/2021, 8:37 PMDaniele B
02/14/2021, 8:38 PM