Ok I want to use gradle to run my tests in an emulator.
gradle has two targets that allow me to run tests:
connectedCheck
deviceCheck
If I understood correctly, we should use deviceCheck to test stuff in an emulator, but when I run it runs no tests.
connectedCheck also doesn't work because it can't find a device (emulators don't appear in the Android Studio the way my cell phone do).
What I would like is (ideally):
run my gradle script
it boots up an emulator
it runs tests on that emulator
it turns down the emulator
I would also like to have a target that won't boot or turn down the emulator, but it will use one if one is up.
It's possible to do any of these things? I can't find documentation anywhere on how to configure gradle android plugin.
An emulated device is a connected device. I can't tell that gradle has a way of starting an emulator for you short of an Exec task. I leave a couple emulators always running in the background with -no-window, and on our CI I did up a little bash script to fire up a few at various API levels before gradle is invoked and then shut them down afterward.
I came here searching for an example of how deviceCheck is used. It seems like it's supposed to be self-evident.
Related
When I type in:
cordova run
The Cordova app is run in all added platforms. However, Android doesn't run because it always seems to need a specified target to run. When I run it specifically for the Android platform it needs a target, like:
cordova run android --target=Nexus_S_API_25
Since I like to run all platforms at once nicely, I am looking for a way to let Cordova know it should target Android in a specified emulator. Is there a way?
Thanks for your help.
This will work if your emulator is already running. Cordova is printing the following message in that case:
No target specified and no devices found, deploying to emulator
There seems to be no way to specify default targets in a config file. You can take a look at the logic for choosing the run target for the android platform yourself. AFAICT by checking code in cordova-cli and cordova-lib repos, nothing but the command line options are passed to the platform commands.
However, as you can tell from the code, if no target is specified, devices will take precedence over emulators. Among the emulators a started emulator will be chosen if available. So if you have your preferred emulator running and no android devices connected, you should be fine.
I am thinking of writing a simple app with Python+Kivy, mostly for my own use - nothing fancy. For development, I would like to be able to
Compile the app into a package
Run it on an Android emulator
Sadly, at the moment I cannot quite close the loop - and googling didn't help.
I believe I downloaded all the relevant tools: Kivy, buildozer, Android SDK. I typed in the Kivy 'hello world' app, and it runs fine without Android emulation - unfortunately, when running it under the emulator (with suggested architecture x86), I get an error INSTALL_FAILED_NO_MATCHING_ABIS. If I make an emulator device with an ARM architecture (which is pretty slow to run), I can at least install the app on the emulated device - but it crashes once loaded. Error message is not informative.
I am guessing somehow I need to build the package for the native x86 architecture (?) which is the recommended default emulator in the Android emulator wizard - is that right? If so, how do I do it with buildozer tool? Or maybe I can run it on the ARM architecture, without it crashing?
Some finer detail:
I am running on OSX
I am building the package with the suggested command buildozer -v android debug
To install the app, I drag it onto the emulator window (there probably is a better way..?)
The emulator is the one coming with Android SDK, I'm emulating the default 'Nexus 5X' phone
Android SDK version is 23
I suggest trying to install the app on a real device and connecting the device to your pc in debug mode and use adb logcat to get the log of the device to know what is causing the error. This way you can make sure if the problem rises from your code or your emulator environment.
Your setup sounds fine, the immediate problem is entirely the architecture (although the crash on your ARM emulator suggests that your app has a bug, which you can debug by checking out the logcat log).
python-for-android supports x86 and will work on the emulator this way. You can use this with --arch=x86. However, buildozer does not currently expose this option (it hardcodes armeabi-v7a). This wouldn't be difficult to fix, feel free to open an issue in the buildozer github repository about it.
I'll note that if you have a device available, debugging using that isn't really any different (or slower/faster) than using the emulator. Buildozer/python-for-android can push the apk and run it automatically, and viewing the logcat output works the same in both cases.
I have written a demo application which includes unit, instrument and automation testing in android. I am able to successfully test, generate test report using gradle. Source code can be found here.
./gradlew connectedCheck works perfectly fine in Emulator but when i try to run the same test in android real devices i get connectedAndroidTestDebug FAILED
It's quite strange same test runs perfectly fine on Emulator.
Before the start of test when i run adb devices, i get the list of connected devices but right just the test finishes adb could not list the connected devices and i get the error as shown in stack trace above.
Anyone facing similar issue? Please suggest if there is any work around or i am missing anything here.
NOTE: Device driver, everything is installed i am able to run app, install APK on device, also as mentioned in android official documentation for android test support library, devices is running API 18.
Add this on your app.gradle file
project.gradle.taskGraph.whenReady {
connectedAndroidTestDebug {
ignoreFailures = true
}
}
I'm normally testing my android app on a physical device, but today I want to do some testing using an emulator. So I created one and it's running fine. I now want to install my app on my emulator. I normally install the app on my device using the Gradle task "installDebug". In the list of Gradle tasks I can't find anything which refers to the emulator though. Although this should be an easy thing to do, I can't find any place in Android Studio to do this.
So I found this question here on SO which explains a way to do it from the command line. Although I'm not afraid of the terminal it would be great if I can just do it from within Android studio/IntelliJ so it goes quick and easy.
Any tips on how to install my app on the emulator from within Android Studio (either using a Gradle task or not) would be great!
Emulator instances act just like physical devices for the purposes of the installDebug task in Gradle, in ADB, and the Android Debug Monitor. If you only have an emulator running and no physical device connected, most things will simply use the emulator by default without needing to ask you; if you have an emulator as well as devices, then you may need to choose which one to use in the same way you would if you had multiple physical devices.
I want to deploy on several emulator devices in android studio.
Just for testing it on different devices.
Is it possible?
Yes, it is possible.
Start a few emulators.
Create run configuration that shows chooser dialog (target device).
Run configuration.
Select all running emulators when Android Studio asks.
This will work only for non debug Android Application configuration, it will not work for Android Tests or debug configurations.
You can also run Gradle command connectedCheck to run tests on all devices outside of Android Studio.