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

五迷三道 提交于 2019-12-01 11:31:16

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.

The main issue is that your compileSdkVersion does not match major version of support libraries you include with the project. Follow these rules:

Set targetSdkVersion to 22 because you want to use Lollipop features on Lollipop devices (and don't care about Marshmallow for now).

Set compileSdkVersion to 23 because it's the newest.

Set buildToolsVersion to "23.0.1" because it's the newest.

Set support library versions to the latest matching compileSdkVersion:

compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'

Okay . At first call fill_parent .

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:overScrollMode="never" />

And use this instead of yours .

compile 'com.android.support:support-v4:21.0.3'

set targetSdkVersion 19

Edit1

you set

compileSdkVersion 23
buildToolsVersion "23.0.1"

and

targetSdkVersion 23

I hope it will helps you .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!