working with UIautomator 2.0 and Android Studio 2.x - android-uiautomator

I was working with uiautomator 1.0.1 using eclispe and generating jar files and using in my setup.
Can anyone point to appropriate source where I can get step by step procedure for switching to Uiautomator 2.0 with Android Studio.

To use the Android Testing Support Library in your Gradle project, add these dependencies in your build.gradle file:
dependencies {
androidTestCompile 'com.android.support.test:runner:0.4'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.4'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
}
Also you need to set the JUnitRunner as the default test instrumentation runner in your Gradle project (UI Automator 2.0 uses android.support.test.runner.AndroidJUnitRunner instead of android.test.InstrumentationTestRunner).
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
For more details, follow the link here.

Related

Can't build kotlin files using gradle kotlin DSL in Intellij idea

I'm trying to set up a kotlin project with gradle kotlin DSL as build system in IntelliJ idea,but I'm getting below error when try to run buil.gradle.kts file. I have tried with different kotlin compiler version but no luck.
warning: default scripting plugin is disabled: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatible with this version of compiler
error: unable to evaluate script, no scripting plugin loaded
IntelliJ Version:
Gradle version : 6.3
build.gradle.kts
plugins {
id("org.jetbrains.kotlin.jvm") version "1.3.70"
// Apply the application plugin to add support for building a CLI application.
application
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// Use the Kotlin test library.
testImplementation("org.jetbrains.kotlin:kotlin-test")
// Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
application {
// Define the main class for the application.
mainClassName = "Music.AppKt"
}
The correct way to build a Gradle project in IDEA is to execute "Main menu | Build | Build project" if your build is delegated to Gradle in IDEA settings, or execute one of the build tasks in Gradle tool window: http://jetbrains.com/help/idea/work-with-gradle-tasks.html
However, the behavior you described can be considered a usability problem, I created an issue https://youtrack.jetbrains.com/issue/KT-37814, please follow it for updates.

Kotlin 1.3.20 with Gradle 5.1.1 compileKotlin2Js execute hot reload

In Kotlin 1.3.20 and Gradle 4.10.2, it is possible to hot reload js files with the following in Gradle:
task watch {
inputs.files 'src/main'
doLast {
compileKotlin2Js.execute()
}
}
However, then we get a warning of:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
With Kotlin 1.3.20 / Gradle 5.1.1, the deprecation warning goes away, but the compileKotlin2Js.execute() results in the following error:
Parameter specified as non-null is null: method org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute, parameter inputs
Is there a way to compileKotlin2Js.execute() for hot-reloading js files with Kotlin 1.3.20 / Gradle 5.1.1?
Answering own question, got Kotlin 1.3.72 multiplatform project working with Gradle 6.3 with Kotlin DSL: https://github.com/alexoooo/sample-multiplatform-boot-react
When developing, there are two processes:
Java back-end from IDE, run with: --server.port=8081
Webpack proxy with hot-reload: gradlew -t :proj-js:run
Note that Kotlin multiplatform projects are currently experimental, and some of the details are likely to change as the new IR is introduced: https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-4-m1-released/

Use of the 'compileOnly' scope in Android projects?

I'm using Gradle 2.12 (or newer) with an appropriate version of the Android Gradle plugin in my project. Gradle 2.12 introduced the compileOnly configuration, so why do I get an error when I try to use it?
Could not find method compileOnly() for arguments
Note the following sentence from the Gradle 2.12 release notes regarding the new compileOnly configuration (my emphasis):
You can now declare dependencies to be used only at compile time in conjunction with the Java plugin.
So the Java Gradle plugin is a component we need to consider when answering this question. We can find the compileOnly configuration declared in the Java Gradle plugin source code for new enough versions.
However, the Android Gradle plugins do not direct extend the Java Gradle plugin. In fact, I believe the Android plugins represent a sort of 'frankenplugin', with some functionality borrowed but not inherited from the Java plugin. The following chunks of source code support this idea.
From the base Android plugin class:
project.apply plugin: JavaBasePlugin
The Android Gradle plugins therefore incorporate functionality from the base Java Gradle plugin, not from the full Java Gradle plugin. Moreover, there is an explicit check that the full Java Gradle plugin is not applied alongside an Android Gradle plugin:
// get current plugins and look for the default Java plugin.
if (project.plugins.hasPlugin(JavaPlugin.class)) {
throw new BadPluginException(
"The 'java' plugin has been applied, but it is not compatible with the Android plugins.")
}
Based on this information, my guess is that compileOnly has just not been manually ported from the Java Gradle plugin to the Android Gradle plugin yet. It probably won't appear before we get an Android Gradle plugin with minimum Gradle version set at 2.12 or higher.
Simple use provided instead of compileOnly
See https://github.com/google/auto/issues/324#issuecomment-212333044

Android Gradle dependencies - only Maven?

I'm trying to get to know the Android Studio / Gradle build system, having come from Eclipse and Ant. In particular, I don't understand how the dependencies block in my build.gradle file works.
My current project has the following structure:
In my project I am using both the android support library (v4), and the jxl spreadsheet library. My build.gradle (the one inside the sub-module, not the root level one) currently looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
}
dependencies {
compile 'net.sourceforge.jexcelapi:jxl:2.6.+'
compile 'com.android.support:support-v4:13.0.+'
//compile fileTree(dir: 'libs', include: '*.jar')
}
On the second last line, you can see I've tried using the local copies of android-support-v4.jar and jxl.jar. I've also tried using the lines
compile files('libs/android-support-v4.jar')
compile files('libs/jxl.jar')
However, whenever I try to use the local .jar files, my build fails, saying that the Android support and jxl libraries cannot be found. I've seen lots of posts saying that you can simply use local .jars like this, however I cannot get this to work. If possible, I would like to be able to use my locally stored .jar files so I can work offline, when Maven isn't available.
Can anyone tell me why using the local .jar files doesn't work?
EDIT: I've also tried restarting the Android Studio IDE, and cleaning and re-building my project after adding the local jar dependency lines.
It's not finding the libs directory because it needs to be located at your module root instead of inside src/main. The paths in build.gradle are relative to the location of the build.gradle file, which lives in your module root.
For the Android support library, I'd recommend using the Maven dependency (e.g. compile 'com.android.support:support-v4:13.0.+') instead of including the jar file. With the support library, the Android Gradle plugin actually looks for it in your SDK instead of going out to the network for it; you have to have the support repository installed via the SDK manager. This is actually a little confusing and trips up a lot of users since it's not well-documented. But if you access it this way instead of just including the JAR, then the build system can be smarter about not trying to include duplicate copies of it and causing errors if you include other library projects that depend on it.

Android Studio missing external dependencies

I have a library project. I want to use Android's new build system. Currently I'm encountering a quite annoying scenario.
I have my dependencies defined on gradle.build but they never appear under External Libraries in Android Studio. Hence all the references to those libraries are marked as errors.
When I run gradle dependencies on the command line it shows the full dependencies tree and compiles successfully. The problem clearly is with Android Studio.
I tried to restart the IDE/OS but nothing.
This is my gradle.build
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.1'
}
}
apply plugin: 'android-library'
apply plugin: 'idea'
repositories {
mavenCentral()
}
dependencies {
compile 'junit:junit:4.11'
compile 'org.robolectric:robolectric:2.1:jar-with-dependencies'
compile 'com.google.android:android:4.1.1.4'
compile 'com.google.android:support-v4:r7'
compile 'info.cukes:cucumber-java:1.1.3'
compile 'info.cukes:cucumber-junit:1.1.3'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
versionCode 1
versionName "0.3-SNAPSHOT"
minSdkVersion 15
targetSdkVersion 17
}
}
UPDATE
This issue seems to be fixed on latest Android Studio version (0.2.5)
You can use 'Tools->Android->Sync project with Gradle files'. It will resolve the dependencies, download, and add them to external libraries.
Unfortunately, in the current version of Android Studio, the IDE is not completely integrated with the build system (gradle). You have to add the library once in gradle.build for compilation, and once via the GUI for code completion.
Right click on your project, select "Open Module Settings". Acknowledge the warning. Select "Libraries", "+", and add the library you are using. You can search for libraries on Maven in the dialog that appears. You should select your libs dir for the jar. Finally, add the library to your code's module. If your app is MyApp, you probably have MyApp and MyAppProject. You need to add it to MyApp. (You can probably also directly add it from the "Modules" page.)
To additionally get gradle to add the jar to your apk, make the following changes to your grade file. Replace:
compile 'org.jsoup:jsoup:1.6.1'
and similar with
compile files('libs/jsoup-1.6.1.jar')
Now it should all work.
I commented following line from build.gradle file and it started working.
//compile files('libs/android-support-v4.jar')
Previously dry build operation would succeed but when I would try to run on device there would be error
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;

Resources