Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MainActivity does not exist error in Android react-native

So I'm getting the MainActivity does not exist error, it might be because I renamed the package and app from bomber to Bomber and changed the appId from com.bomber to cool.bomber.android

I've checked the AndroidManifest, the activity source files and the build.gradle file but I can't seem to find what's the mistake

Error message

Starting: Intent { cmp=cool.bomber.android/.MainActivity }
Error type 3
Error: Activity class {cool.bomber.android/cool.bomber.android.MainActivity} does not exist.

app/build.gradle

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "cool.bomber.android"
...

AndroidMaifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="22" />

<application
  android:name=".MainApplication"
  android:allowBackup="true"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:theme="@style/AppTheme">
  <activity
    android:name=".MainActivity"
    android:launchMode="singleTask"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="com.google.intent.category.CARDBOARD" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:host="foo.app.goo.gl" android:scheme="http"/>
        <data android:host="foo.app.goo.gl" android:scheme="https"/>
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

android/app/src/main/java/cool/bomber/android/MainActivity.java

package cool.bomber.android;    
import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {
    @Override
    protected String getMainComponentName() {
        return "Bomber";
    }
}

I'm not sure what else I should be looking at to debug.

like image 203
MonkeyBonkey Avatar asked Mar 30 '18 15:03

MonkeyBonkey


2 Answers

You need to uninstall the application properly.

If it does not work from the phone, you can use cmd

adb uninstall "package name"

like image 61
DeveloperApps Avatar answered Sep 18 '22 11:09

DeveloperApps


Add package name in manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cool.bomber.android">

and still not working than write full package name like this

<application
  android:name="cool.bomber.android.MainApplication"
  android:allowBackup="true" >

<activity
    android:name="cool.bomber.android.MainActivity"
    >

and make sure this is the right path

and in CMD write this:

 cd android & gradlew clean 
      or maybe
 cd android && ./gradlew clean 

and than run react-native run-android

Make sure when you write this code you are at root of your project folder

Or Else:

Follow this to refresh whole project after changing package using android studio.

like image 38
Sagar Chavada Avatar answered Sep 18 '22 11:09

Sagar Chavada