When running a unit test from within Android Studio on a mac, I can manually run it 1 time, then it fails with the error "Could not execute build using Gradle distribution 'https://services.gadles.org/distributions/gradle-4.10-all.zip'".
I can run it again by deleting my .gradle folder and restarting Android Studio, but this isn't sustainable for testing.
When running the unit test manually with ./gradlew, it works every time but that doesn't lend itself well to debugging.
This applies to even the most simple of tests.
Wanted to add specific error message from the Build tab. This happens on a simple test, with the first time running it working, and the second time running it not working:
#Test
fun testTrue(){
assertTrue(true)
}
FAILURE: Build failed with an exception.
* What went wrong:
java.lang.NullPointerException (no error message)
So, I have a suspect that could be the cause, and a hack that makes it work in the short term.
First, the hack. As many other people have answered, deleting the .gradle folder resolves the issue for me temporarily. However, that is a bit over overkill and forces a complete build every time you run it.
You can get around this partially by deleting just the fileHashes.bin and fileHashes.lock file in .gradle/4.7/fileHashes folder. I wrote a quick script to delete those two files and edited the "Android JUnit" Template in "Run/Debug Configurations" to run that script before every junit run. See screenshot for details, but you'll need to make sure it is the first thing that runs. (Drag it to the first)
The .bsh file is an executable which just deletes those two files.
#!/bin/bash
echo This script deletes the .gradle files necessary for my android studio to work
cd wealth-android/.gradle/4.7/fileHashes
rm fileHashes.*
Now, the real problem may be that I could have multiple implementations of gradle on my machine. I'll look into that more and update the answer.
Related
I'm new to android and android studio is taking too long to build
and I'mscreenshoot not sure why
I have noticed that sometimes Android Studio builds either get stuck or slow down for seemingly no reason. First thing to try would be to quit Android Studio, then run ./gradlew --stop from the command line to make sure any Gradle deamons have been shut down completely. You may also want to do a ./gradlew clean to get rid of any intermediate files that might be troubling the build.
If that doesn't help, you may need to look into optimizing your build. There are lots of resources on the web, but you might want to start with the Android team's list of ideas.
I've created an Android module in Android Studio to create a home screen widget for including in a Delphi app. To do this I need to manually run part of the build process a second time via a manual build script. This script runs aapt to generate the R.java, then javac and dex to re-compile it with some additional modules, which works well.
However, the resulting app + widget doesn't work correctly and I suspect it's the R.java file not being complete. When I host the same widget in a native Java app, the resulting R.java generated by Gradle contains lots of additional items, which I believe may be the problem.
I'd like to see what the generateReleaseRFile Gradle task actually does - i.e. what terminal commands it runs, and, if it calls aapt, what parameters it passes into it so I can compare to my manual build script.
Does anyone know if this is possible?
Thanks!
I recently switched from Eclipse to Android Studio because I read that it is now the official IDE for Android application development. I downloaded and installed the latest version (1.0.2) for Windows. When using the program for the first time, I decided to create a test application to see if the program was working correctly. Unfortunately, it was not. Once I clicked the finish button to complete the New Project Wizard, A loading bar showed up that said Gradle: Build. This is where the program gets stuck. There is no error message and it appears that the program is running fine, however the build never actually completes. I am never given my MainActivity.Java class, or my activitymain.xml document. If I click the cancel button, the program freezes and I have to use the TaskManager to kill the program. If I re-enter the program and choose to open an existing project, my project will be there. However, upon trying to open the project, I am greeted with the same Gradle: Build loading bar.. I have been searching for an answer for the last 3 days and nothing has worked. Any help is greatly appreciated!
Things I have tried:
Simply letting the program sit for a while to see if it was actually downloading something and was just really slow. I let it sit for 45+ minutes before killing the program.
Uninstalling and re-installing Android Studio
Restarting my computer
Turning off my firewall (Kaspersky)
Running the program as an administrator
Connecting to a different network
Disconnecting my computer from any networks (to force the program to build in offline mode)
Manually downloading Gradle from the link that Android Studio attempts to use when it gets stuck and telling the program to use that file instead of downloading another one.
(I went to this link https://services.gradle.org/distributions/gradle-2.2.1-all.zip, downloaded the file, unzipped it, went to Gradle settings in Android Studio, checked the Offline work checkbox, and finally set the service directory path to my unzipped Gradle folder.)
Hopefully I have given enough information and made it clear what my problem is. If not please tell me what else I need to explain so I can get this issue resolved. Thanks!
Please note I am working on a 64 bit machine running Windows 8. Also, I use studio64.exe
to run the program.
From the discussion we had in the comments, it does not look like you have your gradle on your windows path.
Please change the below to point to your gradle install:
set GRADLE_HOME=C:\<installation location>\gradle-1.11
set PATH=%PATH%;%GRADLE_HOME%\bin
After this, verify that in the terminal running the following works:
gradle tasks
once you get this working, you will want to run the following in your project:
gradle wrapper
This will produce a .bat file which you can then use to run gradle through the wrapper, letting you support multiple native gradle installations.
I am trying to set up a CI environment with Jenkins and Robotium. I want to use the same project for both built and test, but seems so tricky to get all working. I was wondering if someone had something like that working and if it can publish at least build.gradle and the project structure. Thanks.
Have been running in production for a few months now. See this question for a sample project and video of how to use robotium with gradle.
https://stackoverflow.com/a/23295849/1965124
As for the jenkins side of things:
Install the android sdk on the machine that will be running jenkins
set up android home variable
install the android plugin
run the following tasks from inside a jenkins job: clean connectedAndroidTest
after running 1 build (it will fail the first time), change the local.properties file to point to the local installation of the android sdk.
Let me know if you need any more pointers, its not as hard as I initially thought it would be.
I configured TeamCity as CI server. Also, project builds by Gradle.
The main idea is to execute gradle connectedInstrumentTest, that task will execute all project's tests on all connected devices, then it will put the test results in standard ant-junit format, so then you can set Jenkins to parse app-folder/build/instrumentTest-results/connected/*.xml test results.
If you got more questions, you can post them to the comments.
I would like test our android applications via Jenkins. I configured everything, but i got this error message:
[android] Emulator did not appear to start; giving up
I found a solution for this problem from here
This one can have several reasons. One of them is listed in the error below. I didn't encounter this myself but I've read on stackoverflow while looking for a solution to my specific issue. It seems to be related to the revision of the android sdk tools. On windows there was a fix like stated in this ticket: https://issues.jenkins-ci.org/browse/JENKINS-10815
However there seems to be a similar issue on linux that isn't fixed yet (at least the ticket is still open): https://issues.jenkins-ci.org/browse/JENKINS-14901
Solution: The proposed solution in that ticket is to create a link with the name emulator (back original) towards the appropriate emulator-X bin.
I tried it and solved our problem, but only some builds, after that I got again this message. That's why i removed the android plugin and deleted the sdk folder, so i reinstall everything. After that there were 4 success builds. (Interesting, that i didn't create emulator link like than before) But it was all, the problem backed. I played with configuration and set 30 second delay for emulator start and checked the "delete emulator after build" option. I thought that the problem solved because I had 14!!! success build but the problem backed again :(
And now there is a new error message too:
NAND: could not write file /tmp/android-jenkins/emulator-CaWkYU, File exists
[android] Emulator did not appear to start; giving up
What are you thinking, what is the problem? With same setting sometimes success, sometimes not. Why?
Finally i found the problem in the source code:
AndroidEmulator.java
The adb connection timeout is 1min and it's fix:
private static final int ADB_CONNECT_TIMEOUT_MS = 60 * 1000;
So i increment it to 5 mins, build a new plugin and installed and it solved my problem (~100 build without this problem)
How many build executors do you have (default is 2)? I bet you can only have one emulator running on your Jenkins server at a time, when two jobs are trying to execute, one job is getting clobbered. If this is the case, you may want to consider the Heavy Build plugin to lock up all executors when an Android job goes by. Or use slaves.
You can check pull request which has fixes for this issue. Before merging PR to the main repo and get new plugin version, just download project from the author's forked repo and run command:
mvn install
from the project root directory. After that take "android-emulator.hpi" file located in
"<project root>/target"
directory and update/install plugin from the Jenkins Web UI
Manage Jenkins -> Manage Plugins -> Advanced
then reboot Jenkins CI. In project configuration use option
"Build Environment" -> "Common Emulator Options" -> "Advanced" -> "Adb timeout"
set it to 300 sec, for instance.