Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react native build error: package android.support.annotation does not exist

Tags:

I had to completely rewrite the question.

I have a react native android app. When I built the apk file with ./gradlew assembleRelease -x bundleReleaseJsAndAssets, it went fine, but after that it stopped compiling at all. Even react-native run-android is not working anymore.

What I found so far: First, the error is this

Task :app:processDebugResources FAILED resource android:attr/fontVariationSettings not found. resource android:attr/ttcIndex not found. 

If I add these lines to gradle.properties,

android.useAndroidX=true android.enableJetifier=true 

the error changes. Now it's this

Task :@JWWon_react-native-universal-pedometer:compileDebugJavaWithJavac FAILED  error: package android.support.annotation does not exist import android.support.annotation.Nullable;                                  ^ cannot find symbol   private void sendPedometerUpdateEvent(@Nullable WritableMap params) {                                          ^   symbol:   class Nullable   location: class BMDPedometerModule 

The problem is not with the library though. If I remove it from the project, it start complaining about another one. To get it to compile, I have to remove 7 libraries. An example:

Task :@react-native-community_netinfo:compileDebugJavaWithJavac FAILED error: package android.support.v4.net does not exist import android.support.v4.net.ConnectivityManagerCompat; error: cannot find symbol     promise.resolve(ConnectivityManagerCompat.isActiveNetworkMetered(getConnectivityManager()));                     ^   symbol:   variable ConnectivityManagerCompat   location: class ConnectivityReceiver 2 errors 

then if I remove another, this happens:

Task :react-native-camera-kit:compileDebugJavaWithJavac FAILED package android.support.annotation does not exist import android.support.annotation.ColorInt;                                  ^ package android.support.annotation does not exist import android.support.annotation.IntRange;                                  ^ ... 92 errors 

So it will compile if I remove 7 libraries from the project. They are:

react-native-camera-kit @react-native-community_netinfo react-native-push-notification react-native-sensors @JWWon_react-native-universal-pedometer react-native-keep-awake react-native-toast-native

Without them, it compiles perfectly. So there's a bigger problem that doesn't let it work. 2 days ago, all of those libraries were working perfectly with no problem. But now something crushes it.

like image 618
irondsd Avatar asked Jun 19 '19 12:06

irondsd


2 Answers

Try with jetifier

npm install --save-dev jetifier
Or use yarn, but install it locally in your project, not globally

npx jetify
or
npx jetify -w=1 - to specify the number of parallel workers

npx react-native run-android

like image 150
bằng đoàn Avatar answered Sep 20 '22 13:09

bằng đoàn


I actually had something very similar happen and running this worked

npx jetify 

When I ran it through the CI pipeline it didn't work and ended having to add

"scripts": {  ...     "postinstall": "jetify" } 

After npm runs install in the pipeline it then run jetify to convert to androidx and covers all the libraries that need to be converted.

like image 30
Kamil Saykali Avatar answered Sep 18 '22 13:09

Kamil Saykali