Category: Uncategorized

No valid iOS code signing keys found in keychain. You need to request a codesigning certificate from

If you receive the following error message after trying to run an Xamarin application in Visual Studio

"No valid iOS code signing keys found in keychain. You need to request a codesigning certificate from <YourAppName>"

What this basically means is that you need to create or log into your Apple ID in XCode itself and get a certification straight from Apple.

There is a great article on the Xamarin website on how to do this, check it out here

If you still get the error message, make sure you have the iPhone simulator selected





Changing SharedPreferences of a Context instance for testing with Robolectric

The following code will get it done in a snap

Context context = RuntimeEnvironment.application.getApplicationContext();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
sharedPreferences.edit().putBoolean("useOnlyOnWifi", false).commit();



You use “RuntimeEnvironment.application.getApplicationContext();” to create an instance of a Context object.

You return the preferences, and modify the needed value and then commit it.

The next time this instance of Context returns SharedPreferences, it will return the version that you modified.

Change as many settings as you need to, then pass the context to the method you are trying to test!


Android Studio – How to make an instance of Context during unit testing

One of the great new features of Android Studio 2.0 is the automatic implementation of unit testing when you create a new project. However, in it’s base form, it’s only good for testing Java code (nothing Android specific). Mocking an instance of Context won’t do any good if you need it to execute your code.

The solution is…


The only drawback to this method, is that it doesn’t currently support Api level 22 and above. You will need to adjust the following in your build.gradle…

compileSdkVersion 21
buildToolsVersion "21.1.2"

You will also need to change the version of appcompat you’re using

compile ''

Add the following line into the dependencies section

testCompile "org.robolectric:robolectric:3.0"

So all said and done, your build.gradle file should look similar to this

apply plugin: ''

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "net.evanp.umactuallynerdtriviagame"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    testCompile "org.robolectric:robolectric:3.0"
    compile ''


Editing your test classes

Before your class is declared, add the following

@Config(constants = BuildConfig.class)

On top of the test method add @test just like usual, but notice how the instance of Context is created

public void testAbilityToAccessXML() throws Exception {
    Context context = RuntimeEnvironment.application.getApplicationContext();

It’s that easy!