-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android build fails for libs with minSdkVersion 17 with react-native 0.64 #2712
Comments
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:
We'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. |
@IPWright83, yes, I felt that the issue was more related to |
@LeoNatan I know you've shared your views on this library in the past - I'd be interested to know though if you could share any insight into why builds via Detox might fail in this way and why all the suggested workarounds don't work? I've got a StackOverflow question where no one has been able to understand the nuances of the Detox build and why we're unable to resolve it. So far the only thing I've found works is to hack the |
I'm facing the same issue after upgrading RN 0.63.3 --> 0.64. I think it's related to the fact that RN 0.64 has dropped support for Android versions 16-20, even though I have
After I upgraded
If you've managed to fix it, any assistance would be appreciated! |
@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 Looking at the library you are using you are facing the same issue. |
The rabbit hole gets deeper than I thought... 😱 @Andarius 's instructions fixed the react-native-haptic-feedback library, thanks a lot for that. Then the next library, react-native-navigation-bar-color failed, but that library does check the root project minSdkVersion. However, it uses It seems that pretty much every RN native library checks the values from It seems to me that this issue will bite every user who tries to use Detox on RN 0.64, while normal RN builds work just fine. It also seems weird why a library requiring a lower minSdkVersion is causing the build to fail. Does @LeoNatan have any idea why the Detox builds fail, while the regular builds don't? I think this bug should be reopened. |
@plaan, I don't have issues when the library is using |
@plaa I think that depends on the root
|
Yes, I have exactly the same:
I even tried adding an embedded
When I add
|
This is actually even weirder than I thought:
So |
@plaa, maybe |
Yeah, I was able to dig out that This basically means that Still no idea why the |
After much digging around I figured out that Essentially RN libraries that either have a hard-coded minSdkVersion or which use the incorrect 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. |
This commit fixes a build problem (wix/Detox#2712) with Detox builds
This is also now an issue for us after upgrading to RN 0.64.x. Is there a workaround or just need to wait for the fix? |
@josephbaylon The library needs to be fixed so that
(or similar) in
You have three options:
|
@plaa Thanks for the tips! |
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 subprojects {
task listAllDependencies(type: DependencyReportTask) {}
// Force all subprojects to use one and only one set of versions
ext {
compileSdk = rootProject.ext.compileSdkVersion
buildTools = rootProject.ext.buildToolsVersion
minSdk = rootProject.ext.minSdkVersion
targetSdk = rootProject.ext.targetSdkVersion
}
afterEvaluate { project ->
if (!project.name.equalsIgnoreCase("app")
&& project.hasProperty("android")) {
android {
compileSdkVersion compileSdk
buildToolsVersion buildTools
defaultConfig {
minSdkVersion minSdk
targetSdkVersion targetSdk
}
}
} 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 |
@mikehardy thanks for the suggestion but still failing, could you share the project's url? thanks! |
React-native-firebase tests directory |
Yeah I saw there this piece of code, thanks. No lucky in my project 😔 |
Then you are doing something wrong. Keep trying. It definitely works. I use it in all my projects. |
@mikehardy I'm not sure, this is a basic project and still failing https://github.com/bsalesc/detox-build-failing
|
I'm not going to troubleshoot your project. I've linked one that works. Build off that. |
Still reproduces on detox 18.18.1. In case that the build works for release build, but not with
This reproduces even after a full clean: # Cleanup project dependencies.
cleanup:
rm ~/.gradle -R ;\
rm android/.gradle -R ;\
rm android/.gradle_home -R ;\
rm android/build -R ;\
rm android/app/build -R ;\
npm ci ;\
(cd android && ./gradlew clean) ;\ |
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. |
or use patch-package if you want a hackier solution than gradle - https://github.com/ds300/patch-package |
@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 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: diff --git a/android/app/build.gradle b/android/app/build.gradle
index 61b1580..44d943d 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -1,3 +1,4 @@
+apply plugin: 'com.android.application'
apply plugin: "com.github.triplet.play"
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
diff --git a/android/build.gradle b/android/build.gradle
index 0afd430..7cb3ca0 100755
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -2,7 +2,6 @@
buildscript {
ext {
- buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
@@ -19,8 +18,8 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath "com.github.triplet.gradle:play-publisher:3.4.0"
- classpath "com.android.tools.build:gradle:4.1.0"
+ classpath "com.github.triplet.gradle:play-publisher:3.4.0-agp4.2"
+ classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
@@ -48,3 +47,24 @@ allprojects {
maven { url 'https://www.jitpack.io' }
}
}
+
+subprojects {
+ // Force all subprojects to use one and only one set of versions
+ ext {
+ compileSdk = rootProject.ext.compileSdkVersion
+ minSdk = rootProject.ext.minSdkVersion
+ targetSdk = rootProject.ext.targetSdkVersion
+ }
+ afterEvaluate { project ->
+ if (!project.name.equalsIgnoreCase("app") && project.hasProperty("android")) {
+ android {
+ compileSdkVersion compileSdk
+ buildToolsVersion "30.0.2"
+ defaultConfig {
+ minSdkVersion minSdk
+ targetSdkVersion targetSdk
+ }
+ }
+ }
+ }
+}
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
index 14e30f7..1f3fdbc 100644
--- a/android/gradle/wrapper/gradle-wrapper.properties
+++ b/android/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
index bba7a0c..23a3b97 100644
--- a/package.json
+++ b/package.json
@@ -33,7 +33,7 @@
"@babel/register": "^7.9.0",
"@babel/runtime": "^7.12.5",
- "@react-native-community/async-storage": "^1.9.0",
+ "@react-native-async-storage/async-storage": "^1.15.5",
"@react-native-community/google-signin": "^4.0.3",
"@react-native-community/masked-view": "^0.1.7",
"@react-native-community/netinfo": "^5.9.4",
@@ -71,7 +71,7 @@
"react": "17.0.1",
"react-dom": "^16.13.1",
"react-intl": "^4.7.6",
- "react-native": "0.64.0",
+ "react-native": "0.64.2",
"react-native-calendars": "^1.265.0",
"react-native-device-info": "^5.5.7",
"react-native-dotenv": "^0.2.0",
@@ -98,14 +98,14 @@
"devDependencies": {
"@react-native-community/eslint-config": "^2.0.0",
"@types/chai": "^4.2.11",
- "@types/detox": "^16.4.1",
+ "@types/detox": "^17.14.0",
"@types/mocha": "^8.0.3",
"@types/react-test-renderer": "17.0.1",
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"better-npm-audit": "^1.1.1",
"chalk": "^4.0.0",
- "detox": "^17.4.5",
+ "detox": "^18.18.1",
"dotenv": "^8.2.0",
"eslint": "7.14.0",
"eslint-config-prettier": "^6.10.0",
diff --git a/src/Localization/LocalizationProvider.tsx b/src/Localization/LocalizationProvider.tsx
index e6766f3..0328fcc 100644
--- a/src/Localization/LocalizationProvider.tsx
+++ b/src/Localization/LocalizationProvider.tsx
@@ -1,5 +1,5 @@
import React, { useState, FunctionComponent, useCallback } from 'react';
-import AsyncStorage from '@react-native-community/async-storage';
+import AsyncStorage from '@react-native-async-storage/async-storage';
import { DEFAULT_LANGUAGE, languages } from './Translations';
import * as RNLocalize from 'react-native-localize';
import LanguageSetContext from './LanguageSetterContext';
diff --git a/test/integration/mocha/init.js b/test/integration/mocha/init.js
index 29a4d98..6fb10d9 100644
--- a/test/integration/mocha/init.js
+++ b/test/integration/mocha/init.js
@@ -25,6 +25,7 @@ before(async () => {
await detox.init(config);
global.isDetoxInitialized = true;
}
+ await device.launchApp();
});
beforeEach(async function () { |
@mikehardy That's a neat workaround. (Haven't tested it myself though.) Still, it's best practice that libraries pass through In the interim I already suggested either forking or patch-package'ing the module. Gradle override is fine as well. |
Had the same problem, I was able to fix it by adding this in
Reference: uxcam/react-native-ux-cam#24 (comment) |
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. |
|
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 |
Thanks for this |
worked for me! |
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).
Running
./gradlew assembleDebug
or./gradlew bundleRelease
thennpx 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
Expected behavior
Build should not fail with this error.
Detox Trace-Logs
NA
Device logs (adb logcat)
NA
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: