java.lang.NoClassDefFoundError:解析失败:Lcom / google / android / gms / common / R $ string;

时间:2018-05-16 08:27:46

标签: java android noclassdeffounderror

德语:Hallo Leute, Ich habe schon vieles ausprobiert,aber bisher nochkeineLösunggefunden。 Ich bekomme immer den imTitelerwähntenFehler。 Unten habe ich die代码mal reinkopiert。

英语:大家好 首先,对不起我的英语,我是德国人。我尝试了很多东西,但它并没有解决我的问题。

完整错误代码(kompletter错误代码):

05-16 09:59:53.428 25010-25010/main.faseflex.de.fgnapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: main.faseflex.de.fgnapp, PID: 25010
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string;
    at com.google.android.gms.common.internal.StringResourceValueReader.<init>(Unknown Source:14)
    at com.google.firebase.FirebaseOptions.fromResource(Unknown Source:2)
    at com.google.firebase.FirebaseApp.initializeApp(Unknown Source:19)
    at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source:4)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1925)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1900)
    at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:23)
    at android.app.ActivityThread.installProvider(ActivityThread.java:6578)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6133)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6043)
    at android.app.ActivityThread.-wrap1(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    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.R$string" on path: DexPathList[[zip file "/data/app/main.faseflex.de.fgnapp-C4iBOV7sIO2cNc4pfCATmA==/base.apk"],nativeLibraryDirectories=[/data/app/main.faseflex.de.fgnapp-C4iBOV7sIO2cNc4pfCATmA==/lib/arm64, /system/lib64, /system/vendor/lib64]]
    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.google.android.gms.common.internal.StringResourceValueReader.<init>(Unknown Source:14) 
    at com.google.firebase.FirebaseOptions.fromResource(Unknown Source:2) 
    at com.google.firebase.FirebaseApp.initializeApp(Unknown Source:19) 
    at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source:4) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1925) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1900) 
    at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:23) 
    at android.app.ActivityThread.installProvider(ActivityThread.java:6578) 
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6133) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6043) 
    at android.app.ActivityThread.-wrap1(Unknown Source:0) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764) 
    at android.os.Handler.dispatchMessage(Handler.java:105) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6944) 
    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) 

build.gradle app:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    //buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "main.faseflex.de.fgnapp"
        minSdkVersion 21
        targetSdkVersion 25
        multiDexEnabled true
        dexOptions {
            preDexLibraries true
        }
        versionCode 1
        versionName "0.98.41"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            multiDexKeepFile file('multidex-config.txt')
        }

    }
    productFlavors {
    }
}

dependencies {
    implementation 'com.android.support:support-v4:25.4.0'
    implementation 'com.android.support:support-vector-drawable:25.4.0'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.google.firebase:firebase-core:15.0.2'
    implementation 'com.google.firebase:firebase-messaging:15.0.2'
    implementation 'com.google.firebase:firebase-database:15.0.1'
    implementation 'com.google.firebase:firebase-auth:15.1.0'
    implementation 'com.android.support:appcompat-v7:25.4.0'
    implementation 'com.android.support:design:25.4.0'
    implementation 'com.android.support:preference-v7:25.4.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.github.SHashank02051997:FancyToast-Android:0.1.3'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    testImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}

build.gradle项目:

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

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.2.0'

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

allprojects {
    repositories {
        jcenter()
        google()
        maven {
            url "https://jitpack.io"
        }
        maven {
            url "https://maven.google.com"
        }
    }
}

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

的AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="main.faseflex.de.fgnapp"
    tools:node="replace">

    <supports-screens
        android:anyDensity="true"
        android:compatibleWidthLimitDp="50"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="false"
        android:smallScreens="false"
        android:xlargeScreens="false" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/fgn_icon"
        android:label="@string/app_name"
        android:resizeableActivity="false"
        android:roundIcon="@mipmap/fgn_icon"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        ------------------------------------------------
        MAIN ACTIVITY
        ------------------------------------------------
        <activity
            android:name=".FGNmainActivity"
            android:label="FGN-App"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        STUNDENPLAN
        ------------------------------------------------
        <activity
            android:name=".activity_timetable"
            android:label="FGN-App | Stundenplan"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        ESSENSBESTELLUNG
        ------------------------------------------------
        <activity
            android:name=".activity_food"
            android:label="FGN-App | Essenplan"
            android:parentActivityName=".FGNmainActivity"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        MDV
        ------------------------------------------------
        <activity
            android:name=".activity_mdv"
            android:label="FGN-App | Verkehrsverbund"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        DOKUMENTE
        ------------------------------------------------
        <activity
            android:name=".activity_documents"
            android:label="FGN-App | Dokumente"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        NEWS
        ------------------------------------------------
        <activity
            android:name=".activity_news"
            android:label="FGN-App | News"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        LEHRER
        ------------------------------------------------
        <activity
            android:name=".activity_teachers"
            android:label="FGN-App | Lehrer"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        MOODLE
        ------------------------------------------------
        <activity
            android:name=".activity_moodle"
            android:label="FGN-App | Moodle"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        OFFICE 365
        ------------------------------------------------
        <activity
            android:name=".activity_office"
            android:label="FGN-App | Office 365"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        KONTAKT
        ------------------------------------------------
        <activity
            android:name=".activity_contact"
            android:label="FGN-App | Kontakt"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        TERMINE
        ------------------------------------------------
        <activity
            android:name=".activity_termine"
            android:label="FGN-App | Termine"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        MITTAGSBAND
        ------------------------------------------------
        <activity
            android:name=".activity_mittagsband"
            android:label="FGN-App | Mittagsband"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.APP_BROWSER" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        FEEDBACK
        ------------------------------------------------
        <activity
            android:name=".activity_menu_feedback"
            android:label="FGN-App | Feedback"
            android:parentActivityName=".SettingsActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        IMPRESSUM
        ------------------------------------------------
        <activity
            android:name=".activity_menu_impressum"
            android:label="FGN-App | Impressum"
            android:parentActivityName=".FGNmainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />

                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        FIREBASE
        ------------------------------------------------
        <service android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <service android:name=".FirebaseIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
        <service android:name=".MyInstanceIDListenerService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
        ------------------------------------------------
        EINSTELLUNGEN
        ------------------------------------------------
        <activity
            android:name=".SettingsActivity"
            android:label="FGN-App | Einstellungen"
            android:parentActivityName=".FGNmainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="main.faseflex.de.fgnapp.FGNmainActivity" />
        </activity>
        ------------------------------------------------
        SPLASH SCREEN
        ------------------------------------------------
        <activity
            android:name=".SplashActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        ------------------------------------------------
        CHANGELOG
        ------------------------------------------------
        <activity
            android:name=".ChangelogActivity"
            android:label="FGN-App | Changelog"
            android:parentActivityName=".SettingsActivity"></activity>
    </application>



</manifest>

德语:Ichweiß,wie der NoClassDefFoundError zustande kommt,aber ich habe das问题nicht gefunden。 Sagt,wenn ihr noch weitere DateienzurLösungdesProblems braucht。 Schonmal danke im Voraus。

英语:我知道NoClassDefFoundError的作用,但我没有发现问题。询问您是否需要更多文件来解决问题。

11 个答案:

答案 0 :(得分:38)

如果您在应用中使用 Realm插件,则可以尝试 升级插件,因为这是应用程序在崩溃时崩溃的原因之一 运行中。


更新领域插件的步骤:

  • 打开build.gradle(Project: Project_name_here)文件。
  • 使用latest stable version替换领域gradle插件的类路径,如下所示:
  • classpath "io.realm:realm-gradle-plugin:7.0.0"


另外,请检查build.gradle文件中是否有任何过期的插件,因为这可能是应用程序崩溃的原因之一。


OR

在将Android Studio升级到 3.6.0版后,我遇到了类似的问题

降级我的等级到3.5.3 ,以便解决此问题,直到将来解决。


步骤:

  • 打开build.gradle(Project: Project_name_here)文件。
  • 替换android工具的类路径可在依赖项下构建gradle,并具有以下内容:
  • classpath 'com.android.tools.build:gradle:3.5.3'



请注意:这是一个临时修复程序。将来可能会修复,因此请在此之前降级并继续进行应用程序开发。

答案 1 :(得分:17)

如果您刚刚将项目更新为Gradle 3.6.0,并且正在使用 Realm ,则此问题很有可能是由 Realm插件引起的。 根据{{​​3}}评论,此问题发生在小于5.13.1的旧Realm插件版本中。 因此,仅更新到最新的Realm版本将最有可能解决问题。

截至撰写本文时,它是: classpath "io.realm:realm-gradle-plugin:6.1.0"

答案 2 :(得分:4)

2020年8月5日-已解决..!

您必须更新 REALM-PLUGIN ,并且需要在 顶级Gradle(项目:Gradle)中编写此代码> ,复制粘贴到“ classpath ”行以下:

buildscript {
  ... 
  dependencies {
    classpath 'io.realm:realm-gradle-plugin:7.0.0' //<--Your answer.
  }
}

@canerkaseler

答案 3 :(得分:3)

嗨,我知道问题的后期,但是对于当前的android版本,我解决了这个问题。

关于build.grade项目级别的依赖项,更新您的内容:

在build.grade应用程序级别上更新您的依赖项

此问题的一些答案涉及multidex和其他修复程序,但没有一个为我解决。

这就是为什么做出这个答案的原因。

我当前的设置:

项目级

dependencies {
   classpath 'com.android.tools.build:gradle:4.0.0'
   classpath "io.realm:realm-gradle-plugin:6.0.2"
   classpath 'com.google.gms:google-services:4.3.3'
}

应用级

dependencies {
  implementation fileTree(include: ['*.jar'], dir: 'libs')
  implementation 'androidx.core:core:1.3.0'
  implementation 'androidx.annotation:annotation:1.1.0'
  implementation 'androidx.appcompat:appcompat:1.1.0'
  implementation 'com.google.android.material:material:1.1.0'
  implementation 'com.android.volley:volley:1.1.1'
  implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  implementation 'androidx.recyclerview:recyclerview:1.0.0'
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'androidx.test:runner:1.2.0'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  implementation 'com.facebook.android:facebook-login:5.15.3'
  implementation "com.google.android.gms:play-services-location:17.0.0"
  implementation 'com.google.code.gson:gson:2.8.5'
  implementation 'com.squareup.picasso:picasso:2.71828'
  implementation 'commons-validator:commons-validator:1.6'
  implementation 'com.appeaser.sublimepickerlibrary:sublimepickerlibrary:2.1.2'
  implementation 'de.hdodenhof:circleimageview:2.2.0'
  implementation 'com.google.maps.android:android-maps-utils:0.5+'
  implementation 'com.google.android.gms:play-services-maps:17.0.0'
  implementation 'com.evrencoskun.library:tableview:0.8.8'
  implementation 'androidx.multidex:multidex:2.0.1'
  implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'
  implementation 'com.google.firebase:firebase-core:17.4.3'
  implementation 'com.facebook.android:facebook-share:5.15.3'
  implementation('com.smartlook.recording:app:1.1.0-native')
}

希望我能帮上忙!

答案 4 :(得分:1)

最近,在更新到Gradle 3.6.4(和较新版本)之后,遇到了同样的问题ClassNotFoundException: Didn't find class "com.google.android.gms.common.R$string"

就我而言,它是旧的不推荐使用的io.mironov.smuggler插件。

在大多数情况下,问题似乎出在旧插件上(尤其是那些使用transform api的插件),因此,首先找到哪个插件应该尝试对其进行全部更新。而且,如果这样没有帮助,请逐个禁用它们,直到应用程序开始运行且没有错误为止。

答案 5 :(得分:1)

据我所知,这个问题来自 'project level' build.gradle 文件中依赖项的版本冲突。 尤其是在 gradle 版本更新时发现。

buildscript {
    ...
    dependencies {
        classpath 'com.google.gms:google-services:4.3.4'
        classpath 'com.android.tools.build:gradle:4.1.1'
        classpath "io.objectbox:objectbox-gradle-plugin:2.8.1"
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
    }
}

更新 gradle 版本 (classpath 'com.android.tools.build:gradle:4.1.1') 时,请确保其他类路径依赖项也是最新的。

答案 6 :(得分:0)

我遇到了同样的问题,因此请确保扩展应用程序的类具有以下内容:

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

否则,您需要清理-重建。

答案 7 :(得分:0)

如果在添加multidex后问题仍然存在,则

尝试在Project结构下删除.gradle和.idea文件,然后进行重建。

答案 8 :(得分:0)

由于realm-db

它是基于gradle的alpha版本以及其他一些特定于项目的情况(AndroidX,Kotlin),因此这不是一个普遍的问题,而是需要检查的另一件事

答案 9 :(得分:0)

我从我的项目中删除了所有的firebase和gms依赖项,并且发生了泄漏泄漏错误,因此将其删除。并再次发生书法3等错误... 我认为它是multidex错误。

答案 10 :(得分:0)

我最近也面临着同样的问题。

使用classpath('com.google.firebase:perf-plugin:1.2.1')。并在禁用它后起作用。