Instrumented tests do pass on local emulators and physical devices but fail on Firebase Test Lab, when the following conditions are met:
ProGuard is enabled for the debug builds;
There are both Dagger and Espresso dependencies.
FTL shows different test issues:
1) In case with APIs 26-28 it shows either Instrumentation run failed due to 'java.lang.NoClassDefFoundError' or Instrumentation run failed due to 'Process crashed.'
Exception stacktrace looks like this, it's not always shown in Firebase but is always present in logcat:
Rejecting re-init on previously-failed class java.lang.Class<androidx.test.espresso.core.internal.deps.dagger.internal.Factory>:
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/inject/Provider;
FATAL EXCEPTION: Instr: androidx.test.runner.AndroidJUnitRunner
Process: com.example.debug, PID: 11425
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/inject/Provider;
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at androidx.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:72)
at androidx.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:104)
at androidx.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:789)
at androidx.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:544)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:387)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.inject.Provider" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/com.example.debug.test-9kvw--JgNKzmuQurRdDbCQ==/base.apk", zip file "/data/app/com.example.debug-sz-oCUGs05zlEadCzyqsDA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.debug.test-9kvw--JgNKzmuQurRdDbCQ==/lib/arm64, /data/app/com.example.debug-sz-oCUGs05zlEadCzyqsDA==/lib/arm64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 8 more
2) I also ran one test on API 21 which only had one NoClassDefFoundError in the logs. However, this exception is also present on APIs 26-28, but is a part of the exception shown above. Maybe there's just some difference between how it's logged on different API levels.
java.lang.NoClassDefFoundError: androidx.test.espresso.core.internal.deps.dagger.internal.Factory
FATAL EXCEPTION: Instr: androidx.test.runner.AndroidJUnitRunner
Process: com.example.debug, PID: 5691
java.lang.NoClassDefFoundError: androidx.test.espresso.core.internal.deps.dagger.internal.Factory
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at androidx.test.internal.runner.TestLoader.doCreateRunner(Unknown Source)
at androidx.test.internal.runner.TestLoader.getRunnersFor(Unknown Source)
at androidx.test.internal.runner.TestRequestBuilder.build(Unknown Source)
at androidx.test.runner.AndroidJUnitRunner.buildRequest(Unknown Source)
at androidx.test.runner.AndroidJUnitRunner.onStart(Unknown Source)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1837)
Some relevant lines from build.gradle configuration:
android {
defaultConfig {
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
debug {
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules-debug.pro'
testProguardFile 'proguard-rules-test.pro'
}
}
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:core:1.0.0-beta01'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-beta01') {
// exclude module: 'javax.inject' - Exclusion doesn't help
}
// androidTestImplementation 'javax.inject:javax.inject:1' - Inclusion doesn't help either
androidTestImplementation('androidx.test.ext:junit:1.0.0-beta01') {
exclude group: "org.junit"
}
androidTestImplementation 'androidx.test:runner:1.1.0-beta01'
androidTestImplementation 'androidx.test:rules:1.1.0-beta01'
androidTestImplementation 'org.mockito:mockito-android:2.22.0'
implementation 'com.google.dagger:dagger:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
}
proguard-rules-test.pro:
-ignorewarnings
-dontshrink
-dontoptimize
-dontobfuscate
Upon disabling ProGuard or removing Dagger dependency, tests start to pass on FTL.
So I contacted Firebase support and got an embarrassingly simple solution.
Add the following rule to the proguard-rules-debug.pro
-keep class javax.inject.** { *; }
It's still not clear why this problem doesn't occur while testing locally.
But at least this solution works.
Related
Starting a new project and I am experiencing the following error... I have tried other solutions but seem to be dated
Steps I have tried:
Double checked plugins (listed below)
Instance Run (not listed)
tried using kapt in-place of annotationProccessor (produces a different error)
Process: com.example.transfer_tracker, PID: 28953
java.lang.RuntimeException: Unable to instantiate application com.example.transfer_tracker.CoreApplication package com.example.transfer_tracker: java.lang.ClassNotFoundException: Didn't find class "com.example.transfer_tracker.CoreApplication" on path: DexPathList[[dex file "/data/data/com.example.transfer_tracker/code_cache/.overlay/base.apk/classes4.dex", zip file "/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/base.apk"],nativeLibraryDirectories=[/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/lib/arm64, /system/lib64, /system_ext/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1364)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6686)
at android.app.ActivityThread.access$1500(ActivityThread.java:247)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.transfer_tracker.CoreApplication" on path: DexPathList[[dex file "/data/data/com.example.transfer_tracker/code_cache/.overlay/base.apk/classes4.dex", zip file "/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/base.apk"],nativeLibraryDirectories=[/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/lib/arm64, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
at android.app.Instrumentation.newApplication(Instrumentation.java:1177)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1356)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6686)
at android.app.ActivityThread.access$1500(ActivityThread.java:247)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/transfer_tracker/Hilt_CoreApplication;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 15 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.transfer_tracker.Hilt_CoreApplication" on path: DexPathList[[dex file "/data/data/com.example.transfer_tracker/code_cache/.overlay/base.apk/classes4.dex", zip file "/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/base.apk"],nativeLibraryDirectories=[/data/app/~~zfKHJdy7wnPYBA_pfwtohQ==/com.example.transfer_tracker-gXT0kIH37Cwb7XaCDmovmg==/lib/arm64, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 18 more
[CIRCULAR REFERENCE:java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/transfer_tracker/Hilt_CoreApplication;]
Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.transfer_tracker">
<application
android:name=".CoreApplication"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.TransferTracker">
<activity
android:name=".login.LauncherActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Project build.gradle
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module project.gradle
plugins {
id 'com.android.application'
id 'kotlin-kapt'
id 'kotlin-android'
id 'dagger.hilt.android.plugin'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.transfer_tracker"
minSdk 22
targetSdk 31
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.google.dagger:hilt-android:2.40.5'
annotationProcessor 'com.google.dagger:hilt-compiler:2.40.5'
}
Application Class
package com.example.transfer_tracker
import android.app.Application
import androidx.multidex.MultiDexApplication
import dagger.hilt.android.HiltAndroidApp
#HiltAndroidApp
class CoreApplication : Application()
when using kapt instead of annotationProccessor
public final class CoreApplication extends android.app.Application {
^
Expected #HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin? (dagger.hilt.android.plugin)
See https://dagger.dev/hilt/gradle-setup.html
[Hilt] Processing did not complete. See error above for details.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
> java.lang.reflect.InvocationTargetException (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
UPDATE
Implemented with Dagger2 error is gone... maybe this is due to a bug within the Hilt library
After adding these dependencies everything works fine
implementation 'com.google.dagger:hilt-android:2.40.5'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0'
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
annotationProcessor 'com.google.dagger:hilt-android-compiler:2.38.1'
Try extending the CoreApplication class with MultiDexApplication like this:
#HiltAndroidApp
class CoreApplication : MultiDexApplication() {...}
I think your Application class is getting saved in a different Dex file.
Trying to keep them in a single Dex file should work.
Try this Procedure
Suggestion:
To check Dex file classes you can use Android Studio,
open your apk into Android Studio. You can see your dex files in the apk explorer.
Then select the dex file to see what classes are inside it.
I had the same problem.
Got it resolved by removing this from AndroidManifest.xml
<application
android:name="com.package.name.Application" <- Remove this entire line
Before that I tired invalidating caches, Project Clean, delete build, .gradle and .idea folders, upgraded everything to the latest versions.
Nothing else worked.
App crashes when i apply crashlytics on it
FATAL EXCEPTION: main
Process: com.ehs.pk, PID: 20963
java.lang.RuntimeException: Unable to get provider com.crashlytics.android.CrashlyticsInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.crashlytics.android.CrashlyticsInitProvider" on path: DexPathList[[zip file "/data/app/com.ehs.pk-8.apk"],nativeLibraryDirectories=[/data/app-lib/com.ehs.pk-8, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4993)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4585)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4499)
at android.app.ActivityThread.access$1500(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.crashlytics.android.CrashlyticsInitProvider" on path: DexPathList[[zip file "/data/app/com.ehs.pk-8.apk"],nativeLibraryDirectories=[/data/app-lib/com.ehs.pk-8, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.installProvider(ActivityThread.java:4978)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4585)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4499)
at android.app.ActivityThread.access$1500(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
I was facing the same issue, is related to the 64k limit "multidex".
I was using multiDexEnabled true property in build.gradle in defaultConfig block, under android one.
As stated in Google documentation
for devices with Android API prior to 21, we need to include the multidex library (implementation 'com.android.support:multidex:1.0.2')
and extend MultiDexApplication in our Application class
I have solved this problem by doing the following:
In the Application class:
#Override
public void attachBaseContext(Context base) {
super.attachBaseContext(base);
try {
MultiDex.install(this);
} catch (RuntimeException multiDexException) {
multiDexException.printStackTrace();
}
}
We were having the same issue, and disabling instant run in Android Studio seemed to get it working.
On mac
Android Studio Settings or Preferences -> Build,Execution,Deployment -> Instant Run.
By looking at this part...
Didn't find class ... on path: DexPathList ... dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
of the stack trace you can figure out that your test device is probably pre-Lollipop (Android 5.0) and that you just hit the 64k limit. You can fix it as described here.
This could be an issue with Instant Run. Turn off the Instant Run and run the build again. I faced the same issue and it resolved it.
When minifyEnabled is true while using firebase or crashlytics this problem may happens. Enabling minifyEnabled shrinks methods and classes names to lowest possible characters (changing names and that raises ClassNotFoundException). Unfortunately, firebase and crashlytics versions had many problem with that. To solve it just tell proguard to not shrink those classes by writing the next lines in proguard file "proguard-rules.pro" as:
-keep class com.crashlytics.** { *; }
-keep class com.google.firebase.*.* { *; }
Now if the problem not go away or it didn't find other classes like yours, then check your base project build.gradle dependencies version of gradle and others. I found these version is free of that error:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.2.0'
classpath 'io.fabric.tools:gradle:1.25.1'
}
Remeber you can put any classes path into that proguard file so it did not change its name or methods when minify is enabled, and that will help you with other classes "ClassNotFoundException" as well.
Also to test this in debugging, you can adjust debug setting in build.gradle as:
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Just one more case:
In my case, I disabled instant run, added multiDexEnabled true in my gradle, and added the 'com.android.support:multidex:1.0.3' to my dependencies, called the MultiDex.install(this); directly in my custom application, but I still got the same error. The error only occurs in the system Android 4.4. Everything works well on Android 7.0 and 9.0.
Finally, moving the MultiDex.install(this); from the onCreate(Context) method to the attachBaseContext(Context) solved my problem.
So, you should call MultiDex.install(this); in attachBaseContext(Context) instead of onCreate(Context) when you don't plan to extend the MultiDexApplication directly.
If this happens when you run with minifyEnabled true, add this rule in your proguard-rules.pro file:
-keep public class com.crashlytics.android.CrashlyticsInitProvider
I've been developing a project for 2 months and it works in debug mode.
Today I created a release apk and I have an error on all devices:
android.view.InflateException: Binary XML file line #0: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/constraint/solver/widgets/ConstraintWidgetContainer;
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.solver.widgets.ConstraintWidgetContainer" on path: DexPathList[[zip file
Suppressed: java.lang.ClassNotFoundException: android.support.constraint.solver.widgets.ConstraintWidgetContainer
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Please help!
'com.android.support.constraint:constraint-layout:1.0.0'
To me it happens copying an existing class from a non androidx project into an androidx one.
I had to change:
android.support.constraint.ConstraintLayout
in the xml layout
into:
androidx.constraintlayout.widget.ConstraintLayout
and it solved the issue.
I had to add multidex support:
build.gradle:
android {
...
defaultConfig {
...
multiDexEnabled true
}
}
and:
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
...
}
Try this
select file and choose invalidate caches / restart
if not worked then update it to
compile 'com.android.support.constraint:constraint-layout:1.0.2'
setting
dexOptions {
preDexLibraries false
}
solved the problem
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.
I'm trying to add Espresso testing framework to my project. However, I'm stuck with this NoClassDefFoundError for 3 days. After searching over Google I found testing APK is using by default the DEBUG build type. For some reason I need to set Proguard on for debug build type. However, I get the following error when running my test configuration:
06-02 15:27:01.105 19436-19457/com.lingyue.YqgAndroid E/TestLoader: Could not find class: android.support.test.espresso.base.UiControllerModule_ProvideUiControllerFactory
06-02 15:27:01.107 19436-19457/com.lingyue.YqgAndroid I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.test.espresso.core.deps.dagger.internal.Factory>
06-02 15:27:01.107 19436-19457/com.lingyue.YqgAndroid I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.test.espresso.base.ViewFinderImpl_Factory>
06-02 15:27:01.107 19436-19457/com.lingyue.YqgAndroid I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.test.espresso.base.ViewFinderImpl_Factory>
06-02 15:27:01.109 19436-19457/com.lingyue.YqgAndroid E/TestLoader: Could not find class: android.support.test.espresso.base.ViewFinderImpl_Factory
06-02 15:27:01.114 19436-19457/com.lingyue.YqgAndroid I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.test.espresso.core.deps.dagger.internal.Factory>
06-02 15:27:01.115 19436-19457/com.lingyue.YqgAndroid E/AndroidRuntime: FATAL EXCEPTION: Instr: android.support.test.runner.AndroidJUnitRunner
Process: com.lingyue.YqgAndroid, PID: 19436
java.lang.NoClassDefFoundError: android.support.test.espresso.core.deps.dagger.internal.Factory
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at android.support.test.internal.runner.TestLoader.doLoadClass(TestLoader.java:92)
at android.support.test.internal.runner.TestLoader.loadIfTest(TestLoader.java:113)
at android.support.test.internal.runner.TestRequestBuilder.loadClassesFromClassPath(TestRequestBuilder.java:801)
at android.support.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:747)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:354)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:260)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)
My build.gradle looks likes this for dependencies:
dependencies {
compile "com.android.support:cardview-v7:${supportVersion}"
compile "com.android.support:recyclerview-v7:${supportVersion}"
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.qiniu:qiniu-android-sdk:7.0.9'
compile 'com.mcxiaoke.gradle:packer-helper:1.0.4'
compile 'me.henrytao:smooth-app-bar-layout:23.2.1.1'
compile 'com.alipay.euler:andfix:0.4.0#aar'
compile 'com.umeng.analytics:analytics:6.0.0'
compile fileTree('libs')
compile project(':framework')
compile project(':yqdsdk')
// Only needed at compilation
provided 'com.google.dagger:dagger-compiler:2.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
// For testing
androidTestCompile "com.android.support:support-annotations:${supportVersion}"
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'javax.inject'
}
}
Build Types look like the following:
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testProguardFile 'test-proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testProguardFile.pro looks like this:
-dontobfuscate
-dontwarn
What I've done:
If I switch Proguard off for debug build by setting minifyEnabled=false, the test runs successfully. I get the error above otherwise.
I tried to put testProguardFile under "defaultConfig" and "debug", but to no avail both.
I tried to add one more build type "uiTest" with Proguard off, but the test configuration won't work after I set testBuildType to "uiTest". The error is that Android Studio won't recognise the test runner AndroidJUnitRunner.
It seems to me the problem comes with the mix use of proguard and dagger2 but I'm running out of ideas. Please help.
Best wishes
After doing more research, I found a solution for this problem although which is not straight forward:
Add a new build type and sync the build the project, e.g.
uiTest {
minifyEnabled true
}
On the left down side of the Android Studio, click on "Build Variants". For your application module, choose the newly added build variant, e.g. "UiTest".
Run the application.
This is somewhat inconvenient because you need to switch back and forth when you need to test under different build variants. But it gets Expresso running.
I had a similar problem and was able to fix it by adding the following rule to the proguard-rules.pro:
-keep class javax.inject.** { *; }
I'm not entirely sure your issue is the same though.
Also I'm not sure that you need to exclude javax.inject group from espresso-core dependency.