Juan Acevedo
Juan Acevedo

Reputation: 1788

Java.lang.ClassCastException: Android.support.v7.widget.ContentFrameLayout cannot be cast to Android.support.v7.widget.ContentFrameLayout

There are times when I install my Android app and I get the following exception but this isn't always reproducible.

java.lang.ClassCastException: android.support.v7.widget.ContentFrameLayout cannot be cast to android.support.v7.widget.ContentFrameLayout

I am using multidex on my Android app and I read this question about Samsung devices having a bug with the multidex implementation but this happens on LG G3 running 5.1 and an HTC A9 running 6.0.

Anyone have any ideas why this is randomly happening and what can I do to fix it?

EDIT: I can't share much of the code because this is for a company I work for.

buildscript {
repositories {
    mavenCentral()
}

dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}

}

apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt'

buildscript { repositories { mavenCentral() }

dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}

}

apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt'

repositories { mavenCentral() maven { url 'https://repository-achartengine.forge.cloudbees.com/snapshot' } maven { url 'libs-localrepository' } }

android { buildToolsVersion "23.0.2" compileSdkVersion 23

dexOptions {
    javaMaxHeapSize "4g"
}

defaultConfig {
    minSdkVersion 18
    targetSdkVersion 23
    multiDexEnabled true
}

packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/INDEX.LIST'
}

lintOptions {
    ignore 'ProtectedPermissions'
}

signingConfigs {

    release {
        storeFile file("somepath...")
        storePassword System.getenv("some_password")
        keyAlias "release"
        keyPassword System.getenv("some_password")
    }
}

buildTypes {

    release {
        minifyEnabled false
        proguardFile getDefaultProguardFile('proguard-android.txt')
        proguardFile 'proguard-config.txt'
    }

    debug {
        minifyEnabled false
        proguardFile getDefaultProguardFile('proguard-android.txt')
        proguardFile 'proguard-config.txt'
    }
}

dependencies {

    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.0'
    compile 'com.android.support:preference-v14:23.1.0'

    compile ('com.m.c:CE:1.0') {
        changing=true
    }

    compile ('com.m.c:APL:1.0') {
        changing=true
    }

    compile ('c.m.c:C:1.0') {
        changing=true
    }

    debugCompile 'ch.acra:acra:4.5.0'

    compile files('libs-gradle/aM.jar')
    compile files('libs-gradle/android-logging-log4j-m-1.0.3.jar')
    compile files('libs-gradle/ce.jar')
    compile 'com.google.android.gms:play-services-analytics:8.4.0'

    apt 'com.squareup.dagger:dagger-compiler:1.2.2'

}

}

apply plugin: 'com.google.gms.google-services'

Upvotes: 7

Views: 2791

Answers (2)

Juan Acevedo
Juan Acevedo

Reputation: 1788

I found that the issue was with a flag that was set in the manifest for having a persistent process. My app is a system app loaded by the manufacturer and when an update happens, which kills the app, android os relaunches the old process thus resulting in odd behavior. My solution ended up having to change class names and android manifest components to use those new class names and let the other persistent process just hang around after the update. After the app is killed once or the phone is rebooted, those processes die and are never launched again. I also removed the flag for persistent process.

Upvotes: 1

Dinash
Dinash

Reputation: 3047

Sometime back we faced similar kind of problem, we added

    android {
        dexOptions {
          jumboMode = true
        }
    }

in build.gradle and extended Application class to MultiDexApplication, Please try whether this helps you.

Upvotes: 0

Related Questions