Detox: Android build fails for libs with minSdkVersion 17 with react-native 0.64
Describe the bug
The following command fails after upgrading to RN 0.64
./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug
With the following message (only this library seems to fail).
> Task :react-native-pager-view:processDebugAndroidTestManifest FAILED
[androidx.vectordrawable:vectordrawable-animated:1.0.0] /.gradle/caches/transforms-2/files-2.1/3050775700026023c1db3db79ab19a97/vectordrawable-animated-1.0.0/AndroidManifest.xml Warning:
Package name 'androidx.vectordrawable' used in: androidx.vectordrawable:vectordrawable-animated:1.0.0, androidx.vectordrawable:vectordrawable:1.0.1.
/node_modules/react-native-pager-view/android/build/intermediates/tmp/manifest/androidTest/debug/manifestMerger2807704319365703146.xml:5:5-74 Error:
uses-sdk:minSdkVersion 17 cannot be smaller than version 21 declared in library [com.facebook.react:react-native:0.64.0] /.gradle/caches/transforms-2/files-2.1/4e32a44ca1590525038237dd6b47cd32/jetified-react-native-0.64.0/AndroidManifest.xml as the library might be using APIs not available in 17
Suggestion: use a compatible library with a minSdk of at most 17,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="com.facebook.react" to force usage (may lead to runtime failures)
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
Running ./gradlew assembleDebug
or ./gradlew bundleRelease
then npx react-native run-android --variant=release
works fine.
Maybe this issue should be posted in the react-native-pager-view repo but as I can only reproduce when running the detox build command I’m asking here first.
Steps To Reproduce
- I have tested this issue on the latest Detox release and it still reproduces
Expected behavior
Build should not fail with this error.
Detox Trace-Logs
NA
Device logs (adb logcat)
NA
Environment (please complete the following information):
- Detox: 18.9.0
- React Native: 0.64.0
- Node: v14.8.0
- Device: NA
- OS: KDE neon User Edition 5.21
- Test-runner (select one): jest-circus
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 15
- Comments: 38 (10 by maintainers)
Links to this issue
Commits related to this issue
- fix(android): detox build error See wix/Detox#2712 — committed to alpha0010/react-native-file-access by Andarius 3 years ago
- refactor: read minSdkVersion from gradle.properties (#146) This commit fixes a build problem (https://github.com/wix/Detox/issues/2712) with Detox builds — committed to edeckers/react-native-blob-courier by Andarius 3 years ago
Had the same problem, I was able to fix it by adding this in
android/build.gradle
:Reference: https://github.com/uxcam/react-native-ux-cam/issues/24#issuecomment-892547229
@josephbaylon The library needs to be fixed so that
(or similar) in
android/build.gradle
is replaced with withYou have three options:
package.json
using an https/github URLI’m still seem to be facing this issue.
"detox": "^18.15.0",
ANY LIBRARY CAN HAVE ANY minSdkVersion! It’s not unique to this library. And if the libraries move to 21, then how would all the people still using react-native 0.63 to support API16 feel?
It’s not a bug.
TAKE CONTROL OF YOUR DEPENDENCIES by using gradle to raise them during the build.
Please don’t spam other modules with requests to pass things through. There is no way the whole ecosystem will support this in a timely manner, and there is a much cleaner way to do this:
take control of your own dependencies using buitt-in gradle features
Here’s what I mean
In your
android/build.gradle
put these lines:Example taken from a project that is open source and uses both detox and react-native 0.64.2, you can see it in action
I tried this command and the build passed
cd android ; ./gradlew app:assembleRelease app:assembleAndroidTest -DtestBuildType=release ; cd -
Do the same for debug build. Add ‘app’ before
assembleRelease
andassembleAndroidTest
It’s quite interesting suggestion. In my team, we had a little discussion about its safety. We came up with that trade-off solution:
You might ask why? Just to be sure that these older modules still have their versions during building a release type.
@mikehardy That’s a neat workaround. (Haven’t tested it myself though.)
Still, it’s best practice that libraries pass through
minSdkVersion
. Every module template / generator I’ve seen does it. It’s the way things “just work” instead of having to have deep knowledge of gradle. I recommend sending PR’s to projects to make them better. It’s a minority of modules that don’t have pass-through already.In the interim I already suggested either forking or patch-package’ing the module. Gradle override is fine as well.
@mikehardy I still would expect an explanation why the default release build works correctly (in contrast to detox build)? All I am saying is that the
no solution
is the best solution. I believe lots of people will lose time and struggle on this.Anyways I opted in using @mikehardy `s gradle solution. At first it was not working, so I decided to investigate the repository in which he said it worked. I noticed I had some different versions to some dependencies. I went down the rabbit hole to update starting from gradle. In the end I am not sure what fixed it, but I am mostly certain it was either gradle or react-native update. Here is a diff of what changes I needed to make:
After much digging around I figured out that
rootProject.ext.hasProperty
always returns null (bug report by me), which caused me a lot of confusion. It’s not documented to work, but it’s very confusing that it doesn’t throw an exception.Essentially RN libraries that either have a hard-coded minSdkVersion or which use the incorrect
rootProject.ext.hasProperty("minSdkVersion")
will cause Detox builds to fail for anyone using RN 0.64. For me this was three libraries, react-native-webview (!), react-native-haptic-feedback and react-native-navigation-bar-color.This will be a major painpoint for anyone using Detox on RN 0.64. Still no idea what is different in the Detox build to cause it to fail.
I’m not going to troubleshoot your project. I’ve linked one that works. Build off that.
@plaa for us the fix was to make sure that the library we were using (react-native-pager-view) had the right configuration (https://github.com/callstack/react-native-pager-view/pull/319/files#diff-197b190e4a3512994d2cebed8aff5479ff88e136b8cc7a4b148ec9c3945bd65a) in the
android/build.gradle
file.Looking at the library you are using you are facing the same issue. In this file https://github.com/junina-de/react-native-haptic-feedback/blob/master/android/build.gradle, replace
minSdkVersion 16
withrootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : 16
I’m wondering @Andarius (seen we’re using the same reps). Did you close this because you felt the issue was down to the dependencies?
What I’ve found interesting here is that:
<uses-sdk>
in an AndroidManfiest.xml doesn’t seem to fix the issue eitherWe’re left with just hacking/trying to get libraries we’re relying upon updated. Which is one answer, but I don’t understand why Detox builds differently/these fixes don’t work.