Android Studio project works on Lollipop but does not work on Kitkat

后端 未结 3 604
太阳男子
太阳男子 2021-01-15 04:12

I have an Android Studio project that is working fine on devices with Android build version Lollipop but is throwing an exception when trying to run it on a device with andr

3条回答
  •  礼貌的吻别
    2021-01-15 04:51

    This is how I solved the problem if anyone gets here.

    After I searched deeply about the problem, I found out that it's not an inflating exception though that's what the logcat said, the real exception was OutOfMemory exception caused by the infamous 65K problem click here for more information about the problem and it was wrapped with the inflate excpetion.

    To solve the problem, I firstly added the multidex support library in my build.gradle file:

    compile 'com.android.support:multidex:1.0.0'
    

    Then I followed these three simple steps to make it work:

    1. If you’re not implementing an Application class yourself, you can simply define the library’s MultiDexApplication in your Android Manifest file under the application tag:

      android:name="android.support.multidex.MultiDexApplication"

    2. If you are implementing your own Application class, you can either simply override the MultiDexApplication file:

      public class MyAwesomeApplication extends MultiDexApplication {

    3. Or if your application class is already extending another class, you can just override attachBaseContext method and add the following call to it:

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

    I already had my own application class that extends from class "Application" so I jumped directly to step 3 and voila it worked on Kitkat and on Lollipop.

    Hope this helps anyone. Happy Coding.

提交回复
热议问题