获取错误:无法找到类com.google.android.gms.common.GooglePlayServicesUtil.zza引用的类'android.app.AppOpsManager'

jac*_*aal 11 android google-play-services

当我尝试在早于API级别22的手机上运行应用程序时,我收到此错误并导致程序崩溃.但是该应用程序在API级别为22的手机上正常工作.原因可能是什么.

这是我的依赖:

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

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 {
    }
}
Run Code Online (Sandbox Code Playgroud)

感谢帮助

jac*_*aal 17

花了几天时间来解决这个奇怪的问题,终于找到了崩溃的原因.虽然错误仍然存​​在,但程序现在运行没有任何问题.

程序在API级别22下运行正常而不是在21以下的原因是android中的方法限制是65K.21以上本身支持从应用程序APK文件加载多个dex文件,其中21以下没有.文件在这里陈述

此stackoverflow帖子解决了这个问题的解决方案

要么

如果您使用谷歌播放服务,而不是编译整个API,选择性编译可能会有所帮助.你可以在这里找到更多细节.


小智 5

我遵循了jackaal提到的第二种方法.我把整个游戏服务都包含在我的gradle中.删除此并仅选择所需的播放服务后,apis修复了我的问题.

由于游戏服务有很多api,因此总方法数量本身超过65k.因此,这会导致api级别为21及以下的移动设备出错.

在gradle之前: -

compile 'com.google.android.gms:play-services:8.4.0'
Run Code Online (Sandbox Code Playgroud)

格拉德后: -

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'
Run Code Online (Sandbox Code Playgroud)