5

I've set android.useAndroidX = true and android.enableJetifier = true on gradle.properties. But when I run react-native run-android I see:

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1902 file(s) to forward-jetify. Using 4 workers...

But when I change dir to android dir, and run ./gradlew assembleDebug, I didn't see such thing. Hence my build breaks everywhere where there's android.support.* library imported.

> Task :react-native-app-auth:compileDebugJavaWithJavac FAILED
.../node_modules/react-native-app-auth/android/src/main/java/com/rnappauth/
RNAppAuthModule.java:10: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
                                 ^
.../node_modules/react-native-app-auth/android/src/main/java/com/rnappauth/RNAppAuthModule.java:11: error: cannot find symbol
import android.support.customtabs.CustomTabsCallback;
                                 ^
  symbol:   class CustomTabsCallback
  location: package android.support.customtabs
.../node_modules/react-native-app-auth/android/src/main/java/com/rnappauth/RNAppAuthModule.java:12: error: cannot find symbol
import android.support.customtabs.CustomTabsClient;
                                 ^
  symbol:   class CustomTabsClient
  location: package android.support.customtabs

(25 more errors)

Why is this happening? How can I fix this? Is there any way to externally force gradlew to run jetifier?

Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124

2 Answers2

5

I found the answer. So that your gradle build includes the jetifier-ed codes of your libraries, the step is simple.

  1. Run react-native run-android first. This will jetifier the libraries and put them in the build folder.
  2. Run ./gradlew assembleDebug. This will grab your jetifier-ed code in the build folder into APK without complaining anymore.

My case is that I run ./gradlew assembleDebug before I ever run react-native run-android after I clone the project. Deleting build folder in android folder also resulting the same situation.

Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124
  • I find `react-native run-android` run transforms first while the android generate apk steps doesnt include this step. Is there any working solution other. than this? – heisenberg Feb 26 '20 at 15:59
  • @heisenberg by running the `react-native run-android` first, then run android generate apk, the android generate apk will automatically include what's already in the build folder, including the jetified libraries. – Chen Li Yong Mar 02 '20 at 03:39
0

you can run

npx jetify

before assembleDebug

SooCheng Koh
  • 2,271
  • 3
  • 21
  • 34
  • Interesting. This answer still benefits me as I use a script now to run through all the needed process to build APK, including the `react-native run-android`. Now I can replace the longer running time `react-native run-android` with the shorter running time `npx jetify`. Thanks! – Chen Li Yong Jul 27 '20 at 01:25