LiveEdit not working in Android Studio: Internal error ClassCastException BasicValue cannot be cast to IntValue

I’m using jetpack compose in a project.

I’m using android studio Koala 2024.1.2 Patch 1. I’m using everything almost to the latest versions.

I have a simple composable screen (a bunch of Composable functions that use each other). The only special thing that I’m using into this screen is that I’m using PagingData by creating some composables dynamically, and I’m also using a viewmodel injected with Hilt.

I’ve struggled to make the preview work because of the usage of ViewModels, but I’ve workarounded by creating “Content” composables that use the flows in the viewmodel but they don’t access the viewmodel itself.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Composable
fun SlideMovieScreen(viewModel: SlideMovieViewModel = hiltViewModel()) {
val deviceLanguage = getDeviceLocale()
viewModel.setLanguage(deviceLanguage)
val context = LocalContext.current
val vibrator = remember { getVibrator(context) }
SlideMovieScreenContent(viewModel.swipeAction, viewModel.moviesFlow, {
triggerSmallVibration(vibrator); viewModel.onLikeButtonClicked()
}, {
triggerSmallVibration(vibrator); viewModel.onDislikeButtonClicked()
}, {
viewModel.clearSwipeAction()
})
}
@Preview
@Composable
fun SlideMovieScreenPreview() {
val swipeAction =
remember { MutableStateFlow(SlideMovieViewModel.SwipeAction.LIKE).asStateFlow() }
val moviesFlow =
flowOf(PagingData.from(movies))
FilmatchApp {
SlideMovieScreenContent(swipeAction, moviesFlow, {}, {}, {})
}
}
</code>
<code>@Composable fun SlideMovieScreen(viewModel: SlideMovieViewModel = hiltViewModel()) { val deviceLanguage = getDeviceLocale() viewModel.setLanguage(deviceLanguage) val context = LocalContext.current val vibrator = remember { getVibrator(context) } SlideMovieScreenContent(viewModel.swipeAction, viewModel.moviesFlow, { triggerSmallVibration(vibrator); viewModel.onLikeButtonClicked() }, { triggerSmallVibration(vibrator); viewModel.onDislikeButtonClicked() }, { viewModel.clearSwipeAction() }) } @Preview @Composable fun SlideMovieScreenPreview() { val swipeAction = remember { MutableStateFlow(SlideMovieViewModel.SwipeAction.LIKE).asStateFlow() } val moviesFlow = flowOf(PagingData.from(movies)) FilmatchApp { SlideMovieScreenContent(swipeAction, moviesFlow, {}, {}, {}) } } </code>
@Composable
fun SlideMovieScreen(viewModel: SlideMovieViewModel = hiltViewModel()) {
    val deviceLanguage = getDeviceLocale()
    viewModel.setLanguage(deviceLanguage)
    val context = LocalContext.current
    val vibrator = remember { getVibrator(context) }

    SlideMovieScreenContent(viewModel.swipeAction, viewModel.moviesFlow, {
        triggerSmallVibration(vibrator); viewModel.onLikeButtonClicked()
    }, {
        triggerSmallVibration(vibrator); viewModel.onDislikeButtonClicked()
    }, {
        viewModel.clearSwipeAction()
    })
}


@Preview
@Composable
fun SlideMovieScreenPreview() {
    val swipeAction =
        remember { MutableStateFlow(SlideMovieViewModel.SwipeAction.LIKE).asStateFlow() }
    val moviesFlow =
        flowOf(PagingData.from(movies))
    FilmatchApp {
        SlideMovieScreenContent(swipeAction, moviesFlow, {}, {}, {})
    }
}

Other than struggling with my preview, which I think it’s normal when using ViewModels in jetpack, my main problem is that LiveEdit is not working at all. When I run the app and make a minor change such as changing any color, I just see this error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Internal error Unexpected error during compilation command java.lang.ClassCastException class.org.objectweb.asm.tree.analysis.BasicValue cannot be cast to class com.android.tools.idea.run.deployment.liveedit.analysis.IntValue
</code>
<code>Internal error Unexpected error during compilation command java.lang.ClassCastException class.org.objectweb.asm.tree.analysis.BasicValue cannot be cast to class com.android.tools.idea.run.deployment.liveedit.analysis.IntValue </code>
Internal error Unexpected error during compilation command java.lang.ClassCastException class.org.objectweb.asm.tree.analysis.BasicValue cannot be cast to class com.android.tools.idea.run.deployment.liveedit.analysis.IntValue

Sorry I can’t copy the full error text because when I try to move my mouse cursor to the text, it disappears.

Your issue is hard to replicate as we don’t know what is inside of your SlideMovieScreenContent Composable. However, you can try an incremental debugging approach to find the cause.

I just created a minimal sample of your code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Preview
@Composable
fun SlideMovieScreenPreview() {
val swipeAction =
remember { MutableStateFlow("HELLO").asStateFlow() }
val moviesFlow =
flowOf("WORLD!")
FilmatchApp {
SlideMovieScreenContent(swipeAction, moviesFlow, {}, {}, {})
}
}
@Composable
fun SlideMovieScreenContent(
swipeAction: StateFlow<String>,
moviesFlow: Flow<String>,
onLike: () -> Unit,
onDislike: () -> Unit,
onClear: () -> Unit
) {
// ugly Text Composable is only for testing
Text(text = "${swipeAction.value} ${moviesFlow.collectAsState("").value}")
}
</code>
<code>@Preview @Composable fun SlideMovieScreenPreview() { val swipeAction = remember { MutableStateFlow("HELLO").asStateFlow() } val moviesFlow = flowOf("WORLD!") FilmatchApp { SlideMovieScreenContent(swipeAction, moviesFlow, {}, {}, {}) } } @Composable fun SlideMovieScreenContent( swipeAction: StateFlow<String>, moviesFlow: Flow<String>, onLike: () -> Unit, onDislike: () -> Unit, onClear: () -> Unit ) { // ugly Text Composable is only for testing Text(text = "${swipeAction.value} ${moviesFlow.collectAsState("").value}") } </code>
@Preview
@Composable
fun SlideMovieScreenPreview() {

    val swipeAction =
        remember { MutableStateFlow("HELLO").asStateFlow() }
    val moviesFlow =
        flowOf("WORLD!")
    
    FilmatchApp {
        SlideMovieScreenContent(swipeAction, moviesFlow, {}, {}, {})
    }
}

@Composable
fun SlideMovieScreenContent(
    swipeAction: StateFlow<String>, 
    moviesFlow: Flow<String>, 
    onLike: () -> Unit, 
    onDislike: () -> Unit, 
    onClear: () -> Unit
) {
    // ugly Text Composable is only for testing 
    Text(text = "${swipeAction.value} ${moviesFlow.collectAsState("").value}")
}

With this code, LiveEdit is working fine. Whenever I change HELLO or WORLD, it is correctly refreshed on the emulator.

Please try to paste this code on your end and see if it also works for you.

  • If the minimal sample works, start to migrate it to your previous code step-by-step and see at which point LiveEdit stops working. Then you have found your issue and can investigate it further.
  • If the minimal sample doesn’t work, go to your build.gradle file and check if there are some updated dependencies available. If there are, update all versions to use the latest version.
  • If it still does not work, you can also check if there are any Android Studio updates available.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật