Can Gradle build Instrumentation tests without running them? - android

TL:DR
I am looking for a way to make sure our Instrumentation testing suite compiles, but without actually running it. Is it possible to achieve that using the Android plugin for Gradle?
I looked over official documentation and I don't see anything other than a Gradle command that compiles and then runs tests together.
The reason I am looking for this is we want to be able to run a build on every Pull Request but running the suite takes way too long. Yet we want to make sure the instrumentation suite at least compiles with all the code changes so it can run in its time.
Thanks for your help

Can be achieved, gradle is running everything as task, I hope you are executing:
./gradlew test
and you can see output as
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2501Library
:app:prepareComAndroidSupportAppcompatV72501Library
:app:prepareComAndroidSupportDesign2501Library
:app:prepareComAndroidSupportRecyclerviewV72501Library
:app:prepareComAndroidSupportSupportCompat2501Library
:app:prepareComAndroidSupportSupportCoreUi2501Library
:app:prepareComAndroidSupportSupportCoreUtils2501Library
:app:prepareComAndroidSupportSupportFragment2501Library
:app:prepareComAndroidSupportSupportMediaCompat2501Library
:app:prepareComAndroidSupportSupportV42501Library
:app:prepareComAndroidSupportSupportVectorDrawable2501Library
:app:prepareComAndroidSupportTransition2501Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:incrementalDebugUnitTestJavaCompilationSafeguard UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:compileDebugUnitTestJavaWithJavac
:app:processDebugJavaRes UP-TO-DATE
:app:processDebugUnitTestJavaRes UP-TO-DATE
:app:compileDebugUnitTestSources
:app:mockableAndroidJar
:app:assembleDebugUnitTest
:app:testDebugUnitTest
:app:checkReleaseManifest
:app:prepareReleaseDependencies
:app:compileReleaseAidl
:app:compileReleaseRenderscript
:app:generateReleaseBuildConfig
:app:generateReleaseResValues
:app:generateReleaseResources
:app:mergeReleaseResources
:app:processReleaseManifest
:app:processReleaseResources
:app:generateReleaseSources
:app:incrementalReleaseJavaCompilationSafeguard
:app:compileReleaseJavaWithJavac
:app:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:incrementalReleaseUnitTestJavaCompilationSafeguard UP-TO-DATE
:app:preReleaseUnitTestBuild UP-TO-DATE
:app:prepareReleaseUnitTestDependencies
:app:compileReleaseUnitTestJavaWithJavac
:app:processReleaseJavaRes UP-TO-DATE
:app:processReleaseUnitTestJavaRes UP-TO-DATE
:app:compileReleaseUnitTestSources
:app:assembleReleaseUnitTest
:app:testReleaseUnitTest
:app:test
BUILD SUCCESSFUL
which is tasks call hierarchy, means task "test" is dependent on all or one above task i.e. "app:testReleaseUnitTest". so you can call upto "assembleReleaseUnitTest"
./gradlew assembleReleaseUnitTest

Found the Gradle task to achieve this:
$ ./gradlew compileDebugAndroidTestJavaWithJavac
Above task will compile Instrumented tests without actually running them.

Related

React Native Blank White Screen in Android

I was following this tutorial https://facebook.github.io/react-native/docs/getting-started.html, but when i build the project using this command: react-native run-android, i got this message
Starting JS server... Running
/home/nakama/Android/Sdk/platform-tools/adb -s 915fdc90 reverse
tcp:8081 tcp:8081 adb server version (32) doesn't match this client
(36); killing...
* daemon started successfully * Building and installing the app on the device (cd android && ./gradlew installDebug... :app:preBuild
UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72301Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42321Library UP-TO-DATE
:app:prepareComFacebookFrescoDrawee0110Library UP-TO-DATE
:app:prepareComFacebookFrescoFbcore0110Library UP-TO-DATE
:app:prepareComFacebookFrescoFresco0110Library UP-TO-DATE
:app:prepareComFacebookFrescoImagepipeline0110Library UP-TO-DATE
:app:prepareComFacebookFrescoImagepipelineBase0110Library UP-TO-DATE
:app:prepareComFacebookFrescoImagepipelineOkhttp30110Library
UP-TO-DATE :app:prepareComFacebookReactReactNative0350Library
UP-TO-DATE :app:prepareComFacebookSoloaderSoloader010Library
UP-TO-DATE :app:prepareOrgWebkitAndroidJscR174650Library UP-TO-DATE
:app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig
UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets
UP-TO-DATE :app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE :app:mergeDebugResources
UP-TO-DATE :app:bundleDebugJsAndAssets SKIPPED
:app:processDebugManifest UP-TO-DATE :app:processDebugResources
UP-TO-DATE :app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE :app:compileDebugJavaWithJavac
UP-TO-DATE :app:compileDebugNdk UP-TO-DATE :app:compileDebugSources
UP-TO-DATE :app:preDexDebug UP-TO-DATE :app:dexDebug UP-TO-DATE
:app:validateDebugSigning :app:packageDebug UP-TO-DATE
:app:zipalignDebug UP-TO-DATE :app:assembleDebug UP-TO-DATE
:app:installDebug Installing APK 'app-debug.apk' on 'Mi 4i - 5.0.2'
Installed on 1 device.
BUILD SUCCESSFUL
Total time: 20.971 secs
This build could be faster, please consider using the Gradle Daemon:
http://gradle.org/docs/2.4/userguide/gradle_daemon.html Starting the
app (/home/nakama/Android/Sdk/platform-tools/adb shell am start -n
com.awesomeproject/.MainActivity... adb server version (32) doesn't
match this client (36); killing...
* daemon started successfully * Starting: Intent { cmp=com.awesomeproject/.MainActivity }
and the result is my apps always shows blank screen. I did not change any single javascript code on those project, what is the root caused which makes my apps always give me a blank screen ?
Please set your ip address in developer menu of react native. Follow this link
Running on android device. to run on android device.
When you using this command: 'react-native run-android'. You should use press 'R' twice times or Ctrl + M (open option menu and choose reload) to reload screen and see result. I recommend use Genymotion for android emulator.
Cheer! =))

Custom linting lib in android

My team and I develop Android apps and have decided on coding guidelines that all should follow. I therefore started implementing custom lint rules as per the following links:
Post written by Matt Compton
Git Repo
The problem that I'm having is actually implementing these lint rules on a project basis. When I run ./gradlew clean build test install , as specified the rules apply and all is well. However when I build the aar library with ./gradlew aarWrapper:assemble and add it to my libs folder the linting does not work.
I added the following to my build.gradle file to add the library
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name: 'aarWrapper-debug', ext: 'aar')
}
I'm not sure what I'm missing but when I run ./gradlew lint it runs the linter but not with my custom rules... Any help, tips or advice is greatly appreciated.
EDIT 1
Here is the terminal output when running gradle.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareAarWrapperDebugLibrary UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2421Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72421Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2421Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCompat2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUi2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUtils2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportFragment2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportMediaCompat2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2421Library UP-TO-DATE
:app:prepareComAndroidVolleyVolley100Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidAnswers138Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidBeta121Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlytics261Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlyticsCore2310Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase961Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement961Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesLocation961Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMaps961Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesTasks961Library UP-TO-DATE
:app:prepareIoFabricSdkAndroidFabric1312Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:transformClassesWithDexForDebug UP-TO-DATE
:app:mergeDebugJniLibFolders UP-TO-DATE
:app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:validateSigningDebug
:app:packageDebug
:app:assembleDebug
BUILD SUCCESSFUL
Total time: 7.881 secs
EDIT 2
Forked project: https://github.com/apertomove/linette
build.gradle: https://github.com/apertomove/linette/blob/apertomove-linette/build.gradle
EDIT 3
In addition to the links above I found this post written by Jason Atwood. We too have a CI server running jenkins in which we can run our checks and inform developers of errors based off of our lint rules. This works great, however, it is one step to far. It would be much more valuable and time save to run lint checks from the library when running our projects out of Android Studio, instead of committing our code only to find out that our project breaks rules.
I have written a post on how to add and integrate custom lint rules to your android app, you can have a look. It also has links to github repos showing how its done in an android project.
Link to post
The easiest way for me was to set ANDROID_LINT_JARS path in the gradlew file and point it to the custom lint jar which is checked in to VCS system, so that you can run it locally as well before pushing the code.
Hope it helps.
#hopeman copy the jar file to the /.android/lint folder. Android will pick your custom lint rules.

Error:Execution failed for task ':app:transformClassesWithInstantRunSlicerForDebug'. > java.io.IOException:

whenever I try to run my app i get this error :
Error:Execution failed for task
:app:transformClassesWithInstantRunSlicerForDebug'.
java.io.IOException: Failed to delete
C:\Users\ashis\AndroidStudioProjects\FirstApp\app\build\intermediates\instant-run-support\debug\restart-changes.txt**
and here is the output:
Information:Gradle tasks
[:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2340Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72340Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42340Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2340Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:buildInfoDebugLoader
:app:transformClassesWithExtractJarsForDebug UP-TO-DATE
:app:transformClassesWithInstantRunVerifierForDebug UP-TO-DATE
:app:transformClassesWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:mergeDebugJniLibFolders UP-TO-DATE
:app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:transformResourcesAndNative_libsWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:transformClassesWithInstantRunForDebug UP-TO-DATE
:app:transformClasses_enhancedWithInstant+reloadDexForDebug UP-TO-DATE
:app:incrementalDebugTasks
:app:prePackageMarkerForDebug
:app:fastDeployDebugExtractor UP-TO-DATE
:app:generateDebugInstantRunAppInfo UP-TO-DATE
:app:coldswapKickerDebug
:app:transformClassesWithInstantRunSlicerForDebug FAILED
Error:Execution failed for task ':app:transformClassesWithInstantRunSlicerForDebug'.
java.io.IOException: Failed to delete C:\Users\ashis\AndroidStudioProjects\FirstApp\app\build\intermediates\instant-run-support\debug\restart-changes.txt
Information:BUILD FAILED
Information:Total time: 1 mins 6.761 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
:app:transformClassesWithInstantRunSlicerForDebug'.
java.io.IOException: Failed to delete
-- try to clean project and rebuild project.
From #Kael: A clean is performed via Build -> Clean Project or Build -> Rebuild Project.
Kindly follow these steps:
Goto
1>File
2>Settings
3>Build,Execution,Deployment
4>Instant Run
5>Uncheck (Enable Instant Run to hot swap code)
So this helped me.
In my situation Build Menu > Clean Project and Build Menu > Rebuild did NOT work. Instead I had to delete the build folder manually from the filesystem (using Finder on OSX, Explorer on Win).
Try to clean project and rebuild project from Build Menu > Clean Project and Build Menu > Rebuild
try restarting android studio or use android studio on different user
I had the same problem .. I solved my problem by deleting .gradle file on my project root and rebuilt my project again.
I had Execution failed for task ':app:generateDebugBuildConfig'. error, cleaning and rebuilding project was not working.
I added C:\Users\...\AppData\Local\Android\sdk\tools to my PATH Environment variable.
I closed android studio and vscode that I was using for edit project files. (This is very important)
I run the project and it worked fine.
Change this https://services.gradle.org/distributions/gradle-4.4-all.zip to this https://services.gradle.org/distributions/gradle-4.1-all.zip in grable-wrapper.prperties. And then re import the properties. and sync the project.

Can't Build .apk in Android studio 1.3?

Currently i am trying to run a sample application "Hello Gimbal Android" using Android Studio 1.3 (updated 28 july 2015)
After follow step by step from tutorial :
Clone sample application from github.
Import project in Android Studio
Fill in the API key in MainActivity file.
Add the jars from the Gimbal SDK libs directory to the project libs directory
Last step is build the project (using Build -> Make Project)
It is successfully built as shown in grandle console but after that i search it cant find the .apk file.
Anyone has this experience before? Any clue?
Executing tasks: [:app:compileDebugSources, :app:compileDebugAndroidTestSources]
Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest UP-TO-DATE
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestAssets UP-TO-DATE
:app:mergeDebugAndroidTestAssets UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources UP-TO-DATE
:app:generateDebugAndroidTestSources UP-TO-DATE
:app:compileDebugAndroidTestJava
:app:compileDebugAndroidTestNdk UP-TO-DATE
:app:compileDebugAndroidTestSources
BUILD SUCCESSFUL
Total time: 5.7 secs
Note :
I use ubuntu 14.04, have downloaded the Android SDK and also have configured the PATH.
When you just build, you don't get an apk.
For an unsigned apk you need to either
- Run the app (Run > Run "YourProject")
- Execute assemble Task from Gradle panel (present in right hand side of the
Studio window) or from the embedded terminal window on bottom (in project Root)
Then the apk is in $YOUR_PROJECT/$YOUR_MODULE/build/outputs/apk
For a signed apk, use Build -> Generate Signed APK
If you look in the Gradle Console Rebuild Project will say something like...:
See here. Perhaps help you...

Android Studio Gradle :app:preDexDebug never finishes

I have an issue and despite of a lot of googling, i couldn't find any informations about it.
So I have Windows 7 and had Android Studio 1.1 RC Beta and after modifying my code regarding work with a database i got failure install_failed_dexopt
I tried to clean and then to rebuild my project and since that moment Gradle Executing Tasks never finishes if i run my project. I saw into the Gradle logs and here it is
Executing tasks:
[:app:assembleDebug]
Configuration on demand is an incubating feature.
:app:preBuild
:app:compileDebugNdk UP-TO-DATE
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:app:prepareComAndroidSupportAppcompatV72102Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42102Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug
I waited ~30 minutes and nothing after that.
If i try to stop it, it also never stops, i see only
Stopping - Gradle: Executing Tasks[:app:assembleDebug]
and nothing else
I tried to unistall Android Studio, installed also 1.0.1, I tried to run "hello world" application - is always the same. It would be great if someone have any idea about it, thank you!
So it seemed to be a problem with sdk. At first I didn't notice, that even if I install Android Studio and sdk into another folder path to sdk was always the same and it was something wrong with that sdk directorie.

Categories

Resources