Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating AndroidX run error android.support.annotation does not exist

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.

like image 917
Lorenzo Vincenzi Avatar asked Oct 19 '18 09:10

Lorenzo Vincenzi


People also ask

How to migrate from Android support to AndroidX?

With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar. The refactor command makes use of two flags. By default, both of them are set to true in your gradle.

What is AndroidX library?

The Android Extension Library, often known as AndroidX, is the new open-source project that is a significant upgrade to the original Android Support Library and can be used to develop, test, package version, and release libraries within Jetpack. The Android Jetpack libraries are part of the AndroidX namespace.


1 Answers

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

like image 200
Moonbloom Avatar answered Sep 21 '22 00:09

Moonbloom