Tuesday, June 25, 2013

Google+ and dot42

The Google+ platform for Android lets you authenticate a user with the same credentials they use on Google every day. Once a user signs in with Google, you can create more engaging experiences and drive usage of your app.

Download sample from GitHub.

Create a new Google+ project

It is assumed that you have dot42 with either Visual Studio 2010/2012 Pro or SharpDevelop installed.

If you create a new project and want to add Google Play Services to your project, you can do this by checking the library in the New Project wizard:


You will notice that when you check Google Play Services then Android Support Library will be checked automatically because it is required.

After hitting OK, you will be asked to accept the Android SDK License agreement:


After hitting I agree, your new project is created. If you expand the Reference node in the Solution Explorer, you will see that references to both dot42.AndroidSupportLibrary.dll and dot42.GooglePlayServices.dll have been added:



Register your app in the Google APIs Console

Before you can run your app on a physical device, you need to register your app in the Google APIs Console as follows:

(the following is partly copied from https://developers.google.com/+/mobile/android/getting-started, Step 1. but modifed for dot42)

1. In the Google APIs Console, create an API project for your application.

2. In the Services pane, enable the Google+ API and any other APIs that your app requires.

3. In the API Access pane, create an OAuth 2.0 client ID by clicking Create an OAuth 2.0 Client ID:

a. Type a product name in the dialog box that displays, and click Next. Providing a product logo and home page URL are optional.

b. Choose Installed application as your Application type and select Android as type.

c. In the Package name field, enter your Android's app's package name. You can find this on the Android tab of your Visual Studio project properties dialog.


d. Make sure the Output view is visible and compile the project. Copy the SHA1 fingerprint from the output view:


e. Paste the SHA-1 fingerprint into the Signing certificate fingerprint field.

f. To activate interactive posts, enable the Deep Linking option.

g. Click the Create client ID button.

Google+ Sample

The Google Play services package includes the Google+ sample located in <android-sdk>/extras/google-play-services/samples/plus. We have taken this sample, ported it to C# and made it run as a dot42 app. View it on GitHub.




Android SDK Manager and JDK


Unfortunaly, the JDK from Oracle and the Android SDK Manager are not part of a single coordinated install and getting them to work together can be frustrating sometimes.

Until now, dot42 required the Android SDK Manager if you wanted to download and import packages such as Google Play Services.

The SDK Manager, in turn, requires the JDK from Oracle. My experience with identifying the appropriate JDK version on the Oracle site and installing it is far from painless.

After it has been installed, getting the Android SDK manager to run properly is the next hurdle. On different machines I discovered that I had to either Run as administator. Or if that didn't work, I had to run the android.bat batch from the Android SDK tools folder instead, or I had to tune my PATH environment variable. I have also found myself uninstalling and installing different versions and editions of the JDK just to see what combination would work. The high number of up votes of related questions and answers on StackOverflow is testimony to this problem.

For the purpose of dot42, this effort seems unproportional high given the minor role of the Android SDK manager and especially that of the JDK (we don't use it to parse or generate Java - we do that ourselves).

So, as of 1.0.0.70, we have decided to do offline imports of libraries such as Google Play Services and the Android Support Library and bundle them as DLLs with dot42. You import them by just checking them in the New Project Wizard:


Note that these DLLs are just wrappers to bind with C#. At runtime, your APK will call directly into the corresponding APK or use the original Java code compiled to DEX.

We consider this a first step towards making dot42 more self-contained and realize that there may still be occasions where you need the Android SDK Manager. But we strive to remove this requirement if possible.

Friday, June 21, 2013

1.0.0.70 - What's new

To get the latest version, run "Check for updates" from the Device Center or download.

New: 9-patch image support

It is now possible to use 9-patch images (.9.png) as drawable resource. We have extended the Widgets\UsingButton sample to demonstrate this.

New: Portable Class Library support

It is now possible to reference Portable Class Libraries in your dot42 project. To accomplish this, all dot42 assemblies had to be made retargetable and the assembly name of mscorlib.dll has been fixed.

New: Easier use of Support and GooglePlayServices libraries

The new application project wizard has been extended with checkboxes to import commonly used libraries. Currently, these include Android Support Library and Google Play Services.


Note that you will be asked to agree with the corresponding license agreement.

New: Samples are now on GitHub.

As of this release, our samples are on GitHub for easy access. The samples will also be installed locally at [My Documents]\Dot42\Samples folder.

New: Added Google Plus sample

We have ported the Plus code sample that is included with Google Play Services client library. See on GitHub.

Fixed: Dragging xml files into Visual Studio causes crash

No comment.

Fixed: Step behavior of debugger is broken

Line number information in the DEX files was broken. This resulted in unexpected step behavior in the debugger.

Fixed: Various compiler issues

Various minor issues have been fixed in the IL to DEX compiler.

Fixed: HttpWebResponse may loose data

The underlying HTTP client was closed prematurely. Make sure to close your HttpWebResponse to avoid socket and memory leaks.

Monday, June 17, 2013

dot42 and Parse

Parse allows you to store your app's data in the cloud. The Parse Quickstart let's you create a basic Parse Android app in minutes. We will walk through this Quickstart and make the necessary changes to make it work with dot42. It is assumed that you have signed up with Parse.

Create new dot42 project

First, create a blank dot42 Application Project from Visual Studio 2010 Professional, Visual Studio 2012 Professional or the SharpDevelop edition that is included in the dot42 download.


Parse Quickstart Guide

Login to your Parse account. If you haven't created an app yet, then Parse will make it very obvious how to do so. So I assume your first app as been created. Click 'Quickstart Guide' right after creating your app or click 'Quickstart' at the top of the dashboard.


Let's go through the Quickstart Guide as it appears on the Parse web site and take all the analog dot42 steps. We will number the steps similarly so it should be easy to match the Quickstart steps.

First you must choose your platform. Make the following selections: Android, Native and Existing project.




1. Download the SDK

Follow the "SDK files for existing Android projects (.zip)" link.

2. Import the zip file's contents into your existing Android project

Create a libs folder inside the dot42 project that we created at the very start. Copy "Parse-1.3.0.jar" from the zip archive the to the libs folder.

Right-click the Project node and select 'Add Jar Reference...".


The following dialog shows:


Browse to "Parse-1.3.0.jar" in the libs folder and hit OK. Reload the project if prompted. Compile the project to verify that the import went fine. The reference should now have been added like this:


3. Add the following using statement to your Activity:

using Com.Parse;
Call Parse.initialize from your onCreate methods to set your application id and client key:
Parse.Initialize(this, 
   "k1DM1............................d9RyrVu", 
   "etaQb............................SJfz7Yh");
Make sure to copy your own keys here! Also notice how the Initialize is captitalized.

4. Request appropriate permissions

Your app must request the "INTERNET" and "ACCESS_NETWORK_STATE" permissions:
[assembly: UsesPermission(
   Android.Manifest.Permission.INTERNET)]
[assembly: UsesPermission(
   Android.Manifest.Permission.ACCESS_NETWORK_STATE)]

5. Track statistics around application opens

Add the following to the onCreate method of your main Activity:
ParseAnalytics.TrackAppOpened(GetIntent());


After installing the SDK, copy and paste this code into your app, for example in your Application.onCreate:
ParseObject testObject = new ParseObject("TestObject");
testObject.Put("foo", "bar");
testObject.SaveInBackground();
Run your app. A new object of class TestObject will be sent to the Parse Cloud and saved. When you're ready, click the button below to test if your data was sent. It should look similar to this:





1.0.0.69 - What's new

To get the latest version, run "Check for updates" from the Device Center or download.

Improved: Import Jar References

Importing jar files has improved greatly. The visibility of types and members now resembles the java semantics more closely. The renaming of types and members (in case of name conflicts) is done more predictable and safer. As a result, many jar files that caused issues such a Parse, gdx and google-play-services now import correctly. It does however mean, that in rare cases you have to change a type/member name manually.

New: Import Jar preserves annotations when possible

Annotations placed on java types and members are now preserved in dex when possible. As of this release, all constant values for annotations are supported. Enum and array values are not yet supported.

New: Various .NET framework enhancements

These include support for regular expressions, various IO types such as BinaryWriter/Reader and lots of other small additions. Also various bugs in the framework implementation have been fixed.

Fixed: Lots of compiler issues

A large number of issues have been fixed in the compiler. These issues are both in the compilation phase (the compiler gives an error) and at runtime (typically a verify error is raised).

Fixed: Various debugger issues

Various minor issues in the debugger have been fixed.

Change: License agreement must be accepted during activation

The license agreement is no longer part of the installation. Instead the license agreement must be accepted when dot42 is activated (serial entered).

Fixed: Various SharpDevelop issues

Projects created in SharpDevelop could not be loaded in Visual Studio. We have also fixed various minor user interface issues in the SharpDevelop integration.