I have updated my application to the new firebase using the this and now when i compile my project i get the following exception.
Here is my logcat:
dependencies {
compile 'com.android.support:support-v4:25.0.1'
compile 'com.google.firebase:firebase-ads:9.0.2'
compile files('libs/StartAppInApp-3.5.0.jar')
compile 'com.android.support:multidex:1.0.1'
}
apply plugin: 'com.google.gms.google-services'
.
I was facing the same error when I incremented the targetSDKVersion from 22 to 23 I spent minimum a whole day to resolve the issue. Now finally i find the result that use different play service api in your build.gradle file Source: https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project
I added only relevant Api's and my app is working fine.
It is so simple to fix guys.If you are using player-services and firebase both in your project make sure that you don't import all the available services in the google.Just import the APIs what you actually need. For example:
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'com.google.android.gms:play-services:9.2.0'
Doing this way it can give you noclassdeffounderror .To fix this
remove play-services and sync your project. If you have dependency like using ads or maps in your app then define the specific API. like:
compile 'com.google.android.gms:play-services-maps:9.2.0'
Note: Maximum don't try to use multiDexEnabled true. This should be your last step to fix something.
Hope this is helpful.
Configure your app for multidex to resolve this issue.
For
minSdkVersion
21 or above setmultiDexEnabled
to true in your module-level build.gradle file, as shown below:
android {
defaultConfig {
//...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
//...
}
For
minSdkVersion
API 20 or lower
Modify the module-level build.gradle
and add the multidex library as a dependency, as shown below:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
//...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
If you do not override the Application
class, edit your manifest
file to set android:name
in the application tag as follows
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication">
//...
</application>
</manifest>
2.1.1. If you do override the Application
class Extend MultiDexApplication
public class MyApplication extends MultiDexApplication { //... }
2.1.2. Or if you do override the Application
class but it's not possible to change the base class, then you can instead override the attachBaseContext()
method and call MultiDex.install(this) to enable multidex:
public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
for more mdex-gradle
Hope this will be help others who are facing same issue.
Before doing all those hectic solutions, try to Clean Project or Rebuild Project from Android Studio.
java.lang. NoClassDefFoundError
Exceptions is thrown when you change any Class name in your project but it couldn't get the changes you made in Runtime.
I downgraded my google play-service dependency from
compile 'com.google.android.gms:play-services:9.2.0'
to
compile 'com.google.android.gms:play-services:8.4.0'
which solved this issue for me.
Please refer to the following Stack Overflow link for further description.
Please Note: On upgrading to the latest google play-service
compile 'com.google.android.gms:play-services:9.4.0'
it solved this issue as well.
Or you could selectively import certain services that you require, instead of importing all google play services.