diff --git a/RNTester/android/app/build.gradle b/RNTester/android/app/build.gradle index c5a3f3c3526a9d..2391ab56a9b6d5 100644 --- a/RNTester/android/app/build.gradle +++ b/RNTester/android/app/build.gradle @@ -120,10 +120,12 @@ android { defaultConfig { applicationId "com.facebook.react.uiapp" - minSdkVersion 16 + minSdkVersion 18 targetSdkVersion 29 versionCode 1 versionName "1.0" + testBuildType System.getProperty('testBuildType', 'debug') // This will later be used to control the test apk build type + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } signingConfigs { release { @@ -149,6 +151,8 @@ android { minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release + // Detox-specific additions to pro-guard + proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro" } } } @@ -187,4 +191,8 @@ dependencies { } else { jscImplementation 'org.webkit:android-jsc:+' } + + // Use detox test library + androidTestImplementation('com.wix:detox:+') { transitive = true } + androidTestImplementation 'junit:junit:4.12' } diff --git a/RNTester/android/app/src/androidTest/java/com/facebook/react/uiapp/DetoxTest.java b/RNTester/android/app/src/androidTest/java/com/facebook/react/uiapp/DetoxTest.java new file mode 100644 index 00000000000000..f9febfa3b3845f --- /dev/null +++ b/RNTester/android/app/src/androidTest/java/com/facebook/react/uiapp/DetoxTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// This uses instructions from +// https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md#4-create-android-test-class + +package com.facebook.react.uiapp; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; +import androidx.test.rule.ActivityTestRule; +import com.wix.detox.Detox; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +@LargeTest +public class DetoxTest { + + @Rule + public ActivityTestRule mActivityRule = + new ActivityTestRule<>(RNTesterActivity.class, false, false); + + @Test + public void runDetoxTests() { + Detox.runTests(mActivityRule); + } +} diff --git a/build.gradle.kts b/build.gradle.kts index c57d8a30bd7188..b96f36ddd4280f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,6 +25,11 @@ allprojects { maven { url = uri("$rootDir/node_modules/jsc-android/dist") } + maven { + // https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md + // All of Detox's artifacts are provided via the npm module + url = uri("$rootDir/node_modules/detox/Detox-android") + } mavenLocal() google() jcenter() diff --git a/package.json b/package.json index b25085bca5024f..ea0905981bfa9d 100644 --- a/package.json +++ b/package.json @@ -159,6 +159,25 @@ "runner-config": "RNTester/e2e/config.json", "specs": "", "configurations": { + "android.emu.release": { + "binaryPath": "RNTester/android/app/build/outputs/apk/hermes/release/app-hermes-x86-release.apk", + "testBinaryPath": "RNTester/android/app/build/outputs/apk/androidTest/hermes/release/app-hermes-release-androidTest.apk", + "build": + "./gradlew RNTester:android:app:assembleRelease RNTester:android:app:assembleAndroidTest -DtestBuildType=release", + "type": "android.emulator", + "device": { + "avdName": "Nexus_6_API_29" + } + }, + "android.emu.debug": { + "binaryPath": "RNTester/android/app/build/outputs/apk/hermes/debug/app-hermes-x86-debug.apk", + "testBinaryPath": "RNTester/android/app/build/outputs/apk/androidTest/hermes/debug/app-hermes-debug-androidTest.apk", + "build": "./gradlew RNTester:android:app:assembleDebug RNTester:android:app:assembleAndroidTest -DtestBuildType=debug", + "type": "android.emulator", + "device": { + "avdName": "Nexus_6_API_29" + } + }, "ios.sim.release": { "binaryPath": "RNTester/build/Build/Products/Release-iphonesimulator/RNTester.app/", "build": "xcodebuild -workspace RNTester/RNTesterPods.xcworkspace -scheme RNTester -configuration Release -sdk iphonesimulator -derivedDataPath RNTester/build -UseModernBuildSystem=NO -quiet", diff --git a/template/android/build.gradle b/template/android/build.gradle index b9065bd4984929..3dad13374278d6 100644 --- a/template/android/build.gradle +++ b/template/android/build.gradle @@ -11,9 +11,11 @@ buildscript { google() jcenter() } + ext.kotlinVersion = '1.3.0' dependencies { classpath("com.android.tools.build:gradle:3.5.3") - + // for Detox + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }