error: package com.android.annotations does not exist

后端 未结 13 2296
南旧
南旧 2020-12-13 11:55

I have the following class

import com.android.annotations.NonNullByDefault;

@NonNullByDefault
public final class Log {
    ...
}

and here

相关标签:
13条回答
  • 2020-12-13 12:21

    I had similar issues when migrating to androidx. this issue comes due to the Old Butter Knife library dependency.

    if you are using butter knife then you should use at least butter knife version 9.0.0-SNAPSHOT or above.

    implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT' annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'

    0 讨论(0)
  • 2020-12-13 12:25

    I had similar issues when migrating to androidx.

    If by adding the below two lines to gradle.properties did not solve the issue

    android.useAndroidX=true
    android.enableJetifier=true
    

    Then try

    1. 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 (developer.android.com)

    If you still run into issues with migration then manually try to replace the libraries which are causing the issue.

    For example

    If you have an issue with android.support.annotation.NonNull change it to androidx.annotation.NonNull as indicated in the below class mappings table.

    Class Mappings

    Maven Artifact Mappings

    0 讨论(0)
  • 2020-12-13 12:25

    You shouldn't edit any code manually jetify should do this job for you, if you are running/building from cli using react-native you dont' need to do anything but if you are running/building Andriod studio you need to run jetify as pre-build, here is how can you automate this:

    1- From the above menu go to edit configurations:

    2- Add the bottom of the screen you will find before launch click on the plus and choose Run External Tool

    2- Fill the following information, note that the working directory is your project root directory (not the android directory):

    3- Make sure this run before anything else, in the end, your configuration should look something like this:

    0 讨论(0)
  • 2020-12-13 12:27

    For Ionic, try this:

    ionic cordova plugin add cordova-plugin-androidx
    ionic cordova plugin add cordova-plugin-androidx-adapter
    

    The error comes because this app is not using androidX but these plugins solve errors.

    0 讨论(0)
  • 2020-12-13 12:32

    Use implementation androidx.appcompat:appcompat:1.0.2 in gradle and then

    change import android.support.annotation.Nullable; to import androidx.annotation.NonNull; in the classes imports

    0 讨论(0)
  • 2020-12-13 12:33

    In my case I had to use

    import androidx.annotation...
    

    instead of

    import android.annotation...
    

    I migrated to AndroidX and forgot to change that.

    0 讨论(0)
提交回复
热议问题