After I returned to an older project, after editing a few things, and updating dependencies, I tried to compile and I keep getting this error on startup:
FATAL EXCEPTION: main
Process: com.parsons.bakery, PID: 7383
java.lang.NoSuchMethodError: No direct method <init>(Landroidx/lifecycle/ViewModelStore;Landroidx/lifecycle/ViewModelProvider$Factory;)V in class Landroidx/lifecycle/ViewModelProvider; or its super classes (declaration of 'androidx.lifecycle.ViewModelProvider' appears in /data/app/~~N-cXo7nNU-D-YF78BsrFiA==/com.parsons.bakery-FmBA96FlD6t9sILcrQfjgw==/base.apk)
at androidx.fragment.app.FragmentManagerViewModel.getInstance(FragmentManagerViewModel.java:52)
at androidx.fragment.app.FragmentManager.attachController(FragmentManager.java:2703)
at androidx.fragment.app.FragmentController.attachHost(FragmentController.java:117)
at androidx.fragment.app.FragmentActivity.lambda$init$3$androidx-fragment-app-FragmentActivity(FragmentActivity.java:139)
at androidx.fragment.app.FragmentActivity$$ExternalSyntheticLambda3.onContextAvailable(Unknown Source:2)
at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.kt:84)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:358)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:216)
at com.parsons.bakery.Loading.onCreate(Loading.java:14)
at android.app.Activity.performCreate(Activity.java:8595)
at android.app.Activity.performCreate(Activity.java:8573)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3764)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8177)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
This seems to be an issue in the dependencies as far as I can see, but I'm not confident.
My Gradle file looks as such:
build.gradle
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdk 34
defaultConfig {
applicationId "com.parsons.bakery"
minSdk 27
targetSdk 34
versionCode 1
versionName "1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
proguardFiles 'proguard-rules.pro'
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
multiDexKeepProguard = file('multidex-config.pro')
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
//namespace '${namespaceId}'
allprojects {
tasks.withType(JavaCompile).tap {
configureEach {
options.compilerArgs << "-Xlint:deprecation"
}
}
}
}
dependencies {
implementation 'com.google.code.gson:gson:2.11.0'
implementation 'com.squareup.retrofit2:retrofit:2.11.0'
implementation 'com.squareup.retrofit2:converter-gson:2.11.0'
implementation 'org.mindrot:jbcrypt:0.4'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.activity:activity:1.7.0'
implementation 'androidx.fragment:fragment:1.5.4'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.8.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.7'
implementation 'androidx.preference:preference:1.2.1'
implementation 'androidx.annotation:annotation:1.8.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1'
implementation 'com.google.firebase:firebase-messaging:24.0.0'
implementation 'com.google.firebase:firebase-auth:23.0.0'
implementation 'com.google.firebase:firebase-firestore:25.0.0'
implementation 'androidx.startup:startup-runtime:1.1.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
The error and crash start when the launcher class starts:
public class Loading extends AppCompatActivity {
TextView currentActions;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //Error when this is hit
setContentView(R.layout.activity_loading);
...
I've looked through a lot of other people's posts about similar issues, and none seem to work. I've updated dependencies, and rolled some back, invalidated caches/restart, changed the proguard-rules.pro file to keep the androidx.lifecycle.* class members, and allow code and resource shrinking. According to the documentation about the appcompat package, it requires activity 1.7.0 and fragment 1.5.4 as well, but after adding these, it still crashes with the same error.