迁移AndroidX运行错误android.support.annotation不存在

Lor*_*nzi 5 java migration mobile android androidx

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

error: package android.support.annotation does not exist
Run Code Online (Sandbox Code Playgroud)

在生成的文件上出现此错误

// 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
  }
}
Run Code Online (Sandbox Code Playgroud)

摇篮属性

android.enableJetifier=true
android.useAndroidX=true
Run Code Online (Sandbox Code Playgroud)

牛刀的实现陷入困境

implementation "com.jakewharton:butterknife:8.8.1"
annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"
Run Code Online (Sandbox Code Playgroud)

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

  • Android Studio 3.2.1
  • 最低Sdk 19,最大Sdk 28
  • Gradle版本3.2.1

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

Moo*_*oom 8

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

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

https://github.com/JakeWharton/butterknife

  • 将 butterknife 更新到 10.2.1 后,它解决了我的问题。 (2认同)