Category: Uncategorized

Failed to resolve assembly Xamarin.IOS in Visual Studio – Visual Studio

I received the following message when deploying after updating my version of Xamarin

Severity	Code	Description	Project	File	Line	Suppression State
Error		Failed to resolve assembly: 'Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.TypeReference.Resolve()
   at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeEnum(TypeReference enum_type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeElementValue(TypeReference type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArgument(TypeReference type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeConstructorArguments(CustomAttribute attribute, Collection`1 parameters)
   at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute)
   at Mono.Cecil.CustomAttribute.<Resolve>b__2(CustomAttribute attribute, MetadataReader reader)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
   at Mono.Cecil.CustomAttribute.Resolve()
   at Mono.Cecil.CustomAttribute.get_ConstructorArguments()
   at Mono.Cecil.ImmediateModuleReader.ReadCustomAttributes(ICustomAttributeProvider provider)
   at Mono.Cecil.ImmediateModuleReader.ReadMethods(TypeDefinition type)
   at Mono.Cecil.ImmediateModuleReader.ReadType(TypeDefinition type)
   at Mono.Cecil.ImmediateModuleReader.ReadTypes(Collection`1 types)
   at Mono.Cecil.ImmediateModuleReader.ReadModule(ModuleDefinition module)
   at Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
   at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
   at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
   at Xamarin.Build.Download.XamarinBuildiOSResourceRestore.MergeResources(IAssemblyResolver resolver, String originalAsmPath, String mergedAsmPath, List`1 resourceItems)	CanadianClassifiedsAlerter.iOS

After verifying both my build server and development machine were running the same version of Xamarin, I noticed a slight hint at the end of the message

 at Xamarin.Build.Download.XamarinBuildiOSResourceRestore

Solution

I fixed it by updating Xamarin.Forms and Xamarin.Build.Download in both my Portable project and the iOS project and it built just fine ūüôā

It’s that easy.

 

Canadian Classifieds Alerter for iOS usage update

Effective right now, I will be extending the frequency of checks from the five-ish minutes that users experience now to 12-ish minutes. You will still have your six standard alerts.

I will be offering a pro service to get 45 second checks AND extend the amount of alerts you’re allowed to have to 15 for $65 a month. Please contact me for this service!

Other not as fast but maybe just as good for you plans are:

$40 for every two minutes

$20 for every five

The people interested in this service will be people who make a lot of money off Kijiji, I realize it’s not for everyone.

Why? Are you selling out?

Sort of.

But hear me out… how much money do you think this app makes a month in ad revenue?

$150? $100?

Five bucks.

I make five bucks a month.

This app took 5 months to make as I had to learn how to program for iOS, and I get five bucks a month to show for it.

Weak as shit ad revenue

What are my costs associated with this app?

-Annual Apple Developer Program ($120 a year)

-Power to run my server ($15 a month)

-Cost to build my server ($550)

Not including server upkeep and the initial cost of building the server, it costs me $25 a month to run this service.

I lose money every month by providing this service.

 

Do you have any other good news?

  • If this service takes off, I will be removing ads from the app completely.
  • I will more inclined to add new features if the app is making money every month.

 

 

Thanks for reading everyone ūüôā

Multiple dex files define lcom/android/vending/billing/IInAppBillingService

If you began to implement Google’s API V3 of their In App Billing Service, and switched to¬†android-inapp-billing-v3 made by¬†anjlab, you might get this error message

The reason this is happening is because you have the same library in there twice. Once from before, and again when his library adds the same files.

The solution is simple, delete the aidl folder in your <project>/app directory. Clean, then rebuild and it will work!

Automate backing up visualsvn repositories with Windows Powershell

To backup your VisualSVN repositories, you will need the following

  1. Windows powershell installed and configured to allow scripts to run. If you’re unsure of how to enable powershell scripts to run locally, see this superuser thread
  2. A place to backup files. I have mine synced to a local folder, which is then synced to OneDrive

Step one. Create a text file and change the extension to .ps1

The file would be something like VisualSVNscript.ps1

Step two. Add the following lines to the file

#Name of project1
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
#Name of project2
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
#Name of project3
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
#Name of project4
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>

You will need to do this PER project! Hotcopy can only copy to an empty directory, so we delete the contents of the directory first then copy the newest code to the directory. Save the file and exit

Step three. Use Windows Task Scheduler to run the script automatically for you.

  1. ¬†Press Start and start typing “Task Scheduler”. Click on it.
  2. Click create basic task, name the task “VisualSVN backup” or anything you like and select desired frequency
  3. For a command enter in “powershell -file <pathtoscript>” and click Finish

That’s it! Your VisualSVN projects will now automatically be backup for you!

Xamarin.Forms – iOS/iPhone – Detecting if user said no to push/remote notifications

I assume if you’re reading this, you’re familiar with dependency injection in Xamarin Forms. What you’d create in your portable project (Your Xamarin Forms application) is the following

Xamarin.Forms custom class

public interface INotificationsInterface
{
    bool registeredForNotifications();
}

In your Xamarin.iOS project,  implement the interface with the following:

public class NotificationsInterface: INotificationsInterface
{
	public bool registeredForNotifications()
	{
		UIUserNotificationType types = UIApplication.SharedApplication.CurrentUserNotificationSettings.Types;
		if (types.HasFlag(UIUserNotificationType.Alert))
		{
			return true;
		}
		return false;
	}
}

In your main activity for your Xamarin.Forms application, perform the check as follows:

if (DependencyService.Get().registeredForNotifications())
{
	Debug.WriteLine("alerts enabled!");
} else
{
	String warningAboutAlerts ="The point of this applications is instant alerts" +
" but you choose not to receive alerts. You will need to manually check the notifications" +
	   "page or go into your iPhone's system settings to reenable alerts";
	Debug.WriteLine("No alerts allowed!");
	mainLayout.Children.Add(new Label
	{
		Text = warningAboutAlerts,
		TextColor = Color.Red,
		FontSize = 14
	});
	
}

Fairly simple stuff! For my code above, replace mainlayout with whatever you want… a dialogue box, disabling/enabling menu items… it’s entirely up to yourself!

 

 

Dotnetcore 1.1 – Entity Framework Core – Update database after making changes to the model

You may have noticed that all the blog posts make mention to commands that don’t exist. Such as update-database and other migration like commands

This is because these classes no longer exist in dotnetcore. If you want to save the changes you’ve made to a database, here are the following commands to issue in a command prompt, power shell or through VS Code

dotnet ef migrations add nameOfMigrationHere

And then run

dotnet ef database update

Check the database of your target and your changes will be there! You’ll even notice a table in your database showing the migration

No valid iOS code signing keys found in keychain. You need to request a codesigning certificate from https://developer.apple.com

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 https://developer.apple.com. <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

https://developer.xamarin.com/guides/ios/getting_started/installation/device_provisioning/#Using_Xcode

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

 

Untitled

 

Untitled2

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();

Explanation

 

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…

 Robolectric

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 'com.android.support:appcompat-v7:21.0.0'

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: 'com.android.application'

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'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    testCompile "org.robolectric:robolectric:3.0"
    compile 'com.android.support:appcompat-v7:21.0.0'
}

 

Editing your test classes

Before your class is declared, add the following

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class)

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

@Test
public void testAbilityToAccessXML() throws Exception {
    Context context = RuntimeEnvironment.application.getApplicationContext();
    ProgramWideFunctions.randomCategory(context);
}

It’s that easy!