Skip to content

Commit 9655d3a

Browse files
android: fix libc++_shared packaging in 0.59
Fixes an error merging the JNI libs caused by both the react-native application and the nodejs-mobile-react-native plugin setting the same C++ STL. Detects currently used react-native version and only set the STL from the plugin if the version is earlier than 0.59.
1 parent c6d9a23 commit 9655d3a

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

android/build.gradle

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,35 @@ apply plugin: 'com.android.library'
1313

1414
def _nodeTargetSdkVersion = ((rootProject?.ext?.properties?.targetSdkVersion) ?: 22)
1515

16+
def DoesAppAlreadyDefineWantedSTL() {
17+
// Since react-native 0.59.0, the Application already defines libc++_shared as the APP_STL.
18+
// Defining it also in this plugin would lead to a build error when merging assets.
19+
try {
20+
def _reactAndroidPropertiesFile = file("${rootDir}/../node_modules/react-native/ReactAndroid/gradle.properties");
21+
def _reactAndroidProperties = new Properties()
22+
if (_reactAndroidPropertiesFile.exists())
23+
{
24+
_reactAndroidPropertiesFile.withInputStream { _reactAndroidProperties.load(it) }
25+
}
26+
def _semver = _reactAndroidProperties.getProperty("VERSION_NAME").tokenize('.');
27+
if (_semver.size() != 3) {
28+
return false
29+
}
30+
def _major = _semver[0].toInteger()
31+
def _minor = _semver[1].toInteger()
32+
if ( _major > 0 || (_major == 0 && _minor >= 59) ) {
33+
return true
34+
} else {
35+
return false
36+
}
37+
38+
} catch ( Exception e ) {
39+
return false
40+
}
41+
}
42+
43+
def _isCorrectSTLDefinedByApp = DoesAppAlreadyDefineWantedSTL()
44+
1645
android {
1746
compileSdkVersion ((rootProject?.ext?.properties?.compileSdkVersion) ?: 23)
1847
buildToolsVersion ((rootProject?.ext?.properties?.buildToolsVersion) ?: "23.0.1")
@@ -25,7 +54,9 @@ android {
2554
externalNativeBuild {
2655
cmake {
2756
cppFlags ""
28-
arguments "-DANDROID_STL=c++_shared"
57+
if(!_isCorrectSTLDefinedByApp) {
58+
arguments "-DANDROID_STL=c++_shared"
59+
}
2960
}
3061
}
3162
ndk {

0 commit comments

Comments
 (0)