我在项目中使用数据绑定。但是在更新所有依赖项之后,它会显示以下错误。
错误:找不到符号类AddCrop
我尝试清理项目,使缓存无效并重新启动,重命名布局文件。
我正在使用该库进行数据绑定。我也在该库中也看到过类似的问题> https://github.com/evant/binding-collection-adapter/issues/131
请帮助我解决此问题?
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.puramtech.myfarmer"
minSdkVersion 21
targetSdkVersion 28
versionCode 7
versionName "1.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro_placeholder'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
lintOptions {
disable 'MissingTranslation'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.media:media:1.1.0-alpha01'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0-alpha01'
implementation 'androidx.preference:preference:1.1.0-alpha02'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'io.nlopez.smartlocation:library:3.3.3'
implementation 'com.akexorcist:localizationactivity:1.2.1'
// Arch Components
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
implementation "com.squareup.retrofit2:retrofit:2.5.0"
implementation "com.squareup.retrofit2:converter-gson:2.5.0"
implementation 'com.github.Ilhasoft:data-binding-validator:2.0.0'
implementation 'com.zhihu.android:matisse:0.4.3'
implementation 'ch.acra:acra-core:5.1.1'
implementation 'ch.acra:acra-http:5.1.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'id.zelory:compressor:2.1.0'
implementation 'com.stephentuso:welcome:1.4.1'
implementation 'com.github.jd-alexander:LikeButton:0.2.3'
implementation 'com.github.lawloretienne:imagegallery:0.1.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'me.tatarka.bindingcollectionadapter2:bindingcollectionadapter:3.0.0-beta3'
implementation 'me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-recyclerview:3.0.0-beta3'
}
活动
public class AddCropActivity extends BaseActivity {
ActivityAddcroppBinding binding;
AddCropViewModel mViewModel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_addcropp);
AddCropViewModelFactory factory = InjectorUtils.provideAddCropViewModelFactory(this.getApplicationContext(), mSelected);
mViewModel = ViewModelProviders.of(this, factory).get(AddCropViewModel.class);
binding.setViewModel(mViewModel);
binding.setActivity(this);
validator = new Validator(binding);
permissionHelper = new PermissionHelper(this);
isEDIT = getIntent().getStringExtra("ACTION").equalsIgnoreCase("EDIT");
initToolbar();
mViewModel.getCroptype(
Utils.getLang(getCurrentLanguage().getISO3Language())).observe(AddCropActivity.this, apiResponse -> {
if (apiResponse != null && isEDIT) {
if (apiResponse.getError() == null) {
List<CropType> crops = (List<CropType>) apiResponse.getList();
for (int i = 0; i < apiResponse.getList().size(); i++) {
if (crops.get(i).getCropType().equalsIgnoreCase(cropType)) {
pos = i;
}
}
}
}
});
binding.executePendingBindings();
binding.progressBar.hide();
mViewModel.getImageCount().observe(this, integer -> {
count = (integer != null ? integer : 0);
binding.attachImages.setText("ATTACH IMAGES (" + count + ")");
if(count == 0)
binding.attachImages.setEnabled(false);
else
binding.attachImages.setEnabled(true);
});
}
private void initToolbar() {
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(isEDIT ? "Edit Crops" : "Add Crops");
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
}
布局
<data>
<import type="com.puramtech.myfarmer.R" />
<variable
name="viewModel"
type="com.puramtech.myfarmer.ui.AddCrop.AddCropViewModel" />
<variable
name="activity"
type="com.puramtech.myfarmer.ui.AddCrop.AddCropActivity" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/include_toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="14dp"
android:orientation="vertical">
<Spinner
android:id="@+id/crop_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
app:itemBinding="@{viewModel.singleItem}"
app:itemIds="@{viewModel.itemIds}"
app:items="@{viewModel.croptype}" />
<androidx.cardview.widget.CardView
android:id="@+id/image_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="14dp"
android:visibility="gone">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center"
app:itemBinding="@{viewModel.editImageItem}"
app:items="@{viewModel.items}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
</androidx.cardview.widget.CardView>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/attach_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_marginLeft="42dp"
android:layout_marginRight="42dp"
android:layout_marginTop="18dp"
android:background="@drawable/login_button"
android:onClick="@{()->activity.onImageAttach()}"
android:padding="12dp"
android:text="@string/attach_crop_images"
android:textColor="@color/white" />
</LinearLayout>
</ScrollView>
</RelativeLayout>