Application error in Android API less than 5.0 (lollipop)

The problem I am facing is that my Android application works fine on devices with API 5.0 and higher, but it crashes on devices that have Kitkat (4.4) and its corresponding lower versions. I know that its somehow related to the build tools in my gradle, but still not able to figure out the problem. Can someone please help me with this.

This is my gradle file,

buildscript { repositories { maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'io.fabric.tools:gradle:1.+' } } apply plugin: 'com.android.application' apply plugin: 'io.fabric' apply plugin: 'android' repositories { maven { url 'https://maven.fabric.io/public' } maven { url 'http://clinker.47deg.com/nexus/content/groups/public' } } android { compileSdkVersion 22 buildToolsVersion '22.0.1' defaultConfig { applicationId "com.abc.example" minSdkVersion 10 targetSdkVersion 22 multiDexEnabled true versionCode 12 versionName "1.0" } buildTypes { release { multiDexEnabled true minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } android { packagingOptions { exclude 'META-INF/LICENSE' } } android { packagingOptions { exclude 'META-INF/NOTICE' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:22.2.0' compile('com.fortysevendeg.swipelistview:swipelistview: 1.0-SNAPSHOT@aar ') { transitive = true exclude module: 'httpclient' exclude group: 'httpclient' } compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.okhttp:mockwebserver:2.3.0' compile 'de.hdodenhof:circleimageview:1.2.2' compile 'com.android.support:multidex:1.0.1' compile 'com.google.android.gms:play-services-maps:7.5.0' compile files('libs/bitlyj-2.0.0.jar') } 

Also getting this error when building a project,

 Caused by: java.lang.NoClassDefFoundError: com.package.R$styleable at com.package.widgets.StyleableTextView.<init>(StyleableTextView.java:23) 

This is the StyleableTextView class,

 public class StyleableTextView extends TextView { public StyleableTextView(Context context) { super(context); } public StyleableTextView(Context context, AttributeSet attrs) { super(context.getApplicationContext(), attrs); UiUtil.setCustomFont(StyleableTextView.this, context, attrs, R.styleable.com_eywa_wonk_widgets_StyleableTextView, R.styleable.com_eywa_wonk_widgets_StyleableTextView_font); } public StyleableTextView(Context context, AttributeSet attrs, int defStyle) { super(context.getApplicationContext(), attrs, defStyle); UiUtil.setCustomFont(StyleableTextView.this, context, attrs, R.styleable.com_eywa_wonk_widgets_StyleableTextView, R.styleable.com_eywa_wonk_widgets_StyleableTextView_font); } } 

This is the style in attrs,

 <resources> <attr name="font" format="string" /> <declare-styleable name="com.package.widgets.StyleableTextView"> <attr name="font" /> </declare-styleable> </resources> 
+6
source share
4 answers

When you are using multidex , try extending the application class with MultiDexAppication instead of Application and overriding below the method that is required for Android below 5.0 (since support is 5.0 and above for multidex)

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

and in the dependencies add this

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

+24
source

I had this problem and I decided to add it by adding the following line to AndroidManifest.xml applications as an attribute in the application tag:

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

I have two applications that have the same resources and libraries. The only difference is the open interface. I added multidex to both, but forgot to put the above attribute in the manifest for one. NoClassDefFoundError nothing helped.

You can also check the following: http://developer.android.com/tools/building/multidex.html

+3
source

One problem you may encounter is the one described in the documentation :

 multiDexEnabled true 

Applications that use multidex may not run on devices that run platform versions earlier than Android 4.0 (API level 14) due to a Dalvik linearAlloc error (release 22586). If you are targeting API levels earlier than 14, be sure to test using these versions of the platform, as your application may have problems running or loading certain class groups. Code reduction can reduce or possibly eliminate these potential problems.

+1
source

Perhaps this does not apply to a specific scenario, but since the title of the question refers to the problem that I encountered, and the reason why I came across this question. Therefore, I answer it here. I ran into a problem similar to this problem, but in my case the multidexapplication extension and the inclusion of multidex did not work. I ended up using a plugin to count methods in my project. Using this, I realized that I'm not quite close to the 65K limit, and the error is related to something else. I found this page where they talked about disabling instant launch from the settings, which actually did the job for me. Now I do not use the multi-dex library, and assemblies are faster. If I run into a problem again, I will update the answer accordingly.

0
source

All Articles