Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassNotFoundException: Didn't find class ".MainActivity" on path: DexPathList react-native [duplicate]

I am writing a mobile app using react-native. Even though I did not touch any native side of my code, App started to be stopped just after running. I did some changes in react native components, but I did not use anything new. I debugged it in Android studio and here is the error:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: tedu.edu.tr, PID: 23741
                  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{tedu.edu.tr/tedu.edu.tr.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "tedu.edu.tr.MainActivity" on path: DexPathList[[zip file "/data/app/tedu.edu.tr-Q-Z69MlFdgprlVraa6TSjg==/base.apk"],nativeLibraryDirectories=[/data/app/tedu.edu.tr-Q-Z69MlFdgprlVraa6TSjg==/lib/arm, /data/app/tedu.edu.tr-Q-Z69MlFdgprlVraa6TSjg==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2721)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2895)
                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1596)
                      at android.os.Handler.dispatchMessage(Handler.java:105)
                      at android.os.Looper.loop(Looper.java:164)
                      at android.app.ActivityThread.main(ActivityThread.java:6565)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                   Caused by: java.lang.ClassNotFoundException: Didn't find class "tedu.edu.tr.MainActivity" on path: DexPathList[[zip file "/data/app/tedu.edu.tr-Q-Z69MlFdgprlVraa6TSjg==/base.apk"],nativeLibraryDirectories=[/data/app/tedu.edu.tr-Q-Z69MlFdgprlVraa6TSjg==/lib/arm, /data/app/tedu.edu.tr-Q-Z69MlFdgprlVraa6TSjg==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
                      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                      at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2711)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2895) 
                      at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1596) 
                      at android.os.Handler.dispatchMessage(Handler.java:105) 
                      at android.os.Looper.loop(Looper.java:164) 
                      at android.app.ActivityThread.main(ActivityThread.java:6565) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

Worst part of the problem is everyone keeps suggesting cleaning project or enabling multidex, which are done by me, yet no effect.

Here is my app level build.gradle:

android {
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
    applicationId "tedu.edu.tr"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 15
    versionName "2.0.1"
    multiDexEnabled true
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
}

splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86"
    }
}
buildTypes {
    release {
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), 
"proguard-rules.pro"
        // signingConfig signingConfigs.release
    }
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // For each separate APK per architecture, set a unique version code as described here:
        // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
        def versionCodes = ["armeabi-v7a":1, "x86":2]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
        }
    }
}
buildToolsVersion '27.0.3'
}

dependencies {
compile project(':react-native-file-viewer')
compile project(':rn-fetch-blob')
compile project(':react-native-vector-icons')
compile project(':react-native-randombytes')
compile project(':react-native-firebase')
implementation project(':react-native-firebase')
implementation project(':react-native-vector-icons')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+"  // From node_modules
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation "com.google.firebase:firebase-messaging:17.1.0"
implementation 'me.leolin:ShortcutBadger:1.1.21@aar' // <-- Add this line if you wish to use badge on Android
implementation 'com.android.support:multidex:1.0.3'
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'

Also other build.gradle:

buildscript {
repositories {
    google()
    jcenter()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'
    classpath 'com.google.gms:google-services:4.0.1'

    // NOTE: Do not place your application dependencies here; they 
belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    mavenLocal()
    jcenter()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}
}

ext {
buildToolsVersion = "26.0.3"
minSdkVersion = 16
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
}

Lastly here is My MainApplication.java file(I added attachBaseContext() method so that I use MultiDex):

package tedu.edu.tr;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.facebook.react.ReactApplication;
import com.vinzscam.reactnativefileviewer.RNFileViewerPackage;
import com.RNFetchBlob.RNFetchBlobPackage;
import com.bitgo.randombytes.RandomBytesPackage;
import io.invertase.firebase.RNFirebasePackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import 
 io.invertase.firebase.notifications.RNFirebaseNotificationsPackage; 
  // <-- Add this line
 import java.util.Arrays;
 import java.util.List;

public class MainApplication extends Application implements 
    ReactApplication {

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
        return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(new MainReactPackage(), new RNFileViewerPackage(),
                new RNFetchBlobPackage(), new VectorIconsPackage(), new RandomBytesPackage(),
                new RNFirebasePackage(), new RNFirebaseMessagingPackage(), new RNFirebaseNotificationsPackage());
    }

    @Override
    protected String getJSMainModuleName() {
        return "index";
    }
};

@Override
public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
}

@Override
public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
}

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
}

Sorry If there is a mistake here. I am exhausted due to fighting with this for 2 days. Edit: I tried all of these in possible duplicate questions. None of them helped. Here is my AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tedu.edu.tr">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />                                               
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />                                              
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:allowBackup="false"
  android:theme="@style/AppTheme">
  <meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_tedu" />
  <meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/bluelight" />
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:launchMode="singleTop"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
   android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
 <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
   <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
 <intent-filter>
  <action android:name="com.google.firebase.MESSAGING_EVENT" />
 </intent-filter>
 </service>
 <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
 <intent-filter>
  <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
 </intent-filter>
 </service>
 <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
</application>

</manifest>
like image 590
hayridurmaz Avatar asked Sep 14 '18 08:09

hayridurmaz


2 Answers

Guys one of my project's collaborators deleted package name in MainActivity.java class. It was awful. DO NOT EVER DELETE package name. Adding it again resolved it.

like image 148
hayridurmaz Avatar answered Oct 21 '22 20:10

hayridurmaz


You should look in the AndroidManifest.xml. It seems that it is trying to run a class named MainActivity.java, but your main class is called MainApplication.java. When renaming the MainActivity, renaming should also be made in the AndroidManifest.xml file, where we declare the activity that needs to be launched.

https://www.quora.com/When-developing-Android-applications-do-you-keep-the-main-activity-named-MainActivity-java-or-do-you-change-it-to-something-else

like image 40
Zozinski Avatar answered Oct 21 '22 20:10

Zozinski