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

后端 未结 3 603
太阳男子
太阳男子 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:49

    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'
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-15 04:59

    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 .

    0 讨论(0)
提交回复
热议问题