Android Studio project works on Lollipop, but not on Kitkat

I have an Android Studio project that works fine on devices with the Android version of the Lollipop build, but throws an exception when trying to run it on a device with the Kitkat version for Android. This is the build.gradle project file:

android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { minSdkVersion 16 targetSdkVersion 21 versionCode 1 versionName "1.0" multiDexEnabled true renderscriptTargetApi 22 renderscriptSupportModeEnabled true } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile files('libs/org.apache.commons.io.jar') compile files('libs/commons-codec-1.10.jar') compile('com.twitter.sdk.android:twitter: 1.6.0@aar ') { transitive = true; } compile files('libs/pinit-sdk-1.0.jar') compile project(':bounceScroller') compile 'com.ogaclejapan.smarttablayout:library: 1.2.1@aar ' compile 'com.facebook.android:facebook-android-sdk:4.1.0' compile 'com.android.support:appcompat-v7:21.2.0' compile 'com.github.navasmdc:MaterialDesign: 1.5@aar ' compile 'com.nineoldandroids:library:2.4.+' compile 'com.esri.arcgis.android:arcgis-android:10.2.6-2' compile 'com.github.clans:fab:1.5.3' compile 'com.github.pedrovgs:draggablepanel:1.8' compile 'com.android.support:support-v4:21.2.0' compile 'com.ogaclejapan.smarttablayout:utils-v4: 1.2.1@aar ' compile 'com.github.bumptech.glide:glide:3.6.0' compile project(':rangeseekbar') compile 'com.android.support:recyclerview-v7:22.2.0' compile 'com.android.support:cardview-v7:22.2.0' compile project(':blurry') compile 'com.google.android.gms:play-services:7.8.0' } 

and here is the error I get when running the application on the Kitkat device:

 java.lang.RuntimeException: Unable to start activity: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v4.view.ViewPager at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363) at android.app.ActivityThread.access$900(ActivityThread.java:161) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5356) 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:1265) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v4.view.ViewPager at android.view.LayoutInflater.createView(LayoutInflater.java:626) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) at android.view.LayoutInflater.inflate(LayoutInflater.java:498) at android.view.LayoutInflater.inflate(LayoutInflater.java:398) at android.view.LayoutInflater.inflate(LayoutInflater.java:354) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359) at android.app.Activity.setContentView(Activity.java:2010) at android.visitabudhabi.com.vad.Walkthrough.onCreate(Walkthrough.java:32) at android.app.Activity.performCreate(Activity.java:5426) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)            at android.app.ActivityThread.access$900(ActivityThread.java:161)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:157)            at android.app.ActivityThread.main(ActivityThread.java:5356)            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:1265)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)            at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at android.view.LayoutInflater.createView(LayoutInflater.java:600)            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)            at android.app.Activity.setContentView(Activity.java:2010)            at android.visitabudhabi.com.vad.Walkthrough.onCreate(Walkthrough.java:32)            at android.app.Activity.performCreate(Activity.java:5426)            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)            at android.app.ActivityThread.access$900(ActivityThread.java:161)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:157)            at android.app.ActivityThread.main(ActivityThread.java:5356)            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:1265)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)            at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NoClassDefFoundError: android.support.v4.view.ViewConfigurationCompatFroyo at android.support.v4.view.ViewConfigurationCompat$FroyoViewConfigurationVersionImpl.getScaledPagingTouchSlop(ViewConfigurationCompat.java:56) at android.support.v4.view.ViewConfigurationCompat.getScaledPagingTouchSlop(ViewConfigurationCompat.java:105) at android.support.v4.view.ViewPager.initViewPager(ViewPager.java:368) at android.support.v4.view.ViewPager.<init>(ViewPager.java:356)            at java.lang.reflect.Constructor.constructNative(Native Method)            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)            at android.view.LayoutInflater.createView(LayoutInflater.java:600)            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)            at android.app.Activity.setContentView(Activity.java:2010)            at android.visitabudhabi.com.vad.Walkthrough.onCreate(Walkthrough.java:32)            at android.app.Activity.performCreate(Activity.java:5426)            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)            at android.app.ActivityThread.access$900(ActivityThread.java:161)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:157)            at android.app.ActivityThread.main(ActivityThread.java:5356)            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:1265)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)            at dalvik.system.NativeStart.main(Native Method) 

This is my XML that has a ViewPager:

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="wrap_content" android:overScrollMode="never" /> <LinearLayout android:layout_width="match_parent" android:layout_height="5dp" android:layout_below="@+id/pager" android:layout_gravity="bottom" android:orientation="horizontal"> <ImageView android:id="@+id/first" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3.3" android:background="#c7333f" /> <ImageView android:id="@+id/second" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3.3" android:background="#FFF" /> <ImageView android:id="@+id/third" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3.3" android:background="#fff" /> </LinearLayout> </FrameLayout> 

Does anyone know how to solve this?

+5
source share
3 answers

This is how I solved the problem if someone got here.

After I deeply dealt with the problem, I found that this was not an inflatable exception, although what logcat said, the real exception was the OutOfMemory exception caused by the notorious 65K problem, click here to get more information about this problem , and she was wrapped by exhumation of inflation.

To solve this problem, I first added the multidex support library to the build.gradle file:

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

Then I followed these three simple steps to get it working:

  • If you do not implement the application class yourself, you can simply define the MultiDexApplication libraries in your Android manifest file in the application tag:

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

  • If you implement your own application class, you can simply override the MultiDexApplication file:

    Public class MyAwesomeApplication extends MultiDexApplication {

  • Or, if your application class is already extending another class, you can simply override the 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, which extends from the Application class, so I jumped directly to step 3, and voila worked on Kitkat and Lollipop.

Hope this helps anyone. Happy coding.

+15
source

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

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

Set compileSdkVersion to 23 because it is the newest.

Set buildToolsVersion to "23.0.1" because it is the newest.

Install the supporting library versions for the latest compatible compileSdkVersion command:

 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' 
+1
source

Good. 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 it 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 

Hope this helps you.

0
source

Source: https://habr.com/ru/post/1234461/


All Articles