The problem I am facing is that my android application works well on devices having API 5.0 and above but crashes on devices having Kitkat(4.4) and its corresponding lower versions.I know that its somehow related to the build tools in my gradle file,but still not able to figure out the problem.Could someone please help me out 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 project is built,
Caused by: java.lang.NoClassDefFoundError: com.package.R$styleable
at com.package.widgets.StyleableTextView.<init>(StyleableTextView.java:23)
This is 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 styleable in attrs,
<resources>
<attr name="font" format="string" />
<declare-styleable name="com.package.widgets.StyleableTextView">
<attr name="font" />
</declare-styleable>
</resources>
If your Android apps keep crashing or freezing it's usually because you're low on space or running too many apps at once. Other reasons for crashing apps include a spotty Wi-Fi connection or an old version of the app that hasn't been updated.
There are a few reasons your Android apps might keep crashing, freezing, or not opening. Your device could be running out of storage space, or you might have lost your Wi-Fi or data connection. Apps will usually warn you if these are why an app isn't loading, but it might simply stop working or keep crashing instead.
To fix Android apps that keep crashing: To do this, go to Settings and open Apps. Under Your apps, you'll see a list of the apps currently installed on your device. From the list, tap the app that keeps crashing and tap Force stop in the bottom right corner. Then try opening the app again.
When you are using multidex
, then try to extend your application class with MultiDexAppication
instead of Application
and override below method this required for Android below 5.0 (because 5.0 and above support to the multidex)
@Override
protected void attachBaseContext(Context base)
{
super.attachBaseContext(base);
MultiDex.install(BaseApplication.this);
}
and in dependencies add this
compile 'com.android.support:multidex:1.0.1'
I just had this problem and solved it by adding the following line to the applications AndroidManifest.xml as an attribute on the application tag:
android:name="android.support.multidex.MultiDexApplication"
I have two apps which share the same resources and libraries. The only difference is in the exposed interface. I added multidex to both but forgot to put the above attribute in the manifest for one. The NoClassDefFoundError did not help much at all.
You can also check out the following: http://developer.android.com/tools/building/multidex.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With