当片段交换时应用程序停止工作 - Java Android



我正在尝试在我的应用程序中放置片段,它甚至可以正常工作,但是当通过底部导航视图切换屏幕时,应用程序停止运行

java.lang.NoClassDefFoundError: Failed resolution: Landroidx/lifecycle/MutableLiveData;

我尝试放置生命周期的不同实现,但它根本没有帮助


android {
compileSdkVersion 28
defaultConfig {
applicationId "*************"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0-rc04"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
testCompile 'junit:junit:+'
compile 'com.wang.avi:library:2.1.3'
}
--------------
Fragment used
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
public class Lessons extends Fragment
{
@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View inflate = inflater.inflate(R.layout.lessons_fragment, container, false);
return inflate;
}
}

您需要定义 android 生命周期依赖项才能使用 LiveData。

有关详细信息,请参阅以下页面:https://developer.android.com/jetpack/androidx/releases/lifecycle

对于当前版本,将以下内容添加到依赖项中:

def lifecycle_version = "2.1.0"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"

如果您实际上没有使用任何 LiveData 组件,则发布完整的堆栈跟踪会更有用。

最新更新