error: package com.android.annotations does not exist

后端 未结 13 2297
南旧
南旧 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:37

    To automatically fix all android to androidx issues for React Native (prerequisite npx)

    Add the following two flags to true in your gradle.properties file at ProjectFolder/android/gradle.properties

    android.useAndroidX=true
    android.enableJetifier=true
    

    Execute

    npm install --save-dev jetifier
    npx jetify
    npx react-native run-android
    

    In your package.json add the following to scripts

      "postinstall" : "npx jetify"
    

    More info at https://github.com/mikehardy/jetifier

    Update: This is now in-built in react-native 0.60. If you migrate to react-native 0.60 you won't need this step. - https://facebook.github.io/react-native/blog/2019/07/03/version-60#androidx-support

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

    Open gradle.properties and use following code:

    android.useAndroidX=false
    android.enableJetifier=false
    
    

    or U can use these dependencies too:

    implementation 'androidx.appcompat:appcompat:1.0.2'
     implementation 'androidx.annotation:annotation:1.0.2'
    
    0 讨论(0)
  • 2020-12-13 12:37

    You can find here the official javadoc of the support-annotationslibrary.

    Error:(3, 31) error: package com.android.annotations does not exist

    As you can see all the classes are in the same package android.support.annotation and not com.android.annotations.

    Error:(7, 2) error: cannot find symbol class NonNullByDefault

    Also the class NonNullByDefault doesn't exist in that package.

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

    Annotations come from the support's library which are packaged in android.support.annotation.

    As another option you can use @NonNull annotation which denotes that a parameter, field or method return value can never be null.
    It is imported from import android.support.annotation.NonNull;

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

    All you need to do is to replace 'import android.support.annotation.Nullable' in class imports to 'import androidx.annotation.Nullable;'

    Thats a common practice..whenever any import giving issue...remove that import and simply press Alt+Enter on the related class..that will give you option to 'import class'..hint Enter and things will get resolved...

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

    For me it was an old version of npm.

    Run npm install npm@latest -g and then npm install

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