How do I incorporate robolectric into an existing Android Studio project? - android-studio

The android ecosystem, particularly Android Studio, has been changing a lot over the last year or so. I've found many sets of instructions for incorporating robolectric into a project, written at many points during that period. And I haven't yet made one work on my project.
Which commands do I need to add to my app build.gradle?
Which commands do I need to add to my project build.gradle?
Do I need to use Junit 4 in order to use robolectric?
Are there other libraries needed? What versions?
Do my tests need to be in src/test rather than src/androidTest?
What other information do I need?
I'm using:
Android Studio 1.1.0
gradle 1.1.0
junit 4.12
hamcrest-library 1.3
mockito-core 1.10.19
dexmaker 1.0
dexmaker-mockito 1.0

I suppose that you expect to run tests from Android Studio in addition to be able run them from command line only.
I think the most up to date example of usage Robolectric with latest android gradle plugin is this.
One note: I see dependencies to dexmaker and dexmaker-mockito that gives me assumption that you use Instrumental tests instead of plain junit tests.
It is quite dumb answer with just reference but I can not be more specific until you have specific issue

Related

Importing LIBGDX library gdx-backend-android.jar into Android Studio Project

After a hiatus of a couple of years I'm picking up Android development again.
I installed the newest Android Studio(4.1.1) with the latest Android SDK version (Android 11, API 30). After that I created a new project with gdx-setup.
If I add the old java source to my newly generated project I get this error:
error: package com.badlogic.gdx.backends.android does not exist
I'm not sure how to add this jar into the new project. In the Gradle configuration I see mentions of the backend, but it's not available.
I also downloaded the 'gdx-backend-android.jar' from the nightly build and put the jar in the Android library folder, all to no avail.
Does anyone actually know how to correctly add this dependency into my project?
I added the jar but still have an error, don't mind the other errors, I first need to fix the GDX import.
The project dependencies are managed by Gradle, so there is no need for you to directly touch any .jar files at all.
The most likely issue you're facing is that you are trying to use Android-specific classes from the core module, which is platform agnostic.
In a typical libGDX project, you do almost all your game code in the core module so it can easily be compiled for any platform. The code you showed above would be in the android module, but your LiveWallpaperStarter class would be part of core.
Some might say there's no reason to use core at all if you're making a Live Wallpaper, since it can't run on any other platforms besides Android. But there is some advantage in keeping the rendering in core so you can test in a desktop game window, because you can more rapidly compile and run on the desktop. This library has some tools that make it easy to wrap your rendering code in a class that lets you simulate a live wallpaper on desktop, for testing.

Can I generate an unsigned APK using dexguard?

My question is quite simple but it seems I cannot find the answer on the web and since dexGuard does not have a trial period I cannot test it myself.
Can I generate an unsigend apk obfuscated/encrypted with dexguard in Android Studio. I've been told that is not possible because the signature is used during the obfuscation/encryption process but I feel like I'm missing something.
I would like to know if I can obtain the same result I obtain with "assemble release" gradle task with proguard enabled but using dexguard instead for a better protection.
Thank you for your help
Dexguard is a better version than Proguard so it has all the functionalities that has its little brother. From the Dexguard docs:
The procedure for building Android applications and libraries remains
the same. You can invoke gradle with the usual targets, such as
assemble, build, install, and connectedInstrumentTest. For instance,
to build the release version of your application and install it on a
connected device:
gradle installRelease
To build the release version of a library:
gradle assembleRelease
Debug builds use debug settings, without
optimization or obfuscation. Release builds use release settings, with
full optimization and obfuscation. Applications can optionally be
signed. The entries in application archives are always zip-aligned for
efficiency.
Additionally you can use the Standalone version which makes DexGuard run from the command line. By using this you can post-process an existing Android application (.apk file).
I only use Dexguard to obfuscate a Library in Standalone mode but I am pretty sure it will work.

How to show dotCover coverage in new VS2017-type csproj project

I have a solution that contains 3 projects.
PROJECT 1
A VS2017-style .csproj project that has multitargetting to net45 and netstandard1.1.
PROJECTS 2 and 3
Two traditional VS2015-style .csproj test projects, targetting net45, using NUnit.
The reason for projects 2 and 3 not to be new-style is because it seems that right now ReSharper does not recognize these assemblies for running tests. It does find the tests just fine on old-style projects targeting any .NET framewory (full) or netcore assemblies, though.
Using that structure, I can run all my tests all right with the unit test window from dotCover, but when trying to gather coverage results it returns all green for the old-style projects, and all empty for the new-style project.
Coverage tree shows 0% coverage for my new-style project. Gutter highlighting and code highlighting all show in grey, although the tests have run successfully. All of them.
I've tried building in Debug mode, and setting specific values for "Platform" and "Framework" on the Unit Test Sessions window of ReSharper to no avail.
Is this something I'm doing wrong, or are we waiting for an update from ReSharper to fix this?
I am using:
NUnit 2.6.4 (because my unit test projects target net45)
Moq 4.5.28
ReSharper Ultimate 2017.1.2 with dotCover 2017.1.2 (says it's up to date at the time of writing).
Visual Studio Professional 2017 15.2 (26430.12)
I have installed all target frameworks until 4.7.02053
The projects I'm talking about are in C#
I had the same issue. And setting <DebugType>Full</DebugType> solved it for me as mentions by Martin

Converting android ndk build files to gradle

Is there any documentation on converting a application.mk/android.mk file to a gradle based build.gradle file?
good links, QArea. Thanks a lot!
At this moment NDK support in Gradle are very limited. If you need to assemble something that gradle not provides that function
I do like this.
I collect the old-fashioned, but to .so-patches automatically picks up the Gradle-plugin:
ndk-build -j4 NDK_LIBS_OUT=src/main/jniLibs
Otherwise, you must wait for next version of gradle 0.13. Devs promise that NDK will fix integration with NDK.
I made a script tool to convert android.mk building system to gradle building system, because I wanted to test the demo source codes in:
https://android.googlesource.com/platform/development/+/05523fb0b48280a5364908b00768ec71edb847a2/samples
But after searching whole internet, I found no one did it yet. So I created this tool by myself. But even with this tool, we couldn't ensure all projects in AndroidSamples could be built and executed successfully because of the API versions and features mismatch. So I created my own projects for https://android.googlesource.com/platform/development/+/05523fb0b48280a5364908b00768ec71edb847a2/samples
And I want to convert those demo projects one by one.
Now the whole source codes are here:
https://github.com/clockzhong/AndroidSamples
I already successfully converted some samples into gradle building system and executed them correctly on my android phones. But I still have some version mismatch issues, anyway, I'll mentioned it in the project check-in comments.

Running unit tests on Mac with MvvmCross?

Finally, I've got my Mac and tried to re-compile and run my project with Xamarin.iOs
Since, PCL is not yet supported, I had to create a copies of .sln and .csproj and replace references to MvvmCross-Binaries and it works (thanks, Stuart). I hope Xamarin will give more elegant solution soon.
However, I couldn't compile and run unit tests on Mac - Mono 4.5 is not installed, and I didn't find Cirrious.MvvmCross.Test.Core.dll.
So, is it possible to run this kind of unit tests on Mac or we just test it in Windows platform?
I believe you should be able to build and run the 4.5 assemblies using the latest mono 3 releases. Further, the latest mono alpha release should also contain 'proper' support for portable class libraries.
Alternatively, if you'd rather work off of stable xam releases, then you'll probably need to create your own version of a .net4 core test assembly - there are only 2 small classes so this shouldn't be too hard to do - https://github.com/slodge/MvvmCross/tree/v3/Cirrious/Test/Cirrious.MvvmCross.Test.Core
As well as on mac testing, I know some people also use the on device test runners - especially for iOS where the aot compilation makes on-device testing important.

Resources