idratherbeintheair idratherbeintheair - 12 days ago 7
Android Question

Android Studio 2.0 Application crash on unmodified Application class

I have a really weird Android Studio 2.0 problem. If I edit my application class file, even just adding a couple of spaces, my app launches just fine. If I don't edit it, it crashes with:

11-23 18:17:44.694 30811-30811/******.******.com.****** E/AndroidRuntime: FATAL EXCEPTION: main
Process: ******.******.com.******, PID: 30811
java.lang.RuntimeException: Unable to instantiate application ******.******.com.******.application.******: java.lang.ClassNotFoundException: Didn't find class "******.******.com.******.application.******" on path: DexPathList[[zip file "/data/app/******.******.com.******-2.apk"],nativeLibraryDirectories=[/data/app-lib/******.******.com.******-2, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:507)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "******.******.com.******.application.******" on path: DexPathList[[zip file "/data/app/******.******.com.******-2.apk"],nativeLibraryDirectories=[/data/app-lib/******.******.com.******-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:998)
at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382) 
at android.app.ActivityThread.access$1500(ActivityThread.java:139) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5086) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method) 


Here's my application class:

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

public class MyApplication extends Application {

private static Context context;

@Override
public void onCreate() {
super.onCreate();

context = this;
}

public static Context getContext() {
return context;
}

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


and here's my module
build.gradle
file:

buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}

dependencies {
classpath 'io.fabric.tools:gradle:1.20.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
apply plugin: 'io.fabric'

repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}


android {
compileSdkVersion 23
buildToolsVersion '23.0.2'

signingConfigs {
release {
keyAlias *********
keyPassword **********
storePassword ***********
storeFile **********
}
}

lintOptions {
abortOnError false
}

defaultConfig {
applicationId ***************
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.release
}
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}

dexOptions {
javaMaxHeapSize "4g"
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':boilerplate')
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.code.gson:gson:2.4'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.github.blackfizz:eazegraph:1.2.5l'
compile 'it.sephiroth.android.library.imagezoom:imagezoom:2.2.2'
compile 'com.isseiaoki:simplecropview:1.0.8'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services-ads:8.3.0'
compile 'com.baoyz.swipemenulistview:library:1.3.0'
compile 'joda-time:joda-time:2.9.1'
}


Here's my manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="******" >

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

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />


<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>

<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".activities.LaunchActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- Activities, etc. -->

</application>

</manifest>


Anyone had this issue before? It's is if it's not compiling the application file unless it's changed.

Answer

Looks like this was just a bug. Closing now.