Error: Activity class {xxx.java} does not exist

git切换到不同的branch之后,报下面的错误:
Error: Activity class {xxx.java} does not exist

解决方案:

首先clean 然后会删除build目录
在这里插入图片描述
然后点击:Invalidate Caches
在这里插入图片描述
在这里插入图片描述

Android Studio重启,然后重新build即可。

Initializing Gradle Language Server vscode这个一直在加载是什么意思 还有我运行一个pda项目 PS F:\mom-mls-pda> npx react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. Jetifier found 1363 file(s) to forward-jetify. Using 8 workers... info JS server already running. info Installing the app... The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build. This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal. Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects. If the parent project does not need the plugin, add 'apply false' to the plugin line. See: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl The Kotlin plugin was loaded in the following projects: ':react-native-pager-view', ':react-native-screens', ':shopify_flash-list' > Task :app:installDebug Installing APK 'pda_mls_mom_x86_64_2.0.765.apk' on 'Small_Phone(AVD) - 11' for app:debug Installed on 1 device. BUILD SUCCESSFUL in 1m 38s 360 actionable tasks: 2 executed, 358 up-to-date info Connecting to the development server... info Starting the app on "emulator-5554"... Starting: Intent { cmp=com.hoolinks.mls.mom/.MainActivity } Error type 3 Error: Activity class {com.hoolinks.mls.mom/com.hoolinks.mls.mom.MainActivity} does not exist. PS F:\mom-mls-pda> 总结报错原因 最好深入底层 我这个项目一直卡在这步骤 我已经改了以下文件的build.gradle的 repositories 分别是文件:react-native-pager-view、react-native-screens 、 shopify flash-list 、@react-native-picker 都把对应文件build.gradle的 repositories的改成跟项目的F:\mom-mls-pda\android\build.gradle一样的repositories repositories { // google() // jcenter() maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url = "https://maven.aliyun.com/repository/gradle-plugin" } maven { url = "https://maven.aliyun.com/repository/public" } } 然后别人也只是和我一样改了上面的一些repositories 为什么他们之后可以直接npx react-native run-android 启动项目而我不行 难道是因为我用了不同版本的yarn.lock 然后别人都能直接运行起来 所以我认为我不能去改android\build.gradle里面的内容 公司统一的
08-11
Android 开发中,`package androidx.work does not exist` 错误通常意味着项目没有正确配置 `WorkManager` 依赖。以下是解决此问题的一些常见方法: ### 1. 添加 WorkManager 依赖 确保在项目的 `build.gradle` 文件中添加了 `WorkManager` 的依赖。在 `dependencies` 块中添加以下代码: ```groovy dependencies { def work_version = "2.7.1" // 可以根据需要选择合适的版本 // 对于 Java 项目 implementation "androidx.work:work-runtime:$work_version" // 如果是 Kotlin 项目,还可以添加以下依赖 implementation "androidx.work:work-runtime-ktx:$work_version" } ``` 添加依赖后,点击 Android Studio 工具栏中的 “Sync Now” 按钮,让项目同步依赖。 ### 2. 检查 AndroidX 配置 确保项目已经迁移到 AndroidX。可以通过以下步骤检查和迁移: - 打开 `gradle.properties` 文件,确保包含以下配置: ```properties android.useAndroidX=true android.enableJetifier=true ``` - 如果项目还没有迁移到 AndroidX,可以通过 Android Studio 的 “Refactor” -> “Migrate to AndroidX” 菜单进行迁移。 ### 3. 清理和重建项目 有时候,构建缓存可能会导致依赖问题。可以尝试清理和重建项目: - 选择 “Build” -> “Clean Project” 清理项目。 - 选择 “Build” -> “Rebuild Project” 重建项目。 ### 4. 检查网络连接 确保网络连接正常,因为 Android Studio 需要从 Maven 仓库下载依赖。如果网络不稳定,可能会导致依赖下载失败。 ### 5. 检查 Gradle 版本 确保使用的 Gradle 版本支持 `WorkManager`。可以在 `build.gradle` 文件中检查和更新 Gradle 版本: ```groovy // 在项目根目录的 build.gradle 文件中 buildscript { repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.0.4' // 可以根据需要选择合适的版本 } } ``` ### 6. 检查 SDK 版本 确保安装了足够的 Android SDK 版本。`WorkManager` 可能依赖于特定的 SDK 版本,因此需要确保安装了相应的 SDK 版本。 通过以上步骤,应该可以解决 `package androidx.work does not exist` 错误。如果问题仍然存在,可能需要进一步检查项目配置和依赖关系。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

技术在路上

帮助需要的人

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值