Skip to content

Commit

Permalink
Compiling detox test project from RN sources for debug/development pu…
Browse files Browse the repository at this point in the history
…rposes.
  • Loading branch information
rotemmiz committed Mar 20, 2018
1 parent 8668f7b commit 1b21bdb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
14 changes: 13 additions & 1 deletion detox/test/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ android {
*/
}

productFlavors {
flavorDimensions "compileRNFromSource"
fromSource {
dimension "compileRNFromSource"
}
fromBin {
dimension "compileRNFromSource"
}
}

signingConfigs {
release {
storeFile file("keystore.jks")
Expand All @@ -51,7 +61,9 @@ android {

dependencies {
implementation "com.android.support:appcompat-v7:27.0.2"
implementation "com.facebook.react:react-native:+" // From node_modules

fromSourceImplementation(project(path: ":ReactAndroid"))
fromBinImplementation "com.facebook.react:react-native:+"

androidTestImplementation(project(path: ":detox"))
androidTestImplementation 'junit:junit:4.12'
Expand Down
1 change: 1 addition & 0 deletions detox/test/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'de.undercouch:gradle-download-task:3.1.2'
}
}

Expand Down
5 changes: 4 additions & 1 deletion detox/test/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ rootProject.name = 'DetoxTest'
include ':app'

include ':detox'
project(':detox').projectDir = new File(rootProject.projectDir, '../../android/detox')
project(':detox').projectDir = new File(rootProject.projectDir, '../../android/detox')

include ':ReactAndroid'
project(':ReactAndroid').projectDir = new File(rootProject.projectDir, '../node_modules/react-native/ReactAndroid')
10 changes: 8 additions & 2 deletions detox/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@
},
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"build": "cd android && ./gradlew assembleFromBinDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_26"
},
"android.emu.release": {
"binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
"build": "cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..",
"build": "cd android && ./gradlew assembleFromBinRelease assembleAndroidTest -DtestBuildType=release && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_26"
},
"android.emu.debug.fromSource": {
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build": "cd android && ./gradlew assembleFromSourceDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_26"
}
Expand Down
16 changes: 16 additions & 0 deletions docs/Guide.Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ npm run build:android
npm run e2e:android
```

Android test project includes two flavors:
`fromBin` - uses the precompiled aar from `node_moudles` just like a standard RN project.
`fromSource` - compiles the project with RN sources from `node_modules`, this is useful when developing and debugging Espresso idle resource.
[Here](https://facebook.github.io/react-native/docs/building-from-source.html#android) are the prerequisites to compiling React Native from source.

Each build can be triggered separately by running its assemble task:
`./gradlew assembleFromSourceDebug` or `./gradlew assembleFromBinDebug`.

To run from Android Studio, React native `react.gradle` script requires `node` to be in path.
on macOS environment variables can be exported to desktop applications by adding the following to your `.bashrc`/`.zshrc`:

```sh
launchctl setenv PATH $PATH
```


### 3. Android Native tests

0. Install Java and Android SDK 25
Expand Down

0 comments on commit 1b21bdb

Please sign in to comment.