Ad

Migrating AndroidX Run Error Android.support.annotation Does Not Exist

- 1 answer

I just have migrated my project to AndroidX. Sync and build phase are ok, but when I try to run the compiler show me this error:

error: package android.support.annotation does not exist

This error raises on a builded file

// 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
  }
}

Gradle properties

android.enableJetifier=true
android.useAndroidX=true

Butterknife implementation into gradle

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

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

  • Android Studio 3.2.1
  • Min Sdk 19, Max Sdk 28
  • Gradle version 3.2.1

It seems to be an error with butterknife but I don't know why.

Ad

Answer

I would suggest updating ButterKnife to the newest version.

I haven't migrated my projects to AndroidX yet, but from the commit history on the ButterKnife github page, it would seem like that the newest 9.0.x versions support AndroidX.

https://github.com/JakeWharton/butterknife

Ad
source: stackoverflow.com
Ad