java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / android / gms / common / GoogleApiAvailabilityLight;

时间:2018-11-28 09:25:32

标签: java android android-studio gradle android-gradle

我有一个Android Studio项目,该项目由多个模块组成,并具有多个具有依赖性的gradle文件。

项目已编译,但是在运行时,当应用程序调用Google Play服务库时,它会由于以下堆栈跟踪而崩溃:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/GoogleApiAvailabilityLight;
    at com.bosch.wdw.impl.d.g.d(Unknown Source:3088)
    at com.bosch.wdw.impl.d.a(Unknown Source:90)
    at com.bosch.wdw.impl.e.startMonitoring(Unknown Source:122)
    at com.warptec.widgets.WDWTask.startWDWMonitoring(WDWTask.java:199)
    at com.warptec.widgets.WDWTask.permissionForLocation(WDWTask.java:175)
    at com.warptec.widgets.WDWTask.performTask(WDWTask.java:158)
    at com.warptec.widgets.TaskBase$2.run(TaskBase.java:124)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6938)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.GoogleApiAvailabilityLight" on path: DexPathList[[zip file "/data/app/com.warptec.widgets-H5zUVpqwHV8OyTqLouF8ng==/base.apk"],nativeLibraryDirectories=[/data/app/com.warptec.widgets-H5zUVpqwHV8OyTqLouF8ng==/lib/arm, /data/app/com.warptec.widgets-H5zUVpqwHV8OyTqLouF8ng==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.bosch.wdw.impl.d.g.d(Unknown Source:3088) 
    at com.bosch.wdw.impl.d.a(Unknown Source:90) 
    at com.bosch.wdw.impl.e.startMonitoring(Unknown Source:122) 
    at com.warptec.widgets.WDWTask.startWDWMonitoring(WDWTask.java:199) 
    at com.warptec.widgets.WDWTask.permissionForLocation(WDWTask.java:175) 
    at com.warptec.widgets.WDWTask.performTask(WDWTask.java:158) 
    at com.warptec.widgets.TaskBase$2.run(TaskBase.java:124) 
    at android.os.Handler.handleCallback(Handler.java:789) 
    at android.os.Handler.dispatchMessage(Handler.java:98) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6938) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 

应用程序的模块gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.warptec.widgets"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        ndk {
            abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
        }
    }
    lintOptions {
        abortOnError false
        disable "ResourceType", "ValidFragment", "WifiManagerLeak", "MissingTranslation"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.so', '*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
     })
     /**
     * Library file of the SDK, delivered as aar-library
     */
     compile(name: 'wdwsdk-4.0.1', ext: 'aar')
     compile 'com.google.android.exoplayer:exoplayer-core:r2.4.0'
     compile project(':lChainRunnables')
     compile project(':lClosedSource')
     compile project(':lSpoledgeAAC')
     compile project(':IChromecast')
     compile files('libs/Pushwoosh.jar')
     compile 'com.android.support:support-v4:26.0.0-alpha1'
     compile 'com.android.support:appcompat-v7:26.0.0'
     compile 'com.google.android.gms:play-services:12.0.1'
}

IChromecasts模块的gradle文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile "com.android.support:mediarouter-v7:26.0.1"
    compile "com.google.android.gms:play-services-cast-framework:12.0.1"

}

这是顶级gradle文件:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        flatDir {
            dirs 'libs'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        flatDir {
            dirs 'libs'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

任何帮助都将得到感谢。谢谢。

1 个答案:

答案 0 :(得分:1)

1-将此添加到您的gradle中:

    implementation 'com.android.support:multidex:1.0.3'

2-并更改GooglePlayService的版本:

 implementation 'com.google.android.gms:play-services-maps:12.0.1'
 implementation 'com.google.android.gms:play-services-auth:12.0.1'
 implementation 'com.google.android.gms:play-services-location:12.0.1'
 implementation 'com.google.android.gms:play-services:12.0.1'
 implementation 'com.google.android.gms:play-services-ads:12.0.1'

3-尝试将其添加到您的gradle中:

allprojects {
  repositories {
   }

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.google.android.gms'
            && !details.requested.name.contains('multidex') ) {
                details.useVersion "12.0.1"
            }
        }
    }
}
}

快乐编码:)