Android app closes immediately after launching

21,615

Essentially what is happening is your application is unable to find the class it's looking for in the compiled APK and is crashing.

This can happen for several reasons.

Try this first

The most common I've found is that the IDE has messed up its build cache somewhere. In this case: restart Android Studio, clear the cache, and rebuild the project.

Try this second

It's also possible that you have enough methods that you're pushing the Android method limit (see this), in which case you'll have to enable multidex in your application or use Proguard to minimize your app (this is more complicated, but start here).

Share:
21,615
Admin
Author by

Admin

Updated on November 30, 2022

Comments

  • Admin
    Admin over 1 year

    I'm trying to finish off my app for publishing on the google play store so uploaded to the alpha testing phase. When trying to launch the app it closes immediately and this is the error that I receive:

    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.FinalFrontier.MoonLanding/com.FinalFrontier.MoonLanding.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.FinalFrontier.MoonLanding.MainActivity" on path: DexPathList[[zip file "/data/app/com.FinalFrontier.MoonLanding-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.FinalFrontier.MoonLanding-1, /vendor/lib, /system/lib]]
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2192)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
    at android.app.ActivityThread.access$600(ActivityThread.java:150)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:213)
    at android.app.ActivityThread.main(ActivityThread.java:5225)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.FinalFrontier.MoonLanding.MainActivity" on path: DexPathList[[zip file "/data/app/com.FinalFrontier.MoonLanding-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.FinalFrontier.MoonLanding-1, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2183)
    ... 11 more
    

    ​ This is my first ever app and I'm pretty new to this so any help would be greatly appreciated. I've read the documentation and searched the errors online however can't seem to get any of the solutions to work. Here's a copy of my android manifest.

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="2" android:versionName="1.1" package="com.FinalFrontier.MoonLanding" android:installLocation="preferExternal">
    <application android:icon="@drawable/app_icon" android:label="@String/app_name" android:debuggable="false" android:isGame="true" android:banner="@drawable/app_banner">
    <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="@String/app_name" android:name="com.FinalFrontier.MoonLanding.CustomActivity">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
    </intent-filter>
    </activity>
    <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:hardwareAccelerated="true" android:name="com.unity3d.ads.android.view.UnityAdsFullscreenActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" xmlns:tools="http://schemas.android.com/tools" tools:ignore="UnusedAttribute" />
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
    <uses-feature android:glEsVersion="0x00020000" />
    <uses-feature android:name="android.hardware.sensor.accelerometer" android:required="false" />
    <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
    <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
    <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
    </manifest>
    

    Anybody got any ideas? Thanks in advance.

    • Jim Garrison
      Jim Garrison about 8 years
      Didn't find class "com.FinalFrontier.MoonLanding.MainActivity" looks pretty explicit
    • Roy Falk
      Roy Falk about 8 years
      It's been a long day but the manifest says the name of the main activity is com.FF.ML.CustomActivity. Should it be complaining about not finding it instead?
    • dzikovskyy
      dzikovskyy about 8 years
      Try to remove android:installLocation="preferExternal" from manifest file.