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
Related
I'm working on Android Studio Bumblebee | 2021.1.1
I'm having this error when I try to compile the project:
Caused by: java.lang.RuntimeException: Duplicate class com.google.common.base.FinalizablePhantomReference found in modules jetified-google-collect-snapshot-20080530 (com.google.code.google-collections:google-collect:snapshot-20080530) and jetified-guava-28.1-android (com.google.guava:guava:28.1-android)
Is simple annoying, I not able to recognize which exactly generate the error (The duplicate class).
Please let me know if you have any clue or if you have had the same problem before and know how to solve it, thanks!
Add the following implementation in the app level build.gradle
implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0'
implementation 'com.google.guava:guava:27.0.1-android'
Getting this crash on only release build with r8 enabled on migrating from crashlytics to firebase SDK and upgrading gradle plugin version
Note : I have multidex dependencies defined and set in build.gradle and also in the application class. This happens only when i upgrade my gradle plugin version from 3.5 to 4.1
I am using firebase-crashlytics version
implementation 'com.google.firebase:firebase-crashlytics:17.0.0'
Grade plugin version
classpath 'com.android.tools.build:gradle:4.0.1'
Crashlytics gradle plugin version
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
Also I am getting warning in the logcat for
W/ComponentDiscovery: Class com.google.firebase.crashlytics.CrashlyticsRegistrar is not an found.
java.lang.ClassNotFoundException: com.google.firebase.crashlytics.CrashlyticsRegistrar
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.crashlytics.CrashlyticsRegistrar" on path: DexPathList
W/ComponentDiscovery: Class com.google.firebase.auth.FirebaseAuthRegistrar is not an found.
java.lang.ClassNotFoundException: com.google.firebase.auth.FirebaseAuthRegistrar
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.auth.FirebaseAuthRegistrar" on path: DexPathList
W/ComponentDiscovery: Class com.google.firebase.database.DatabaseRegistrar is not an found.
java.lang.ClassNotFoundException: com.google.firebase.database.DatabaseRegistrar
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.database.DatabaseRegistrar" on path: DexPathList
To get rid of the above warning I added the following in android manifest under application tag
<service android:name="com.google.firebase.components.ComponentDiscoveryService" >
<meta-data
android:name="com.google.firebase.components:com.google.firebase.auth.FirebaseAuthRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
<meta-data
android:name="com.google.firebase.components:com.google.firebase.database.DatabaseRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar"/>
<meta-data
android:name="com.google.firebase.components:com.google.firebase.crashlytics.CrashlyticsRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar"/>
</service>
Still no luck with it. After doing all these I see this
java.lang.RuntimeException: Unable to create application com.app.MyApp: java.lang.NullPointerException: FirebaseCrashlytics component is not present
NPE when I try to access
FirebaseCrashlytics.getInstance();
Adding -keep class com.google.firebase.** { *; } into proguard-rules.pro, fixed this issue.
Try adding Firebase-BOM in Gradle (app).
implementation platform('com.google.firebase:firebase-bom:26.1.1')
Then in your Application class
Instead of
FirebaseCrashlytics.getInstance();
Use
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
I was working on an Android Studio application when I ran into this error.
Process: com.example.visualizercopy, PID: 28098
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.visualizercopy/io.esense.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2812)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6317)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.visualizercopy-1/base.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.visualizercopy-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.view.LayoutInflater.createView(LayoutInflater.java:609)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:424)
at android.app.Activity.setContentView(Activity.java:2471)
at io.esense.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:6757)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2704)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2812)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6317)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
2019-06-23 16:25:42.234 28098-28098/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
This is my gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.example.visualizercopy"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
implementation 'com.jjoe64:graphview:4.2.2'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
This is the constraint layout tag in my xml file
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/PLAY_PARENT"
android:padding="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="81dp">
I have looked into my error on this site and google, and the common answer is to add compile 'com.android.support.constraint:constraint-layout:1.0.2', however compile is now obsolete, and when I replace compile with implementation and changed it to the newest version ('com.android.support.constraint:constraint-layout:2.0.0-beta1') I still run into the same error. How can I fix this?
I figured it out, I had to update the android.support.constraint.ConstraintLayout tags to androidx.constraintlayout.widget.ConstraintLayout in my layout XML.
You are using androidX packages. So you have to migrate all android.support library with androidX.
So replace below line in gradle,
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'
With this,
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
Reference here.
If you are using androidX packages or you want to use them for your project, then you have to migrate your project to androidX. For that you need to follow below steps:
1) In Android Studio, just goto Refactor-> Migrate to AndroidX to migrate your project and there you can backup your project if some problem occurs migrating project.
After that your dependendencies will have androidX packages automatically.
Further reading: Here
I am having an external library (constants.aar) file. I have kept this .aar file in to my Android library module project's (sdk-module)/lib folder. This sdk-module has classes which uses methods from constants.aar.
Compiling the sdk-module generates sdk-module.aar file.
In my application i am including this sdk-module.aar file. When i am trying to use certain class files of sdk-module, i am getting NoClassDefFoundError.
java.lang.NoClassDefFoundError: Failed resolution of: "class file from constant.aar";
Caused by: java.lang.ClassNotFoundException: Didn't find class "xyz" on path:
I have unzipped the sdk-module.aar file and i can see that constants.aar file is available in its /lib folder.
How to resolve this issue?
android {
defaultConfig {
....
multiDexEnabled true // Add this line in your build.gradle file
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Extend : MultiDexApplication Class In in your ApplicationClass.java
public class BusinessCardApplication extends MultiDexApplication { ... }
OR
MultiDex.install(this); //add this line
Either, See this library's Issues File. If It Is from library's issue there is also define this error detail
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.