Assets for Unit-Tests - android

I am migrating some tests from instrumentation to unit-tests ( the new ones that came with 1.1 ) - And now I am facing the problem that I find no way to supply the tests with files ( data that I need to test if it gets parsed correctly )
Anyone knows a way to do this?
Unfortunately for the android asset stuff I have no context and this also does not work:
getClass().getClassLoader().getResource("src.sgf")
The above is null with the file in:
src/test/assets/src.sgf
Interestingly AndroidStudio recognizes the asset - when I control click on the src.sgf in the code it brings me to the right file.

As far as I understand you are looking for resources being accessible from your unit-tests environment.
It is an official issue of android build tools gradle plugin version 1.1.
You can find work around for this issue in this following thread Test resources not found from unit test

Related

Type mismatch when creating a new ViewModel for Room implementation - kotlinx.coroutines obsolete since 1.3

I am building an app that will rely heavily on user data and plan on using Room to help manage and store their information. However, while following a tutorial I ran into a few versioning issues that I was having troubles resolving on my own.
Since I am fairly new to both Android development as well as using Room, I have been following this tutorial: Android Room with a View - Kotlin
I first noticed there might be some issues in step 3 when I updated my Gradle files. I was met by the following error on the last two lines of the dependencies block:
Library should be updated to be compatible with Kotlin 1.3
I was confused by this since the tutorial uses a variable of some kind to determine the library versions. I ran the app at this point and it seemed to work fine so I continued.
When I got to step 9, I also ran into additional errors which now prevent builds from completing:
Type mismatch: inferred type is kotlin.coroutines.experimental.CoroutineContext but kotlin.coroutines.CoroutineContext was expected
Type mismatch: inferred type is kotlin.coroutines.CoroutineContext but kotlin.coroutines.experimental.CoroutineContext was expected
This is on top of errors that implementations of kotlinx.coroutines.experimental are obsolete, however, I couldn't find references to libraries without experimental using Android Studio's intellisense.
What do I need to do in order to resolve these library issues and allow me to continue the tutorial?
To the best of my knowledge, here is the recommended way to resolve these issues.
To try and solve these issues, I started with the errors in my Gradle scripts to see if that would maybe resolve dependencies in the code. I did find this post, which I'm still not completely convinced is the best solution, but just following the first couple of suggestions in the top answer did clear most of my issues.
To be clear, I changed the following:
Changed the variable in the last line of the dependencies Gradle block to have a hard-coded version number (I did the latest as found in the kotlinx.coroutines repo). If possible, I would like this to be auto-generated again as the tutorial implies
Removed the kotlin block from the bottom of that same Gradle file
Synced my Gradle project
Update Kotlin and Gradle (I was asked by Android Studio, you might not be depending on your versions)
Manually removed problem libraries from code, and Alt+Enter'ed any missing libraries back into existence
If you update Gradle, you may also find it necessary to include the following in your Module: app Gradle file inside the android block:
packagingOptions {
exclude 'META-INF/*'
}
(* might be overkill for some, but the suggestion from this post didn't completely eliminate all of my errors.)
After all that, I was then able to rebuild the SDK which loaded to my phone with zero errors.

Visual Studio 2017 - Xamarin - The file "obj\Debug\android\bin\packaged_resources" does not exist

I'm fighting with that issue for 2 days already and can't find any solution.
I have an Xamarin Android app in Visual Studio 2017 consisting of three projects:
Xamarin.Android project (main one)
Android-specific unit tests run on the device - project of type NUnit 3 Test Project (Android) created using NUnit Templates for Visual Studio
Platform-independent unit tests project (project of type Unit Test Project (.NET Framework))
Everything worked just fine until now. When I selected my main project as the Startup one, my app was deployed to the device/emulator. When I selected my Android-specific unit tests project, the test project was deployed and unit tests executed by nUnit Xamarin Runners on the device/emulator.
However few days ago I updated my Visual Studio 2017 with the newest available update and now, when trying to build this android-specific unit tests project I get the following error:
The file "obj\Debug\android\bin\packaged_resources" does not exist.
I've searched everywhere, including this and this SO topics. I also totally reinstalled Visual Studio 2017 and Xamarin with Android SDK included. Nothing helped. From what I read I suspect there is something wrong with the versions of Android SDK Build-tools I have installed. Here's what I have currently installed in SDK Manager:
As the other SO threads suggested, I tried uninstalling the newest Android SDK Build-tools (25.0.2) and installed version 23.0.3 (all my projects target Android 6.0), but it also doesn't help, I still have the same error.
Maybe it's worth adding that this issue may have started to happen when I tried to implement RecyclerView in my app reading this tutorial, where they suggested to install Android 7.1.1 (API 25) in SDK Manager. However I undoed my all changes after that and even reintalled VS2017 + Xamarin.
Do you have any other idea why this can be ? I'd really appreciate any help. Thanks!
EDIT 2017-04-09:
Egh, I removed VS2017, installed VS2015 with brand new Android SDK and still the same issue :(
I've finally found what was the issue. It wasn't related to any component from SDK Manager or VS version.
Following localization tutorial from developer.xamarin.com, I played a bit with Strings.xml in my Android project. I wanted to have my Activities Label taken from resources as well, so in the ActivityAttribute I defined:
[Activity(Label = "#string/peopleListTitle")]
and added this value in Strings.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-------Other resources values ----->
<string name="peopleListTitle">People List</string>
</resources>
In that case my build is failing with above-mentioned error:
The file "obj\Debug\android\bin\packaged_resources" does not exist
When I change ActivityAttribute to use a string directly:
[Activity(Label = "People List")]
the build is passing without any issues.
I managed to find a solution, but actually I don't know why it's not building when I try to use Label text defined in Strings.xml.
BTW, I managed to find what's the problem by setting build output verbosity to Diagnostic in Tools -> Options -> Projects and Solutions -> Build and Run which gives a detailed info why the build failed in the Output window.
I had the same problem. After removing the dash "-" sign from the image file name, the problem is solved. Bad error message! It should not be:
The file "obj\Debug\android\bin\packaged_resources" does not exist.
Writing an error message like this causing the Developer to think about something else while the problem is the illegal file name.
I had the same issue when I added a new image as a resource.
There was a '-' in the file name (Invalid resource name character). I renamed & removed that character and all good.
Resource name can only consist of 0-9,a-z or A-Z or combination of any.
I had the same problem, and i removed all image file name have "-" character. My problem solved
Another reason for this error is that you may have a float number as your version number. In my case I changed it to a integer and everything worked fine. (I found the error by switching the build output to Detailed)
Simply it worked.
In one case I copied and pasted previous working "packaged_resources"
in the bin folder.[the problem was it did not reflect the UI changes]
Other I opened the visual studio as
administrator.
Next changed the "Minimum target to Android" to lower
apis in the project properties windows.
I suggest not touching the code behind of the design. If you get this error simply pull some button from the tool bar into the design and visual studio will come to its consciousness that there is change in UI. Next click on save all so that it make necessary change in the designer file.
Mine was a different solution (and only half a day lost): I was having trouble getting Hockey app to match crashes against the correct version of the app and realised it uses VersionCode not VersionName so I change my code to "0.0.34" the same as the name. For some still unknown reason the app built and deployed to devices for about 3 days before I started getting this error The file "obj\Debug\android\bin\packaged_resources" does not exist. Setting it back to a numeric value fixed the problem.
I found the problem by looking back through my GIT logs and rebuild each push until I found the one that caused the problem.
It just because the Version Code,I set Code by '1.0',The file "obj\Debug\android\bin\packaged_resources" does not exist.;And I set it by '1',everything is ok.
Had the same error, the way I got over it was crank up the Android SDK manager and install all updates and remove any obsolete packages. This happened to me because I was targeting something newer which was not installed.
Check to see if there are any unused entries in resources.designer.cs if there are any manually remove those entries.
This will fix the issue.
After following several online suggestions - updating SDK, updating Xamarin etc - none of which worked for me.
Finally found that I had an activity for a Android provider to Alarm clock in my AndroidManifest file as below
<activity
android:name="com.njcommuter.droid/android.provider.AlarmClock"
android:label="AlarmClock"
.....
/>
Removing this line - and rebuilding worked fine without any errors and was able to deploy solution successfully.
Note : testing this by putting the line back, and I get same error again on rebuilding.
It can be linked to using any android provider which creates the package for it, not necessarily AlarmClock only.
This error is, somewhat of, a wrapper for what can be multiple reasons that that the file was not created. The key is to look in the detailed output and look for the underlying error causing the file creation failure.
In my case, I had corrupted icon.png files (generated right from from the VS xamarin nunit template, no less!). Once I put in valid png files, everything was built fine.
Another reason for this error, if that the android NDK (not android SDK) isn't right, change de version can resolve the problem: go to Tools/Options/Xamarin/android Configurator and change de folder, in my case I've three, the last one can't compile, but the second folder with version xx.r11c do it.
For me it was Target Android Version.I had it set to
but changing it to Compiling version(for me it was the latest platform) resolved the issue.

Running Android tests (junit) in Android Studio does not work Exception in thread “main” java.lang.NoClassDefFoundError: junit/textui/ResultPrinter

When I run a Andriod test (junit) test in Android Studio I get the folowing errormessage.
Exception in thread “main” java.lang.NoClassDefFoundError: junit/textui/ResultPrinter.
I assume the error is because it cannot find the junit.jar file.
When I follow below junit setup it does not fix the error:
http://www.tutorialspoint.com/junit/junit_environment_setup.htm
I cannot get above setup working. It still cannot find the junit classes.
Any ideas how to fix the problem.
Did you put your test class in correct place in the folder structure, Martin?
Look at the table under "Flavors and build types support" on http://tools.android.com/tech-docs/unit-testing-support
It resolved the issue for me, but I had to move the test class (and create folders) manually - while Android Studio can generate the test suite automatically for you (Go to... Test, after right-clicking on the class header), it doesn't offer to put it in right location by default, so it can be confusing.
Also make sure to set Test Artifact to "Unit Tests" in Build Variants tab, but the official tutorial says that more explicitly so I assume that's not what you overlooked.
I understand your question was dated, but maybe someone stumbles upon it like I only just did struggling with this issue myself ;) And guys, remember - highest voted answers on StackOverflow that tell you to stick to Android tests and drop JUnit are obsolete now, Android Studio supports JUnit tests that run on your PC directly, as explained in the link I posted above. Of course they don't give you access to instrumentation - I use them to test my "pure" Java logic which is platform agnostic.

Running a Robolectric test from IntelliJ causes OutOfMemory

I am trying to run a unit test from IntelliJ that uses Robolectric by following the example here ::
http://pivotal.github.com/robolectric/intellij-quick-start.html
Have added the Robolectric jar and a jar for Junit4. When the test runs I see the following output >>
Have googled around and found some suggestions that I need to specify some vm args. This post is describing a similar issue with Eclipse java heap space The post is concerned with using Robolectric in tandem with a Maven project. I have read that it is easier to use Robolectric inside a Maven project but I have elected not to do this as my Android project has no other use for Maven.
If anyone has any wisdom on what is wrong here it would be greatly appreciated.
Maybe it will help. You need proper local.properties file with android sdk location in the root of your project to run Robolectric correctly:
sdk-location=c:\\Development\\android-sdk-windows
sdk.dir=c:\\Development\\android-sdk-windows
I ran into the same issue and found an answer here: https://coderwall.com/p/rcgyfq
1.- Copy the file "/Applications/IntelliJ IDEA.app/bin/idea.vmoptions" to "~/Library/Preferences/IntelliJIdea12/idea.vmoptions"
2.- Edit file "~/Library/Preferences/IntelliJIdea12/idea.vmoptions"
3.- For example change -Xmx800m by -Xmx2048m
4.- Restart IntellijIDEA 12
This stopped my Out of Memory exceptions and greatly decreased my overall test time.

"Resource not found" when building Android app under IntelliJ 9.0 Maia Public Beta

I'm trying to port an app from Eclipse to IntelliJ. The app builds fine but it fails to run properly.
Here's a partial stack trace I receive:
ERROR/AndroidRuntime(957):
java.io.IOException: Resource not found: "org/joda/time/tz/data/ZoneInfoMap" ClassLoader: dalvik.system.PathClassLoader#43761190
at org.joda.time.tz.ZoneInfoProvider.openResource(ZoneInfoProvider.java:209)
at org.joda.time.tz.ZoneInfoProvider.<init>(ZoneInfoProvider.java:123)
at org.joda.time.tz.ZoneInfoProvider.<init>(ZoneInfoProvider.java:82)
at org.joda.time.DateTimeZone.getDefaultProvider(DateTimeZone.java:439)
at org.joda.time.DateTimeZone.setProvider0(DateTimeZone.java:393)
at org.joda.time.DateTimeZone.<clinit>(DateTimeZone.java:114)
at org.joda.time.chrono.GregorianChronology.<clinit>(GregorianChronology.java:71)
at org.joda.time.chrono.ISOChronology.<clinit>(ISOChronology.java:66)
at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:97)
at org.joda.time.DateTime.<init>(DateTime.java:120)
For some reason, the app isn't able to find the joda-time resources, even though they're specified in the module's build path. These are the same jarfiles used by the eclipse version of the app.
alt text http://img.skitch.com/20091106-pgqujbb5eaeqc2wfiqc2c1p39a.png
The APK built by the IntelliJ tool is about 20% smaller than the one built by Eclipse, but I don't know why.
Any idea what might be the problem?
UPDATE:
I spoke with romain and xav yesterday, and it appears that the problem is that intellij is not bundling resources into the apk. Evidently aapt does a two pass approach - first it bundles all the class files into a .dex file, and then it bundles all of the resource files separately into the top level of the apk file. It's this second pass that intellij seems to be missing.
As a workaround, they suggested that I unjar all the resource files from the joda-time jar, and place them in my src directory. The expectation was that intellij would then bundle them into my apk as though they were part of my own source, thus solving the problem. However, when I did this, IntelliJ ignored those files entirely when it created the apk.
I don't know why. Is there maybe a workaround I can use to get the joda-time resource files into my apk that isn't terribly inconvenient every time I want to build?
This is a pretty old version of intellij at this point. 10.5 seems to resolve all of my issues with android dev
Isn't your problem the scope of your dependencies ? If they're only used to compile, it's not garanteed to work at Runtime is it ?
I'm not a user of IJ myself but from your screenshot that's my guess. It would also explain why the size of your android package is 80% lower.

Categories

Resources