Skip to content

Commit

Permalink
Fix cmake error on windows (software-mansion#3755)
Browse files Browse the repository at this point in the history
## Description
I get cmake error (`Invalid character escape '\K'.`) when using latest Reanimated on RN version 0.64.3, this will fix Android build on windows because latest version of reanimated doesn't provide prebuilt AAR for older version, so it will attempt to rebuild from source

![image](https://user-images.githubusercontent.com/15137312/200750965-a126493a-a1c6-4b62-85d0-c91a9f38bed3.png)

## Changes
- added method `toPlatformFileString(File path)` to android/build.gradle to replace windows file separator character with '/'
- call `toPlatformFileString` on cmake arguments REACT_NATIVE_DIR
- fix sources taken from [this PR](Kudo/react-native-v8#132)

## Test code and steps to reproduce
- create new project with RN v0.64.3
- install latest version of react-native-reanimated
- try to build apk for Android `./gradlew clean installDebug`

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Added TS types tests
- [ ] Added unit / integration tests
- [ ] Updated documentation
- [ ] Ensured that CI passes
  • Loading branch information
muhamad-rizki authored and fluiddot committed Jun 5, 2023
1 parent 9969b90 commit f5e32fe
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.android.Version
import org.apache.tools.ant.filters.ReplaceTokens
import org.apache.tools.ant.taskdefs.condition.Os
import groovy.json.JsonSlurper
import java.nio.file.Paths

Expand Down Expand Up @@ -183,6 +184,13 @@ def getReanimatedVersion() {
return major.toInteger()
}

def toPlatformFileString(String path) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
path = path.replace(File.separatorChar, '/' as char)
}
return path
}

boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
if (CLIENT_SIDE_BUILD) {
configurations.maybeCreate("default")
Expand Down Expand Up @@ -447,7 +455,7 @@ android {
"-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
"-DANDROID_TOOLCHAIN=clang",
"-DBOOST_VERSION=${BOOST_VERSION}",
"-DREACT_NATIVE_DIR=${reactNativeRootDir.path}",
"-DREACT_NATIVE_DIR=${toPlatformFileString(reactNativeRootDir.path)}",
"-DJS_RUNTIME=${JS_RUNTIME}",
"-DJS_RUNTIME_DIR=${jsRuntimeDir}",
"-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}",
Expand Down

0 comments on commit f5e32fe

Please sign in to comment.