guys i have two questions:
1) how to test complete app (i mean run test, not unit) on each api from minSDK version which i set up. Is it any auto process for that?
2) after publish my app i have ANR error on my app publish console (system run 4.4 Kitkat):
java.lang.RuntimeException:
at android.app.ActivityThread.installProvider(ActivityThread.java:5011)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4582)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4522)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method:0)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method:0)
Caused by: java.lang.ClassNotFoundException:
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:4996)
i set up avd emulator with similar config on my android studio i after compile i have below exception:
1829-2839/com.google.android.gms.persistent E/LoadManifestTask: Can't find Chimera operation impl class com.google.android.location.copresence.GcmRegistrationChimeraReceiver dropping operation
java.lang.ClassNotFoundException: Didn't find class "com.google.android.location.copresence.GcmRegistrationChimeraReceiver" on path: DexPathList[[zip file "/system/framework/com.android.media.remotedisplay.jar", zip file "/system/framework/com.android.location.provider.jar", zip file "/system/priv-app/PrebuiltGmsCore.apk", zip file "/data/data/com.google.android.gms/code_cache/secondary-dexes/PrebuiltGmsCore.apk.classes2.zip", zip file "/data/data/com.google.android.gms/code_cache/secondary-dexes/PrebuiltGmsCore.apk.classes3.zip", zip file "/data/data/com.google.android.gms/code_cache/secondary-dexes/PrebuiltGmsCore.apk.classes4.zip", zip file "/data/data/com.google.android.gms/code_cache/secondary-dexes/PrebuiltGmsCore.apk.classes5.zip"],nativeLibraryDirectories=[/vendor/lib, /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 bws.<init>(:com.google.android.gms:799)
at bwt.run(:com.google.android.gms:2049)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
[ 05-25 03:04:16.195 1623: 1638 D/ ]
HostConnection::get() New Host Connection established 0xb9183a30, tid 1638
Any Idea what cuse this problem?
My app work fine on Lollipop and Nugat.
I paste also my gradle:
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId 'com.fff.hhh'
minSdkVersion 15
targetSdkVersion 25
versionCode 8
versionName '4.0'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
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:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.google.android.gms:play-services:10.2.6'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.github.bumptech.glide:glide:3.8.0'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.jakewharton:butterknife:8.5.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}
As described official docs:
You are strongly encouraged to use the GoogleApiClient class to
access Google Play services features. This approach allows you to
attach an OnConnectionFailedListener object to your client. To
detect if the device has the appropriate version of the Google Play
services APK, implement the onConnectionFailed() callback method. If
the connection fails due to a missing or out-of-date version of the
Google Play APK, the callback receives an error code such as
SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or
SERVICE_DISABLED. ... Another approach is to use the
isGooglePlayServicesAvailable() method. You get a reference to the
singleton object that provides this method using
GoogleApiAvailability.getInstance(). You might call this method in
the onResume() method of the main activity. If the result code is
SUCCESS, then the Google Play services APK is up-to-date and you can
continue to make a connection.
Please make sure you're following these rules.
To test the app against the particular version :
1. Write espresso test
2. run those tests on the device with desired api level
To solve the gcm problem Add
apply plugin: 'com.google.gms.google-services'
at the end of your build.gradle you have pasted above.
Related
Very much aware there are similar questions. Tried all the answers, none of them helped.
Everything works just fine when I upload the apk to my phone with Android Studio but when I download and install the apk I get this nonsense:
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-1/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5945)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5534)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5473)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1571)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6209)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.ActivityThread.installProvider(ActivityThread.java:5930)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5534)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5473)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1571)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6209)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
The app is pretty much only a webview wrapper for a webapp + widget + GCM functionality that receives push messages and shows notifications. If I get this to work, I might never need to touch Android again, so for the love of god please help me with this final issue.
Here's my build.gradle files:
Project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module:
apply plugin: 'com.android.application'
//apply plugin: "com.ewerk.gradle.plugins.annotation-processor"
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.mycompany.myapp"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true //tried this due to one answer, didnt do anything
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
/*
configurations.all {
resolutionStrategy {
force 'com.android.support:design:23.4.0'
force 'com.android.support:support-v4:23.4.0'
force 'com.android.support:appcompat-v7:23.4.0'
}
}
*/
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
//compile 'com.android.support:appcompat-v7:24.4.0'
//compile 'com.jakewharton:butterknife-compiler:8.4.0'
//annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.jakewharton:butterknife:8.4.0'
//compile 'com.google.android.gms:play-services-gcm:10.0.1'
//compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'
//compile 'com.firebase:firebase-client-android:2.3.1'
// https://mvnrepository.com/artifact/com.squareup.okhttp/okhttp
compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5'
}
apply plugin: 'com.google.gms.google-services'
Yessss, finally. Goodbye android!
Turns out the APK android studio had built during normal build processes was crap for some reason. Build-> Build APK built a 3x bigger apk file that worked when downloaded too.
Hi I'm learning to use Firebase from an Udacity Course.
I got this error when I ran my app and have no clue about it.
11-23 16:48:34.995 3947-3947/com.google.firebase.udacity.friendlychat
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.firebase.udacity.friendlychat, PID: 3841
java.lang.NoSuchMethodError: No virtual method zzait()Ljava/util/ArrayList;
in class Lcom/google/android/gms/auth/api/signin/GoogleSignInOptions;
or its super classes (declaration of 'com.google.android.gms.auth.api.signin.GoogleSignInOptions' appears in /data/data/com.google.firebase.udacity.friendlychat/files/.jrebel/load-dexes/bundle12/libraries24.zip)
at com.google.android.gms.auth.api.Auth$3.zza(Unknown Source)
at com.google.android.gms.auth.api.Auth$3.zzp(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient$Builder.addApi(Unknown Source)
at com.firebase.ui.auth.util.CredentialsAPI.initGoogleApiClient(CredentialsAPI.java:147)
at com.firebase.ui.auth.util.CredentialsAPI.<init>(CredentialsAPI.java:65)
at com.firebase.ui.auth.ui.ChooseAccountActivity.onCreate(ChooseAccountActivity.java:102)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112) at com.zeroturnaround.jrebel.android.agent.JRebelInstrumentation.callActivityOnCreate(SourceFile:93)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
11-23 16:48:35.176 3947-3975/com.google.firebase.udacity.friendlychatE/GED: Failed to get GED Log Buf, err(0)
Can anyone help me?
UPDATE build.gradle
apply plugin: 'com.android.application'
repositories {
mavenLocal()
maven { url 'https://maven.fabric.io/public' }
flatDir {
dirs 'libs'
}
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.google.firebase.udacity.friendlychat"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:appcompat-v7:24.2.0'
// Displaying images
compile 'com.github.bumptech.glide:glide:3.6.1'
// Firebase
compile 'com.google.firebase:firebase-database:10.0.0'
compile 'com.firebaseui:firebase-ui-database:1.0.0'
// FirebaseUI Auth only
compile 'com.firebaseui:firebase-ui-auth:1.0.0'
// FirebaseUI Storage only
compile 'com.firebaseui:firebase-ui-storage:1.0.0'
// Single target that includes all FirebaseUI libraries above
compile 'com.firebaseui:firebase-ui:1.0.0'
// Firebase Auth
compile 'com.google.firebase:firebase-auth:10.0.0'
}
apply plugin: 'com.google.gms.google-services'
Matching the versions resolves this.
In Compatibility with Firebase / Google Play Services Libraries, it matches
FirebaseUI Version Firebase/Play Services Version
1.0.0 9.8.0
So if dependencies are changed to
compile 'com.google.firebase:firebase-database:9.8.0'
compile 'com.google.firebase:firebase-auth:9.8.0'
compile 'com.firebaseui:firebase-ui-auth:1.0.0'
instead of
compile 'com.google.firebase:firebase-database:10.0.0'
compile 'com.google.firebase:firebase-auth:10.0.0'
compile 'com.firebaseui:firebase-ui-auth:1.0.0'
which is the latest available firebase version for firebaseUI version, the app works fine
This is most likely do to a version incompatibility between Firebase, and FirebaseUI. I ran into the same issue, and spent 30-45 min trying to figure it out. Ultimately what I did in order to keep going with the "Firebase in a Weekend" tutorial was:
git checkout 1.04-firebase-auth-firebaseui-signin
This will switch to the branch at this point in the tutorial. It works fine after doing so.
Maybe not the ideal answer as to what the problem is, but will get you going again with the course.
You just need to add :
compile 'com.google.android.gms:play-services-auth:x.x.x'(find the right version here). They missed to say that you also need to add play-services-auth dependency for google authentication to work.
Today I tested my app on a new device (see below) and I'm getting an exception right at launch. I can't event start the main activity.
Device: Genymotion Samsung Galaxy S2 - Android 4.1.1 - API 16
No google play services installed.
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.firebase.g
at com.google.firebase.b.a(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1058)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:4560)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4190)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4132)
at android.app.ActivityThread.access$1300(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
gradle build:
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.app"
minSdkVersion 10
targetSdkVersion 21
multiDexEnabled true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
compile 'com.github.castorflex.smoothprogressbar:library:1.1.0'
compile 'com.jeremyfeinstein.slidingmenu:library:1.3#aar'
compile 'com.google.android.gms:play-services-ads:9.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
}
Is it crashing because of missing Play Services?
Note: I have implemented firebase about a month ago, and It's working on other devices.
Although you have multiDexEnabled true in your build.gradle file, you are missing compile 'com.android.support:multidex:1.0.1' in your dependencies. I doubt that Mulidex is working. Review the Multidex configuration instructions and make sure you have done everything correctly.
Also, it is not good practice to include compile 'com.google.android.gms:play-services:9.4.0'. That adds all the Google Play and Firebase libraries to you app, increasing build time and the size of the APK file. Replace the dependency on play-services:9.4.0 with only the libraries you need. A list of the Google Play libraries is provided here, the Firebase libraries are listed here.
Try adding this apply plugin: 'com.google.gms.google-services' to the end of your gradle build file
You're correct, Firebase requires Google play services. As mentioned here in the release announcement for Google Play Services 9.0:
Google Play Services 9.0
Firebase was built using Google Play services 9.0
Add this line in the Application Tag on manifest file:
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.
I don't even use new relic and I'm getting errors for them. It just happened all of the sudden.
I'm using the latest Android Studio build (0.61). Even my master branch has the same error. There are other projects on my machine that use new relic, but not this one. This project does not use new relic in any way, not so much as a wayward gradle dependency.
I've tried clearing out my gradle cache and re-downloading all the third party libs, didn't work.
StackTrace:
06-15 01:05:54.872 20117-20117/com.waxwings.happyhour.staging D/HappyHourApplication﹕ CREATE TABLE job_holder (_id integer primary key autoincrement , `priority` integer, `group_id` text, `run_count` integer, `base_job` byte, `created_ns` long, `delay_until_ns` long, `running_session_id` long, `requires_network` integer );
06-15 01:05:54.874 20117-20117/com.waxwings.happyhour.staging D/AndroidRuntime﹕ Shutting down VM
06-15 01:05:54.877 20117-20117/com.waxwings.happyhour.staging E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.waxwings.happyhour.staging, PID: 20117
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/newrelic/agent/android/instrumentation/SQLiteInstrumentation;
at com.path.android.jobqueue.persistentQueue.sqlite.DbOpenHelper.onCreate(DbOpenHelper.java:42)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.<init>(SqliteJobQueue.java:42)
at com.path.android.jobqueue.JobManager$DefaultQueueFactory.createPersistentQueue(JobManager.java:594)
at com.path.android.jobqueue.JobManager.<init>(JobManager.java:77)
at com.waxwings.happyhour.HappyHourApplication.configureJobManager(HappyHourApplication.java:84)
at com.waxwings.happyhour.HappyHourApplication.onCreate(HappyHourApplication.java:38)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1030)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4425)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.newrelic.agent.android.instrumentation.SQLiteInstrumentation" on path: DexPathList[[zip file "/data/app/com.waxwings.happyhour.staging-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.waxwings.happyhour.staging-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.path.android.jobqueue.persistentQueue.sqlite.DbOpenHelper.onCreate(DbOpenHelper.java:42)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.<init>(SqliteJobQueue.java:42)
at com.path.android.jobqueue.JobManager$DefaultQueueFactory.createPersistentQueue(JobManager.java:594)
at com.path.android.jobqueue.JobManager.<init>(JobManager.java:77)
at com.waxwings.happyhour.HappyHourApplication.configureJobManager(HappyHourApplication.java:84)
at com.waxwings.happyhour.HappyHourApplication.onCreate(HappyHourApplication.java:38)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1030)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4425)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
Suppressed: java.lang.ClassNotFoundException: com.newrelic.agent.android.instrumentation.SQLiteInstrumentation
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)
... 19 more
Caused by: java.lang.NoClassDefFoundError: Class "Lcom/newrelic/agent/android/instrumentation/SQLiteInstrumentation;" not found
... 23 more
build.gradle for module:
apply plugin: 'android'
apply plugin: 'newrelic'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
useOldManifestMerger true
productFlavors {
staging {
applicationId "com.waxwings.happyhour.staging"
}
production {
applicationId "com.waxwings.happyhour"
}
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile 'com.path:android-priority-jobqueue:1.1.2'
compile "com.android.support:support-v4:19.1.0"
compile 'com.google.android.gms:play-services:4.4.52'
// compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/wearable-preview-support.jar')
compile group: 'com.squareup.okhttp', name: 'okhttp', version: '1.5.3'
compile group: 'com.squareup.picasso', name: 'picasso', version: '2.2.0'
compile 'com.jakewharton:butterknife:5.0.1'
compile 'com.squareup.retrofit:retrofit:1.5.1'
compile 'com.squareup:otto:+'
compile 'com.squareup.phrase:phrase:+'
compile 'com.newrelic.agent.android:android-agent:3.402.0'
// Mockito dependencies
androidTestCompile "org.mockito:mockito-core:1.9.5"
androidTestCompile files(
'libs/dexmaker-1.0.jar',
'libs/dexmaker-mockito-1.0.jar')
androidTestCompile ('com.squareup:fest-android:1.0.8'){
exclude group:'com.android.support', module: 'support-v4'
}
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
exclude group: 'org.hamcrest:hamcrest-core:1.1'
exclude group: 'org.hamcrest:hamcrest-library:1.1'
exclude group: 'org.hamcrest', module: 'hamcrest-integration'
exclude group:'com.android.support', module: 'support-v4'
}
androidTestCompile ('com.jakewharton.espresso:espresso-support-v4:1.1-r3'){
exclude group:'com.android.support', module: 'support-v4'
}
}
build.gradle for project:
buildscript {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/comnewrelic-1153'
}
maven {
url 'https://oss.sonatype.org/content/repositories/comnewrelic-1154'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
classpath 'com.newrelic.agent.android:agent-gradle-plugin:3.402.0'
}
}
allprojects {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/comnewrelic-1153'
}
}
}
Edit
The project now imports New Relic in the build.gradle per a user suggestions. This fixed the issue but I'm still exploring why, as it doesn't seem like it should be necessary.
The class throwing the error is in Path's JobQueue lib, the library hasn't been updated in 4 months, and my app has been running fine, this just started happening suddenly. The class that is erroring in the 3rd party lib doesn't even use New Relic.
Edit 2
The priority job queue lib does not use new relic. I have no clue why the stack trace says it does, seems like a red herring. I've heard the New Relic SDK modifies the Android API and gives weird errors. But again, I don't use new relic in my project. Is it possible using the NR sdk in another project somehow infected this one (maybe a bug in Android Studio)?
Edit 3
OK, the Priority Job Queue lib in the original stack trace is definitely a false flag. I went ahead and accessed my own Provider before the JobQueue had a chance to access its (knowing this would force the creation of my own DB ahead of the JobQueue lib). My logic was that if Android Sqlite was being infected by New Relic then it would cause a similar error on my own OpenHelper, it did.
06-15 15:29:39.848 1368-1368/com.waxwings.happyhour.staging W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4d81b20)
06-15 15:29:39.848 1368-1368/com.waxwings.happyhour.staging E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.waxwings.happyhour.staging, PID: 1368
java.lang.NoClassDefFoundError: com.newrelic.agent.android.instrumentation.SQLiteInstrumentation
at com.waxwings.happyhour.services.HHOpenHelper.onCreate(HHOpenHelper.java:56)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
at com.waxwings.happyhour.services.HappyHourProvider.query(HappyHourProvider.java:121)
at android.content.ContentProvider.query(ContentProvider.java:857)
at android.content.ContentProvider$Transport.query(ContentProvider.java:200)
at android.content.ContentResolver.query(ContentResolver.java:461)
at android.content.ContentResolver.query(ContentResolver.java:404)
at com.waxwings.happyhour.HappyHourApplication.onCreate(HappyHourApplication.java:39)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Edit 4
I just ran the project on a machine that has never had a New Relic library installed in any project and it ran fine. I think this is pretty strong evidence that New Relic is doing something funny w/ their plugin/library.
Edit 5
I updated my gradle-wraper.properties file to use the rc-1 distribution and that seems to have fixed the problem. I removed the new relic dependencies from my build.gradle that one commenter suggested, and the app still runs fine.
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-rc-1-all.zip
My guess is that the New Relic library was being cached in the 1.12-all gradle distro and this was the common link causing other projects to error. I'm still not sure what makes the New Relic library different such that gradle thinks it should include it in other projects. Given that New Relic had an almost identical issue w/ their Eclipse plugin not too long ago, I think it's reasonable to assume there's something going on w/ their Maven distribution. I have a support ticket open with them and I will continue to investigate and report back.
The odd part is if I delete all the gradle distributions/caches/etc in ~/.gradle dir and try to use the 1.12-all distro it still throws that new relic error. The only way it will work is if I use the 1.12-rc-1-all gradle distro.
./gradlew --stop
./gradlew cleanBuildCache
./gradlew clean
works for me
It looks like Android Studio switched over to the gradle daemon for faster builds. Unfortunately, this caches parts of the New Relic agent and it's necessary to stop the daemon when you switch to a project without the agent (or a different version. You can accomplish this simply by running:
gradle --stop
You'll also want to clean your project to ensure the classes are rebuilt and dexed.
While this should get you up and running for now, we'll work on a fix for this issue right away and you can expect it in the next version of the agent.
I tried gradle --stop but it didn't work.
Delete .gradle directory and sync project again, it worked.
I faced the weird issue of NoClassDefFoundError in kitkat. but it was working fine on lollipop.
I tried all the above fix but didn't work.
Finally I come to know that its because of multidex error. I crossed 65k method.
So,I followed this tutorial from android developer site. and worked like charm