I have the following class
import com.android.annotations.NonNullByDefault;
@NonNullByDefault
public final class Log {
...
}
and here
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
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'
You can find here the official javadoc of the support-annotations
library.
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.
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;
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...
For me it was an old version of npm
.
Run npm install npm@latest -g
and then npm install