首页 > 解决方案 > 迁移 AndroidX 运行错误 android.support.annotation 不存在

问题描述

我刚刚将我的项目迁移到 AndroidX。同步和构建阶段都可以,但是当我尝试运行编译器时显示此错误:

error: package android.support.annotation does not exist

在构建的文件上引发此错误

// Generated code from Butter Knife. Do not modify!
package com.xdatanet.cda.Adapters;

import android.support.annotation.CallSuper; //<-- Doesn't exists
import android.support.annotation.UiThread; //<-- Doesn't exists
import android.view.View;
import android.widget.ImageView;
import butterknife.Unbinder;
import butterknife.internal.Utils;
import com.xdatanet.cda.CustomView.CDATextView;
import com.xdatanet.cda.R;
import java.lang.IllegalStateException;
import java.lang.Override;

public class CommunicationAdapter$CommunicationViewHolder_ViewBinding implements Unbinder {
  private CommunicationAdapter.CommunicationViewHolder target;

  @UiThread  //<-- First error
  public CommunicationAdapter$CommunicationViewHolder_ViewBinding(CommunicationAdapter.CommunicationViewHolder target,
      View source) {
      // Some generated code
  }

  @Override
  @CallSuper //<-- Second error
  public void unbind() {
      // Some generated code
  }
}

渐变属性

android.enableJetifier=true
android.useAndroidX=true

Butterknife 实现到 gradle

implementation "com.jakewharton:butterknife:8.8.1"
annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"

IDE说Files under the "build" folder are generated and should not be edited.

这似乎是黄油刀的错误,但我不知道为什么。

标签: javaandroidmobilemigrationandroidx

解决方案


我建议将 ButterKnife 更新到最新版本。

我还没有将我的项目迁移到 AndroidX,但是从 ButterKnife github 页面上的提交历史来看,最新的 9.0.x 版本似乎支持 AndroidX。

https://github.com/JakeWharton/butterknife


推荐阅读