I’m trying to compile an app in Android Studio and I’m constantly getting this error:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.ExceptionInInitializerError
There’s a similar question here: Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio
I tried almost all of the answers in the above Question and nothing seems to work!
This is my build.gradle
(Module):
apply plugin: 'com.android.application'
apply plugin: "androidx.navigation.safeargs"
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.XXXXXXX"
minSdkVersion 18
targetSdkVersion 29
versionCode 3
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
resValue("string", "PORT_NUMBER", "8081")
}
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
def lifecycle_version = "2.2.0"
def room_version = "2.2.5"
def nav_version = "2.1.0-alpha02"
def dagger_version = "2.27"
def work_version = "2.4.0"
//Navigation Jetpack
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
//Lifecycle Jetpack
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
//ROOM DB
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//GSON
implementation 'com.google.code.gson:gson:2.6.2'
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
//RXJava
implementation 'io.reactivex.rxjava2:rxjava:2.0.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation "androidx.preference:preference:1.1.0"
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
//Dagger 2
implementation "com.google.dagger:dagger:$dagger_version"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
// Dagger Android
implementation "com.google.dagger:dagger-android:$dagger_version"
implementation "com.google.dagger:dagger-android-support:$dagger_version"
annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"
// Reactive Streams (convert Observable to LiveData)
def reactivestreams_version = "1.1.1"
implementation "android.arch.lifecycle:reactivestreams:$reactivestreams_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Google maps
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'org.jetbrains:annotations-java5:15.0'
//Shimmer animation
implementation 'com.facebook.shimmer:shimmer:0.5.0'
//local DB debug
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
//floating button
implementation 'com.getbase:floatingactionbutton:1.10.1'
//lombok
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
//swipe to delete
implementation 'it.xabaras.android:recyclerview-swipedecorator:1.2.1'
//work manager
implementation "androidx.work:work-runtime:$work_version"
implementation "androidx.work:work-rxjava2:$work_version"
implementation 'androidx.hilt:hilt-work:1.0.0-alpha01'
annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0-alpha01'
//ml vision api
implementation 'com.google.android.gms:play-services-vision:20.1.3'
//maps location
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
//jackson parser
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.1'
implementation 'com.android.support:multidex:1.0.3'
//chart
implementation 'com.mdgiitr.suyash:graphkit:0.9.0'
}
Could someone please point me in a right direction and advice on this issue?
EDIT:
I’m running the latest Android Studio on a Mac machine.
5
Answers
Okay, I managed to solve this issue by adding this to my build.gradle file:
I didn't upgrade the gradle either!
According to the Official Android site, this error is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable. The problem is in your code. See any unnecessary static idenitfier, and post your code in a repo 🙂
This exception occurs also if Jetpack Room < 2.4.0-alpha03 is used on Apple’s M1 chip.
This can be fixed by adding the right dependency to the gradle file
as stated here.
I had the same error on M1 Pro Macbook and fixed by changing
I got this error while fixing othr crash.
There was change in the order of methods ( lines ) in MyApplications onCreate, I needed to make sure super.oncreate is called before,
instance = this
be placed before where
the instance was later used in the code.
Actually in the stackTrace it showed that the crash was actually due to a null pointer exception.
Kindly check the stacktrace for other exceptions.