I am using FileProvider in my app. As usual I declared <Provider> tag in AndroidManifest.xml file as below.
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.jk.android.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
When I run it on android device which has lollipop version it works fine. when I try it on kitkat version it shows following errors:
FATAL EXCEPTION: main
Process: com.jk.android.perfectphotoeditor2018, PID: 24992
java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.jk.android.perfectphotoeditor2018-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.jk.android.perfectphotoeditor2018-2, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5071)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4648)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4588)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1290)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:932)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:748)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.jk.android.perfectphotoeditor2018-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.jk.android.perfectphotoeditor2018-2, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.installProvider(ActivityThread.java:5056)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4648)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4588)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1290)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:932)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:748)
at dalvik.system.NativeStart.main(Native Method)
I had tried many solutions like this but it doesn't work for me. so, help me for solve this problem.
build.gradle dependencies:
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.2'
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'
})
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
testCompile 'junit:junit:4.12'
/* Add the CSDK framework dependencies (Make sure these version numbers are correct) */
// compile 'com.aviary.android.feather.sdk:aviary-sdk:3.6.3'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.adobe.creativesdk.foundation:auth:0.9.1251'
compile 'com.adobe.creativesdk:image:4.8.4'
compile 'com.localytics.android:library:4.0.1'
compile 'com.android.support:design:25.4.0'
compile 'com.android.support:multidex:1.0.2'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.intuit.sdp:sdp-android:1.0.4'
compile 'com.github.bumptech.glide:glide:4.3.1'
compile 'com.google.android.gms:play-services-ads:9.4.0'
implementation 'com.android.support:support-v4:25.4.0'
}
If you have migrated to AndroidX you have to change the name in AndroidManifest.xml to androidx.core.content.FileProvider
That was the crash in my case.
I have the same question, and this documentation solve my problem.
https://developer.android.com/studio/build/multidexandroid multidex
before android 5.0, you must use follow ways to multidex:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}
and then modify application, select any one of three ways:
if you not implement application:
<?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>
if you have custom application, you can modify like this:
public class MyApplication extends MultiDexApplication { ... }
if you have replace base application, you can modify like this:
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Hope this can solve you problem.
The following code works for me (I've migrated to AndroidX):
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true"
tools:ignore="WrongManifestParent">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>
in my project when set "multiDexEnabled" false, error fixed.
go to manifest and add
android {
defaultConfig {
multiDexEnabled false
}}
hope this is helpful
Just delete the intermediates folder.
After thorough reading of Android Multidex documentation, I found that there is one configuration we generally miss which causes java.lang.NoClassDefFoundError. If you have done regular multidex configuration for 65K reference limit and and still unable to get rid of java.lang.NoClassDefFoundError then you must follow these steps.
Create a file called multidex-config.txt at app level(same directory as the build.gradle file)
Add following line (the absolute class name for which you are getting exception)
android.support.v4.content.FileProvider
Modify your build.gradle as follow
android {
buildTypes {
release {
multiDexKeepFile file('multidex-config.txt')
...
}
}
}
Note : You can add it for specific build type or both by declaring it in defaultConfig.
What happens when you build a multidex enabled app :
The Android build tools construct a primary DEX file (classes.dex) and supporting DEX files (classes2.dex, classes3.dex, and so on) as needed. The build system then packages all DEX files into your APK.
At runtime, the multidex APIs use a special class loader to search all of the available DEX files for your methods (instead of searching only in the main classes.dex file).
Cause of Exception :
When building each DEX file for a multidex app, the build tools perform complex decision-making to determine which classes are needed in the primary DEX file so that your app can start successfully. If any class that's required during startup is not provided in the primary DEX file, then your app crashes with the error java.lang.NoClassDefFoundError.
This shouldn't happen for code that's accessed directly from your app code because the build tools recognize those code paths, but it can happen when the code paths are less visible such as when a library you use has complex dependencies. For example, if the code uses introspection or invocation of Java methods from native code, then those classes might not be recognized as required in the primary DEX file.
So if you receive java.lang.NoClassDefFoundError, then you must manually specify these additional classes as required in the primary DEX file by declaring them with the multiDexKeepFile (shown above) or the multiDexKeepProguard (refer documentation) property in your build type. If a class is matched in either the multiDexKeepFile or the multiDexKeepProguard file, then that class is added to the primary DEX file.
For complete documentation on multidex refer https://developer.android.com/studio/build/multidex
Click to AndroidManifest.xml look at the bottom of the files page you gonna see "Text" and "Merged Manifes" then click to "Merged Manifest" -> Search for "android.support.v4.content.FileProvider" then change it with "androidx.core.content.FileProvider"
Thats it, exact solution.
change
<provider android:name="android.support.v4.content.FileProvider"
to
<provider android:name="androidx.core.content.FileProvider"
tested and works for me
FileProvider was introduced with Android API Level 22 which is Lollipop, that is why you did not face the ClassNotFoundException when testing on a Lollipop device. Android Kitkat does not have the FileProvider class and hence you are facing the exception. If you are looking to access files this post should help you out
Related
What can cause this error for class DrawableWrapper from the support lib?
Caused by: java.lang.ClassNotFoundException: Didn't find class
"android.support.v4.graphics.drawable.DrawableWrapper" on path:
DexPathList[[zip file "/data/app/com.example.banyan.tasty-
1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
Try updating your support library to 27.1.0.
Make sure all of your "com.android.support:*" dependencies are at the same version.
Looks like one of the support libraries uses something that is missing in the other one.
i fixed same error updating version
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:support-v4:27.0.2'
To
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
I started getting this exception in Android 5 and Android 4 users after removing com.android.support-v13 from my build.gradle file:
configurations.all {
exclude group: 'com.android.support', module: 'support-v13'
}
I removed the above exclude configuration and no longer saw this crash.
In my case, I used support library version '27.0.2' for my project. It was working perfectly. However, when I copy & paste the project to different location and I opened in Android studio. That time, android studio added below line in build.gradle (path: MyProject/app/build.gradle)
compile 'com.android.support:support-v4:27.1.1'
Then I got the below exception.
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.graphics.drawable.DrawableWrapper" on path: DexPathList
I removed the line from build.gradle (MyProject/app/build.gradle). Now it is working fine.
Try this:
import android.support.v7.graphics.drawable.DrawableWrapper;
import android.support.v7.graphics.drawable.DrawableWrapper;
or
import android.support.v4.graphics.drawable.WrappedDrawable; will help.
Also, when you use Drawable inner = ((WrappedDrawable) drawable).getWrappedDrawable();, you can add #SuppressLint("RestrictedApi") above your method.
Try:
enable D8
if you using
AS 3.1
After working on a project for about a month, my project started executing errors.. Whenever I'm trying to run the program via phone, it executes "app stopped working".. I monetize to check "android monitor" to know who causes the error..(FATAL EXCEPTION: main):
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.app.programavima.java.javaprogramavimas.MainActivity" on path: DexPathList[[zip file "/data/app/com.app.programavima.java.javaprogramavimas-1/base.apk", zip file "/data/app/com.app.programavima.java.javaprogramavimas-1/split_lib_slice_7_apk.apk"],nativeLibraryDirectories=[/data/app/com.app.programavima.java.javaprogramavimas-1/lib/arm64, /vendor/lib64, /system/lib64]]
Am I missing these "base.apk", "arm64", "lib64" files? Maybe something else is making my app to executes errors?
Every help would be pleased, I can manage to import some code, because there's a lot of files inside my project
Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true // add this line
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1' // add this library
}
In your manifest update with this code:
<?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" > // add this line
...
</application>
</manifest>
I have an Android project, inside I have a library module, my project works fine, compile the project I get the .aar included in a test project and everything ok.
Now,I have added in my library module a Activity that extends Application, Y Added this class in the manifiest.xml of the library
<application
android:allowBackup="true"
android:label="#string/app_name"
android:name=".MyActivityExtendsApplications"
When I test the project it works perfect, but when I take the .aar and test it on other project fails. The problem is that it does not find the activity extend Application ... I have decompiled the aar and I see that everything is correct, all class are inside the folder
The error is
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mylibrary.MyActivityExtendsApplications" on path: DexPathList[[zip file "/data/app/com.myapplication-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myapplication-1/lib/arm, /vendor/lib, /system/lib]]
Suppressed: java.lang.ClassNotFoundException: com.mylibrary.MyActivityExtendsApplications
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
I adding grandle dependency to library .aar In all cases in the same way
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
testCompile 'junit:junit:4.12'
compile 'mylibrary-debug.mylibrary-debug#aar'
}
repositories{
flatDir{
dirs 'libs'
}
}
I check merged manifest in my test Project and the activity is there
application
android:name="com.mylibrary.MyActivityExtendsApplications"
android:allowBackup="true"
And I can import this Activity in my test Project and see the code
And I added mylibrary in libs folder.
When I remove the activity MyActivityExtendsApplications, my library works fine.
The issue may be the the Android Beacon Library aar files are missing when you generate your library aar, and the exception description is simply misleading. I don't think classes from aar files are automatically merged when generating a new aar file. You might check to see if these files (like Beacon.class) are missing from your aar.
If this is indeed the problem, there are two possible solutions:
In your application, reference both your library aar file and the Android Beacon Library aar file.
Merge the classes from the first aar file into your new aar file. I have done this before with rather a rather inelegant shell script that I am happy to share, but there may be a better way to accomplish the same thing.
I keep on getting the NoClassDefFoundError on other test device (4.4.2) that I'm using. But works fine on my test device (Android 5.1).
I tried the solutions that I've googled and nothing seems to work.
I'm using Firebase Realtime Database. Can somebody please help?
Here is the error log:
06-03 01:36:29.607 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseOptions', referenced from method com.google.firebase.FirebaseApp.<init> 06-03 01:36:29.617 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApp$zzb', referenced from method com.google.firebase.FirebaseApp.zzaJ 06-03 01:36:29.621 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApiNotAvailableException', referenced from method com.google.firebase.FirebaseApp.getToken 06-03 01:36:29.629 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApp$zza', referenced from method com.google.firebase.FirebaseApp.zza 06-03 01:36:29.639 2655-2655/mobapps.mypersonal.biz.grouptracker E/AndroidRuntime: FATAL EXCEPTION: main
Process: mobapps.mypersonal.biz.grouptracker, PID: 2655
java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions
at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1656)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1627)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5079)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4653)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4593)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
This is what solved the problem for me:
Add compile 'com.android.support:multidex:1.0.2' to
app/build.gradle.
Add android:name="android.support.multidex.MultiDexApplication" to the application tag in AndroidManifest.xml.
If you are using a custom Application class, skip the
AndroidManifest.xml and make your Application class extend MultiDexApplication instead of Application.
This bug is reported with newer versions mostly arround Revision 28,29 and its resolved in newer Play services versions so if you having this issue then make sure you have updated version of Google Play service in your Android studio. as older versions have it. To update Play services version..
Follow these steps:
Go to Android SDK Manager
Go to Extra here you will find as shown in image below, update it to latest version and try to run project.
Then if you are using MultiDex in your Application,then make sure you have correctly done it.
In you App level Build.Gradle file use this code multiDexEnabled true
defaultConfig {
applicationId "com.reversebits.tapanhp.saffer"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
Apply MultiDex dependency in dependencies inside Same file.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.android.support:multidex:1.0.1'
}
Then inside your AndroidMenifest.xml file make sure that Application tag have name of MultiDexApplication.
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true">
Note
if you have your own Application class and you are using it in your menifest file then you can initialize multidex in your Application class as follows,
public class AppClass extends Application {
//this will initialize multidex in your own Application class
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Thanks to TapanHP above I got this working quickly for me:
Short Answer:
I had multiDexEnabled= true set in my app/build.gradle file and this ran fine on Android 5.x.x above but any test device with 4.x.x (kit kat) would throw a critical error "Unfortunately, YourAppName has stopped."
Debugger showed:
Could not find class 'com.google.firebase.FirebaseOptions' ....
Note: I also have a custom class that extends Application.
My Solution:
Added the following code to my custom Application class
import android.support.multidex.MultiDex;
public class YourCustomApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
...
}
No more critical crash.
I have the same problem, with this I have solved:
https://stackoverflow.com/a/37364044
You must replace android:name=".app" with android:name="android.support.multidex.MultiDexApplication"
I was following the Firebase guide to adding FCM, and so I added the following dependencies to my app gradle:
compile 'com.google.android.gms:play-services:9.0.0'
apply plugin: 'com.google.gms.google-services'
And this one to my project gradle:
classpath 'com.google.gms:google-services:3.0.0'
After this, I added the google-services.json from the Firebase console settings by downloading it and adding it to my app directory.
Now I'm getting this error:
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
If I follow the instructions and have my application to support multidex, my application crashes as soon as it launches.
Here is the error after adding multidex to my app:
05-20 01:25:32.253 19812-19812/com.cryogenos.pearsonvisionlimousine W/dalvikvm: VFY: unable to resolve static field 8723 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;05-20 01:25:32.253 19812-19812/com.cryogenos.pearsonvisionlimousine W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x416b5e30)05-20 01:25:32.253 19812-19812/com.cryogenos.pearsonvisionlimousine E/AndroidRuntime: FATAL EXCEPTION: mainProcess: com.cryogenos.pearsonvisionlimousine, PID: 19812java.lang.NoClassDefFoundError: com.google.android.gms.R$stringat com.google.android.gms.common.internal.zzah.<init>
(Unknown Source)
at com.google.firebase.FirebaseOptions.fromResource(Unknown Source)
at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1609)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1574)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5643)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5206)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5143)
at android.app.ActivityThread.access$1500(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1418)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5883)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:688)
at dalvik.system.NativeStart.main(Native Method)
My phone's google play services is 9.0.0+.
I have updated to the latest play services and the repository in SDK manager.
EDIT:
My app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.cryogenos.pearsonvisionlimousine"
minSdkVersion 19
targetSdkVersion 23
versionCode 3
versionName "2.1"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:multidex:1.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.0'
}
apply plugin: 'com.google.gms.google-services'
One possible way to avoid 64k Dex error is by including only those APIs which your app needs from Google Play Services.
Selectively compiling APIs into your executable
From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:
compile 'com.google.android.gms:play-services:9.0.0'
with these lines:
compile 'com.google.android.gms:play-services-fitness:9.0.0'
compile 'com.google.android.gms:play-services-wearable:9.0.0'
UPDATED
Well I read the doc, which says
Apps that rely on the Play Services SDK should always check the device for a compatible Google Play services APK before accessing Google Play services features
So you only need to check Google Play Service is available or not. And to do this you only need Google Actions, Base Client Library API.
compile 'com.google.android.gms:play-services-base:9.0.0'
as explained in documentation use Selectively compiling APIs into your executable which is best approach for you(take it in first priority insted of Multi Dex), because Multi-dex have some limitations check before proceed.
Avoiding the 64K Limit - Proguard will help you
Before configuring your app to enable use of 64K or more method
references, you should take steps to reduce the total number of
references called by your app code, including methods defined by your
app code or included libraries. The following strategies can help you
avoid hitting the dex reference limit:
Review your app's direct and transitive dependencies - Ensure any large library dependency you include in your app is used in a manner
that outweighs the amount of code being added to the application. A
common anti-pattern is to include a very large library because a few
utility methods were useful. Reducing your app code dependencies can
often help you avoid the dex reference limit.
Remove unused code with ProGuard - Configure the ProGuard settings for your app to run ProGuard and ensure you have shrinking enabled for
release builds. Enabling shrinking ensures you are not shipping unused
code with your APKs.
Using these techniques can help you avoid the
build configuration changes required to enable more method references
in your app. These steps can also decrease the size of your APKs,
which is particularly important for markets where bandwidth costs are
high.
So, try to avoid Multi-Dex
one more thing when you use compile 'com.android.support:design:23.1.1' then you not need to use compile 'com.android.support:appcompat-v7:23.1.1' and compile 'com.android.support:support-v4:23.1.1'. so remove v7 & v4 from build.gradle file
First check if the multidex has really worked, you can do that by renaming the apk file to zip and extracting it. There should 2 multiple classes.dex files.
Secondly, it can also happen if earlier to reduce the method you must have used proguard, so just comment the use of proguard and it should work.
Otherwise paste your exception here.
Something wrong.
Checking the doc you only need this dependency
dependencies {
compile 'com.google.firebase:firebase-messaging:9.0.0'
}
So you can remove this dependency
//compile 'com.google.android.gms:play-services:9.0.0'
If it is not enough and you have more than 65536 methods you can use the multidex support.
Just add these lines in the build.gradle:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Also in your Manifest add the MultiDexApplication class from the multidex support library to the application element
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
and override attachBaseContext method:
#Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
MultiDex.install(this);
}
If you are using a own Application class, change the parent class from Application to MultiDexApplication.