Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza

I receive this error and program crashes when I try to run the app on phone with older than API level 22. However the app works fine on phone with API level 22. What could be the reason for that.

here is my dependencies:

dependencies 
{
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.facebook.android:facebook-android-sdk:4.3.0'
    compile 'com.google.android.gms:play-services-analytics:7.5.0'

    compile project(':volley')
    compile project(':adjust_SDK')
    compile project(':euromessageLib')
    compile project(':com_viewpagerindicator')

    compile files('libs/adxtag3.2.6.jar')
    compile files('libs/jsoup-1.7.3.jar')
    compile files('libs/CWAC-Adapter.jar')
    compile files('libs/newrelic.android.jar')
    compile files('libs/android-query-full.0.26.8.jar')
    compile files('libs/khandroid-httpclient-4.2.3.jar')
    compile files('libs/GoogleConversionTrackingSdk-2.2.1.jar')

    compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
        transitive = true;
    }
}

and

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "com.deneme"
        minSdkVersion 14
        targetSdkVersion 22
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles 'proguard.cfg'
        }
    }
    productFlavors {
    }
}

thanks for help

like image 820
jackaal Avatar asked Jul 10 '15 13:07

jackaal


2 Answers

After spending couple of days to solve this strange problem, Finally found the cause of the crash. Although the error persists, program runs without any problem now.

The reason why the program runs fine with API level 22 and not not with below 21 is the method limit in android which is 65K. Above 21 natively supports loading multiple dex files from application APK files where below 21 does not. Documents states it here

The solution for this problem is solved at this stackoverflow post

or

if you use google play services, instead of compiling the whole APIs, selectively compile may help. You can find more details here.

like image 106
jackaal Avatar answered Sep 24 '22 12:09

jackaal


I followed the 2nd approach mentioned by jackaal. I had included the whole play services in my gradle. After removing this and selecting only the required play services apis fixed my problem.

Since the play services has a lot of apis, the total method count is beyond 65k by itself. So this causes error in mobiles with api level 21 and below.

Before gradle:-

compile 'com.google.android.gms:play-services:8.4.0'

After gradle:-

compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-plus:8.4.0'
like image 20
wittyurchin Avatar answered Sep 21 '22 12:09

wittyurchin