Skip to content
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

[BREAKING] Upgrade to gradle 4.1 and android gradle plugin 3 #468

Merged
merged 7 commits into from
Dec 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ matrix:
- REACT_NATIVE_VERSION=0.49.3
android:
components:
- build-tools-25.0.3
- android-25
- build-tools-27.0.2
- build-tools-26.0.2
- android-27
- extra-android-m2repository
- extra-google-google_play_services
- extra-google-m2repository
- sys-img-armeabi-v7a-android-26
- sys-img-armeabi-v7a-android-27
install:
- ./scripts/install.android.sh
script:
Expand Down
8 changes: 3 additions & 5 deletions detox/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.palantir:jacoco-coverage:0.4.0'
classpath 'com.android.tools.build:gradle:3.0.1'
}
}

allprojects {
repositories {
mavenLocal()
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
}
48 changes: 17 additions & 31 deletions detox/android/detox/build.gradle
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
apply plugin: 'com.android.library'
apply plugin: 'com.palantir.jacoco-coverage'
apply plugin: 'com.palantir.jacoco-full-report'

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 18
targetSdkVersion 25
versionCode 1
versionName "1.0"
}

publishNonDefault true

productFlavors {
oldOkhttp {
flavorDimensions "minReactNative"
minReactNative44 {
dimension "minReactNative"

}
newOkhttp {

minReactNative46 {
dimension "minReactNative"
}
}

testOptions {
unitTests.returnDefaultValues = true
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}


unitTests.all { t ->
reports {
Expand Down Expand Up @@ -65,27 +57,21 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

minReactNative44Implementation 'com.squareup.okhttp3:okhttp:3.4.1'
minReactNative44Implementation 'com.squareup.okhttp3:okhttp-ws:3.4.1'

oldOkhttpCompile 'com.squareup.okhttp3:okhttp:3.4.1'
oldOkhttpCompile 'com.squareup.okhttp3:okhttp-ws:3.4.1'
minReactNative46Implementation 'com.squareup.okhttp3:okhttp:3.6.0'
minReactNative46Implementation 'com.squareup.okio:okio:1.13.0'

newOkhttpCompile 'com.squareup.okhttp3:okhttp:3.6.0'
newOkhttpCompile 'com.squareup.okio:okio:1.13.0'

compile('com.android.support.test.espresso:espresso-core:3.0.0', {
implementation('com.android.support.test.espresso:espresso-core:3.0.0', {
exclude group: 'com.google.code.findbugs'
})

compile 'org.apache.commons:commons-lang3:3.4'

compile 'com.android.support.test:runner:1.0'
compile 'com.android.support.test:rules:1.0'
compile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'

testCompile 'org.json:json:20140107'
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:3.5.2'
testCompile 'org.apache.commons:commons-io:1.3.2'
testImplementation 'org.json:json:20140107'
testImplementation 'junit:junit:4.12'
testImplementation 'org.assertj:assertj-core:3.5.2'
testImplementation 'org.apache.commons:commons-io:1.3.2'
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.wix.detox.espresso;

import android.app.UiAutomation;
import android.content.Context;
import android.os.Handler;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.ViewInteraction;
import android.support.test.uiautomator.InstrumentationUiAutomatorBridge;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Choreographer;
Expand All @@ -26,9 +24,6 @@
public class UiAutomatorHelper {
private static final String LOG_TAG = "detox";

private static final String CLASS_INTERACTION_CONTROLLER =
"android.support.test.uiautomator.InteractionController";

private static final String FIELD_UI_CONTROLLER = "uiController";

private static final String METHOD_LOOP_UNTIL_IDLE = "loopMainThreadUntilIdle";
Expand Down Expand Up @@ -76,31 +71,6 @@ public void run() {
});
}

private static Object interactionController = null;

public static Object getInteractionController() {
if (interactionController != null) {
return interactionController;
}
UiAutomation uiAutomation;
if (android.os.Build.VERSION.SDK_INT >= 24) {
uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation(UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES);
} else {
uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
}
Context ctx = InstrumentationRegistry.getContext();
InstrumentationUiAutomatorBridge bridge = new InstrumentationUiAutomatorBridge(ctx, uiAutomation);
Class<?> interActionControllerClass;
try {
interActionControllerClass = Class.forName(CLASS_INTERACTION_CONTROLLER);
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "Can't find InteractionController class. UiAutomator is not on classpath?", e);
throw new RuntimeException(e);
}
interactionController = Reflect.on(interActionControllerClass).create(bridge).get();
return interactionController;
}

public static float getDensity() {
Context context = InstrumentationRegistry.getTargetContext().getApplicationContext();
return context.getResources().getDisplayMetrics().density;
Expand Down
4 changes: 2 additions & 2 deletions detox/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Jun 25 19:58:35 IDT 2017
#Wed Dec 20 14:09:27 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
18 changes: 16 additions & 2 deletions detox/src/devices/AndroidDriver.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const {spawn} = require('child_process');
const path = require('path');
const fs = require('fs');
const _ = require('lodash');
const log = require('npmlog');
const invoke = require('../invoke');
Expand Down Expand Up @@ -27,8 +29,20 @@ class AndroidDriver extends DeviceDriverBase {

async installApp(deviceId, binaryPath) {
await this.adb.install(deviceId, binaryPath);
const testApkPath = binaryPath.split('.apk')[0] + '-androidTest.apk';
await this.adb.install(deviceId, testApkPath);
await this.adb.install(deviceId, this.getTestApkPath(binaryPath));
}

getTestApkPath(originalApkPath) {
const originalApkPathObj = path.parse(originalApkPath);
let splitPath = originalApkPathObj.dir.split(path.sep);
splitPath.splice(splitPath.length-1 , 0, 'androidTest');
const testApkPath = path.join(splitPath.join(path.sep), `${originalApkPathObj.name}-androidTest${originalApkPathObj.ext}`);

if (!fs.existsSync(testApkPath)) {
throw new Error(`'${testApkPath}' could not be found, did you run './gradlew assembleAndroidTest' ?`);
}

return testApkPath;
}

async uninstallApp(deviceId, bundleId) {
Expand Down
2 changes: 1 addition & 1 deletion detox/src/devices/android/Emulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Emulator {
tail.unwatch();
fs.closeSync(stdout);
fs.closeSync(stderr);
fs.unlink(tempLog);
fs.unlink(tempLog, () => {});
promise._cpResolve();
}

Expand Down
24 changes: 10 additions & 14 deletions detox/test/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ apply plugin: "com.android.application"
apply from: "../../node_modules/react-native/react.gradle"

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
compileSdkVersion 27
buildToolsVersion '27.0.2'

defaultConfig {
applicationId "com.wix.detox.test"
minSdkVersion 18
targetSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
testBuildType System.getProperty('testBuildType', 'debug')
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
missingDimensionStrategy "minReactNative", "minReactNative46"
/*
testInstrumentationRunnerArguments = [
'detoxServer': 'ws://localhost:8099',
Expand All @@ -25,9 +26,6 @@ android {
*/
}

//unremark to generate app-release-androidTest.apk for release tests
//testBuildType "release"

signingConfigs {
release {
storeFile file("keystore.jks")
Expand All @@ -52,15 +50,13 @@ android {
}

dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:25.3.1"
compile "com.facebook.react:react-native:+" // From node_modules

testCompile 'junit:junit:4.12'
implementation "com.android.support:appcompat-v7:27.0.2"
implementation "com.facebook.react:react-native:+" // From node_modules

androidTestCompile(project(path: ":detox", configuration: "newOkhttpDebug"), {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation(project(path: ":detox"))
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test:rules:1.0.1'
}

// Run this once to be able to run the application with BUCK
Expand Down
8 changes: 3 additions & 5 deletions detox/test/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.palantir:jacoco-coverage:0.4.0'
classpath 'com.android.tools.build:gradle:3.0.1'
}
}

allprojects {
repositories {
mavenLocal()
jcenter()
maven {
url "https://maven.google.com"
}
google()
maven {
url "$projectDir/../../node_modules/react-native/android"
}
Expand Down
1 change: 1 addition & 0 deletions detox/test/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
# org.gradle.parallel=true

android.useDeprecatedNdk=true
android.enableAapt2=false
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
4 changes: 2 additions & 2 deletions detox/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
}
},
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/app-debug.apk",
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_24"
},
"android.emu.release": {
"binaryPath": "android/app/build/outputs/apk/app-release.apk",
"binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
"build": "cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_26"
Expand Down
Loading