Error: Activity class {com.xxx.xxx/com.xxx.xxx.MainActivity} does not exist.

本文详细介绍了在使用Android Studio安装应用时遇到的“Activity class does not exist”错误,并提供了具体的解决步骤,包括检查applicationId与包名一致性、更新versionCode等。

版权声明:本文为延成原创文章,转载请标明出处

问题复现

Error: Activity class {com.xxx.xxx/com.xxx.xxx.MainActivity} does not exist.

android studio 安装app时报错。

问题解决

1.首先确定你的applicationId与AndroidManifest.xml中的包名是否一致。

 defaultConfig {
        applicationId "xxx.xxx.xxx"
        ...
}

2.如果包名都一致,运行看下是否OK。
3.如果还不行,检查下代码也都没问题,请更改一下versionCode 号,然后再运行。

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 应用启动时提示 `Activity class does not exist: com.demo.ld.myapp81/MainActivity`,这通常意味着系统无法找到指定的 Activity 类。以下是可能的原因及解决方法: ### 1. Activity 未在 AndroidManifest.xml 中声明 确保 `MainActivity` 已在 `AndroidManifest.xml` 文件中正确声明。例如: ```xml <application android:allowBackup="true" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> ``` 如果 `MainActivity` 不在默认包中,需要使用完整的类名,例如: ```xml <activity android:name="com.demo.ld.myapp81.MainActivity" /> ``` ### 2. 包名或类名拼写错误 检查 `AndroidManifest.xml` 中的 `package` 属性是否与应用的实际包名一致。例如: ```xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.demo.ld.myapp81" > ``` 同时,确保在 `activity` 标签中指定的 `android:name` 属性与实际的类路径匹配。 ### 3. Gradle 配置问题 检查 `build.gradle` 文件中的 `applicationId` 是否与应用的包名一致。例如: ```gradle android { namespace 'com.demo.ld.myapp81' compileSdk 33 defaultConfig { applicationId "com.demo.ld.myapp81" minSdk 21 targetSdk 33 versionCode 1 versionName "1.0" } } ``` 确保 `namespace` 和 `applicationId` 与应用的包名一致。 ### 4. 清理并重建项目 有时,构建缓存可能导致问题。尝试清理项目并重新构建: 1. 在 Android Studio 中选择 **Build > Clean Project**。 2. 然后选择 **Build > Rebuild Project**。 ### 5. 检查 Gradle 插件版本 确保使用的 Gradle 插件版本与项目兼容。可以在 `build.gradle` 文件中检查插件版本: ```gradle plugins { id 'com.android.application' version '7.4.2' apply false id 'org.jetbrains.kotlin.android' version '1.8.0' apply false } ``` ### 6. 检查设备或模拟器上的旧安装 如果之前安装过该应用,但更改了包名或 Activity 名称,可能需要卸载旧版本以避免冲突。可以使用以下命令卸载应用: ```bash adb uninstall com.demo.ld.myapp81 ``` 然后重新安装应用。 ### 7. 检查 ProGuard 或 R8 配置(如果启用) 如果启用了代码混淆,确保 `MainActivity` 没有被混淆。可以在 `proguard-rules.pro` 文件中添加以下规则: ```proguard -keep public class com.demo.ld.myapp81.MainActivity { public *; } ``` ### 8. 检查 Gradle Sync 状态 确保 Gradle 同步成功。如果同步失败,可能会导致构建配置不正确。可以尝试点击 **File > Sync Project with Gradle Files**。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值