24
votes

I tried out many things, but it does not solve my problem.

Full Error Code (kompletter Error Code):

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 project:

    // 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>

I know what the NoClassDefFoundError does, but I did not find the problem. Ask if you need more files for solving the problem.

10
this may be multidex problem. Can you try 2ed solution from developer.android.com/studio/build/multidex.Vishu
I didn't read all of your post, what happens if you remove proguard? Does exception still occur? Do other classes from that lib (within the same package) present at runtime?)deathangel908
@Vishu I added multidex but it doesnt work :/Dureox
@deathangel908 I removed the line proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' but it doesn't workDureox
You have some conflicting libs in the projects, check ./gradlew app:dependenciesdeathangel908

10 Answers

41
votes

If you are using Realm plugin in your app, then you could try upgrading your plugin as it was one of the reason why app crashed while running.


Steps to update realm plugin:

  • Open build.gradle(Project: Project_name_here) file.
  • Replace classpath of realm gradle plugin with the latest stable version as follows:
  • classpath "io.realm:realm-gradle-plugin:7.0.0"


Also, please check for any outdated plugins within build.gradle file as it may be one of the reason why the app crashes.


OR

I faced similar issue after updating Android Studio to 3.6 with Gradle 3.6.0.

I downgraded my Gradle to 3.5.3 in-order to resolve this issue until it gets fixed in future.


Steps:

  • Open build.gradle(Project: Project_name_here) file.
  • Replace classpath of android tools build gradle under dependencies with the following:
  • classpath 'com.android.tools.build:gradle:3.5.3'



Please Note: This is a temporary fix. It may get fixed in future, so until then downgrade and continue with app development.

19
votes

If you have just updated your project to Gradle 3.6.0 and are using Realm there is a very high chance that this issue was caused by the Realm plugin. Accordingly to this comment, this issue happens for older Realm plugin versions, less than 5.13.1. So just updating to the latest Realm version will most likely solve the problem.

As of the time of writing it was: classpath "io.realm:realm-gradle-plugin:6.1.0"

5
votes

You have to update your REALM-PLUGIN and you need to write this in Top-Level Gradle (Project:Gradle), copy paste below "classpath" line:

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

Hi I know its late in the question but for the current android version, I solved this problem.

on build.grade project-level dependencies update your:

on build.grade app-level update your dependencies

Some answers to this problem involved multidex and other fix's but none solved for me.

That's why this answer was made.

my current settings:

project-level

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'
}

app-level

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')
}

Hope I could help a few!

1
votes

Just ran into this due to realm-db

It was on an alpha build of gradle and a few other project-specific circumstances (AndroidX, Kotlin) so this isn't a general issue, but another thing to check

1
votes

Recently, after the update to Gradle 3.6.4(and newer versions) faced the same problem ClassNotFoundException: Didn't find class "com.google.android.gms.common.R$string".

In my case it was old deprecated io.mironov.smuggler plugin.

It seems that in most cases problem is with old plugins (especially ones thar use transform api), so to find which one you first should try to update them all. And if that doesn't help, just disable them one by one until app starts running with out the error.

1
votes

As far as I see, this issue comes from version conflicts of dependencies in 'project level' build.gradle file. And especially caught when the gradle version is updated.

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'
    }
}

When you update your gradle version (classpath 'com.android.tools.build:gradle:4.1.1'), ensure that your other classpath dependencies are also up-to-date.

0
votes

i remove all of the firebase and gms dependencies from my project and error happens with leakcanary and so remove this. and again error happens with calligraphy3 and so on ... i think its multidex bug.

0
votes

I recently also face same issue.

using classpath('com.google.firebase:perf-plugin:1.2.1'). and works after disabling it.

-2
votes

I had same problem, so be sure for class which is extending application to have below :

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

Otherwise you need to make clean - rebuild.