Skip to content

Commit

Permalink
[BREAKING] Upgrade to gradle 4.1 and android gradle plugin 3 (#468)
Browse files Browse the repository at this point in the history
* Upgrade gradle and android gradle plugin, this is a breaking change, and it requires Android users to update to gradle 4.1

* Updated documentation
  • Loading branch information
rotemmiz authored Dec 24, 2017
1 parent d025437 commit 2cf0ee8
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 145 deletions.
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

4 comments on commit 2cf0ee8

@simonracz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

@mkosik
Copy link

@mkosik mkosik commented on 2cf0ee8 Jan 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, this looks great. When do you consider releasing a version (presumably 7?) with these changes in npm? Because you have already updated Introduction.Android.md, I have set up our project according to it as we use new versions of gradle & android gradle plugin, dependencies, build tools, react native & have all according changes in place, but have hit the wall with the current version of Detox.

@mkosik
Copy link

@mkosik mkosik commented on 2cf0ee8 Jan 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I've noticed you've made some changes upgrading to API level 27 - namely in test's app gradle.build (but set the target to 26) & according changes in travis, but when it comes to detox itself, it's still on API level 25, with 26 build tools. And finally, you are encouraging emu setup one with API level 24 and the other with 26 (while updating travis sys img component to 27). Why not to go all the way to API 27, is there anything that prevents it?
thx you for the gr8 work!

@rotemmiz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detox@7.0.0-alpha.0 is out. Try it, give feedback please.

Please sign in to comment.