6

After Android Studio 2.3 update (and gradle update) if I have instant run activated, and I install app from Android Studio through run or generate signed apk it works fine.

If I manually install the debug apk it immediately crashes on opening, with ClassNotFoundException.

Note: if I remove the reference to the file provider, the class not found becomes the main activity. This issue is with the debug apk that getting generated in Build-->Output-->apk folder. If you run app directly it always run fine.

Without instant run there is no crash. With previous versions of Android Studio there was not crash either.

java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.vfirst.ifbagro-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.vfirst.ifbagro-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4993)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4596)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4536)
at android.app.ActivityThread.access$1300(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5214)
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:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.vfirst.ifbagro-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.vfirst.ifbagro-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.ActivityThread.installProvider(ActivityThread.java:4978)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4596) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4536) 
at android.app.ActivityThread.access$1300(ActivityThread.java:149) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5214) 
at java.lang.reflect.Method.invokeNative(Native Method) 
Grimthorr
  • 6,856
  • 5
  • 41
  • 53
Ravindra Shekhawat
  • 4,275
  • 1
  • 19
  • 26
  • Hasn't [this](http://stackoverflow.com/questions/37312103/unable-to-get-provider-com-google-firebase-provider-firebaseinitprovider) solved your issue? – azizbekian Mar 19 '17 at 14:54
  • no .......I tried every available solution .this issue is specifically with Android studio 2.3 update that came out last week .Please read question again even if I remove that firebase dependency it will show that MainActivity class not found exception and that even come only when i share and run the debug apk so no issue while running the app from from android studio on device its just when you install it from apk that generated in build-->output-->apk folder . – Ravindra Shekhawat Mar 19 '17 at 14:57
  • 1
    Yes. This is true! It seems when instant run is enabled the generated app-debug.apk is incomplete. However disabling instant run, generates a larger complete apk file, installing and running which causes no such issue. – Rohan Shah Mar 23 '17 at 07:44
  • https://code.google.com/p/android/issues/detail?id=262104 – Rohan Shah Mar 23 '17 at 07:55

3 Answers3

0

I had the same error and I solved it with MultiDex add build.gradle multiDexEnabled "true".

  android {
        defaultConfig {
            ...
            minSdkVersion 15 
            targetSdkVersion 25
            multiDexEnabled true
        }
        ...
    }

    dependencies {
      compile 'com.android.support:multidex:1.0.1'

described on this link : https://developer.android.com/studio/build/multidex.html

Santosh Bachkar
  • 460
  • 4
  • 14
0

Try this :

  android {
        defaultConfig {
            minSdkVersion 14 
            targetSdkVersion 25
            multiDexEnabled true
        }
    }

    dependencies {
      compile 'com.android.support:multidex:1.0.1'

this code into your manifest :

   <application
       ...
       android:name="android.support.multidex.MultiDexApplication">
       ...
   </application>

If you use custom application class, use this code :

public class YouApplication extends Application {

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

}

and then for manifest :

   <application
       ...
       android:name="YOUR_PACKAGE.YouApplication">
       ...
   </application>

I hope help you my friend

Mohammad Nouri
  • 2,245
  • 4
  • 17
  • 34
  • This is related to instant run as it work without instant run but not with instant run . – Ravindra Shekhawat May 11 '17 at 08:06
  • You added this codes into your codes and when generate APK not problem in real device, instant run bug just for virtual devices. add above codes into your project and disable Instant run adn build generate – Mohammad Nouri May 11 '17 at 10:45
  • I have checked this solution long time back on many question .Follow the steps I have written and this issue is already reported in android issue tracker .I can understand you provided solution on basis of stack trace . But the actual issue is in my question not in stack trace . – Ravindra Shekhawat May 11 '17 at 11:58
-2

As for me I tried the following : Try to check if your phone's Auto-start Manager allows your app to auto-start. By allowing your app to auto-start I think will help in fixing the Instant-run Problem. Hope's this helps.