Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Tuesday, September 02, 2014

Duplicate folders issue with MvvmCross by NuGet

 

EDIT: Issue is fixed in MVVMCROSS v3.2.1 !

With the current NuGet version of MvvmCross, when adding it to the project you get duplicate folders (‘Layout’ and ‘layout’, ‘Values’ and ‘values’)

To fix this, right click on the project and choose ‘Tools \ Edit File’ in Xamarin Studio. In Visual Studio, there’s a similar way.

In the .csproj, you just need to replace the first upper case letter with lower case letter, so replace ‘Layout’ with ‘layout’ and ’Values’ with ‘values’ and save the file.

image

Tuesday, July 29, 2014

Android–deployment error - INSTALL_FAILED_UPDATE_INCOMPATIBLE

 

When trying to deploy on device I got this error:

Deployment failed because of an internal error: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE]

Deployment failed. Internal error.

To fix it, run:

C:\Users\[YourUserName]\AppData\Local\Android\android-sdk\platform-tools>adb uninstall com.xxx.yyy

Don’t include the .apk file extension

Friday, March 14, 2014

Install GooglePlay in emulator

 

I am using the info from http://stackoverflow.com/questions/11154222/google-play-on-android-4-0-emulator#answer-11213598

1. Go to http://wiki.rootzwiki.com/Google_Apps#Universal_Packages_2 and get the latest .zip compatible with your target device.
    Note the “Not compatible with x.x.x!” remarks

2. Start your emulator:

cd %LocalAppData%\Android\android-sdk\tools
emulator -avd VM_NAME_HERE -partition-size 500 -no-audio -no-boot-anim

Then use the following commands:

cd %LocalAppData%\Android\android-sdk\platform-tools

# Remount in rw mode
adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system

# Allow writing to app directory on system partition
adb shell chmod 777 /system/app

# Install following apk
adb push GoogleLoginService.apk /system/app/.
adb push GoogleServicesFramework.apk /system/app/.
adb push Phonesky.apk /system/app/. # Vending.apk in older versions
adb shell rm /system/app/SdkSetup*
 

Wednesday, November 13, 2013

ActionBarSherlock + Xamarin + MVVMCross

 

Short history of ActionBar in Android and Xamarin

1. ActionBar was first added in Android 3.0 (API Level 11).

2. ActionBarSherlock is a third-party library created by Jake Wharton, which brought ActionBar support for Android 2.x: “The library will automatically use the native action bar when appropriate or will automatically wrap a custom implementation around your layouts. This allows you to easily develop an application with an action bar for every version of Android from 2.x and up.”

ActionBarSherlock it’s not just about ActionBar support on Android 2.x, it also has some nice features not available in the Android’s ActionBar implementation.

3. In July 2013, Android Support Library revision 18 introduced a new v7 appcompat library which has ActionBar support for Android 2.1+.

4. Xamarin created a free component for their store as a binding for the ActionBarSherlock, called ‘ActionBarSherlock for Xamarin’.

5. Xamarin created a free component for the Android support Library v7 (rev 18) http://components.xamarin.com/view/xamandroidsupportv7appcompat

I haven’t yet tried how the ActionBar works using the this support library.

 

Using ActionBar in Xamarin application with ActionBarSherlock Xamarin component

The steps are:

1. Create an Android application and add MvvmCross by NuGet. (MvvmCross creates and adds a FirstView activity to the project).

2. Add ActionBarSherlock for Xamarin component from Xamarin Components store

3. Make sure the Android project has ‘Compile using Android version’ and ‘Target Android version’ set to the latest Android version.

4. Add reference to Mono.Android.Support.v4

5. Add a MvvmCross implementation for SherlockFragmentActivity (MvxSherlockFragmentActivity).

   I create a folder ‘MvxSherlockActionBar’ in the Droid project and add to it these two files: MvxEventSourceSherlockFragmentActivity.cs MvxSherlockFragmentActivity.cs These add support for MvvmCross to SherlockActionBar.

6. Change the FirstView’s class parent from MvxActivity to MvxSherlockFragmentActivity and set the ActionBar’s theme

[Activity(Label = "View for FirstViewModel"] 
public class FirstView : MvxSherlockFragmentActivity
{
protected override void OnCreate(Bundle bundle)
{
SetTheme(Resource.Style.Theme_Sherlock);
base.OnCreate(bundle);
SetContentView(Resource.Layout.FirstView);
}
}


You should use SherlockFragmentActivity::SupportActionBar property to use the ActionBar.

A very basic walkthrough to the Xamarin component: http://components.xamarin.com/gettingstarted/XamarinActionBarSherlock 
Xamarin also created a sample application using Xamarin ActionBarSherlock component and made its source code available https://github.com/xamarin/monodroid-samples/tree/master/ActionBarSherlock It contains different examples of usage.

Friday, August 30, 2013

Android native development startup


Installation


#1. Download JDK 6
Java 7 is not officially supported by the Android SDK at this time. Please use the latest version of the Java 6 JDK.
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html

For a 64 bit dev, note that the following trio is required:
  • 64-bit OS
  • 64-bit JDK
  • 64-bit Eclipse

#2.  Add the path to JDK (for example 'C:\Program Files\Java\jdk1.6.0_45\bin') to PATH environment variable.

#3. Download ‘Eclipse Standard’ from http://www.eclipse.org/downloads/
It is not an installer but a .zip archive. Extract its content to a folder like D:\Eclipse

#4 Run eclipse.exe.
It will ask you to select a Workspace. By default it gives a location in C:\Users
Better choose something like D:\Eclipse\Workspaces\MyWorkspace

#5. Install ADT plugin for Eclipse (Android Development Tools)
http://developer.android.com/sdk/installing/installing-adt.html

#6. You might need to install platforms and packages
http://developer.android.com/sdk/installing/adding-packages.html
Emulator runs best using Intel image, so make sure it is selected for all platforms images you install (if available)

Emulator

Keyboard shortcuts: http://developer.android.com/tools/help/emulator.html


Copy and paste: http://stackoverflow.com/questions/3391160/paste-text-on-android-emulator




Thursday, August 29, 2013

Why use ‘AppName.Droid’ for Xamarin Android apps and not ‘AppName.Android’

 

It looks like the if you use “Android” you end up having to use `global::Android` a lot.

So even if “Android” might look better than “Droid”, use “Droid”

Monday, June 03, 2013

make Android device available in Windows and copy the .apk to the device


First, I wasn't able to see the Android device available in Xamarin nor in Windows's USB-connected devices tray icon.

The solution to this is to go to Device Manager \ Other Devices, right click on the Android device item and select 'Update driver' and select to browse for the driver on your disk. Select the location of the Goodle USB driver, which is in the location of where Android SDK is installed (extras\google\usb_driver folder). It's a location similar to this one:

C:\Users\[User]\AppData\Local\Android\android-sdk\extras\google\usb_driver

After this, the Android device item should be not disappear from the Device Manager \Others and also appear in the USB menu in tray icon.


When connectig the USB to the device, a ‘USB Mass Storage’ screen appears with this option.
In order to copy .apk to device, you need to turn on the USB storage.  
You can then copy the released and signed .apk file on the sd_card folder.
Then using the AppInstaller app (search on marketplace) you can select and install the app.

Alternatively, the app can be downloaded and installed from a web location.


You can also install an application using the adb (Android Debug Bridge)

adb install -r [path_to_apk]

the adb is in the Android tools directory: %LocalAppData%\Android\android-sdk\platform-tools (shift + right click in explorer on folder to show 'open command prompt from here')

More info on ADB:
http://developer.android.com/tools/help/adb.html
http://stackoverflow.com/questions/4449540/failure-install-failed-already-exists-when-i-tried-to-update-my-application
http://www.vogella.com/articles/AndroidCommandLine/article.html

MvvmCross Android app with dynamic fragments

It’s not much different than implementing the app with Java, except using the MvvmCross MvxXXXX classes.
Let’s do a simple exercise: have an activity loading a fragment by code behind.
Here’s the code we need:

1. a MvxFragmentActivity derived class.  It is the corresponding to Android’s FragmentActivity class

[Activity(Label = "View for FirstViewModel")]
public class FirstView : MvxFragmentActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.FirstView);
this.AddChildView ();
}
void AddChildView()
{
var childView = new ChildView () {
ViewModel = new ChildViewModel()
};
var fm = this.SupportFragmentManager;
var ft = fm.BeginTransaction ();
ft.Add (Resource.Id.childViewHost, childView, "childView");
ft.Commit ();
}


2. a corresponding Android layout for it: FirstView.axml
  it needs to have a host widget for the fragment, let’s say a FrameLayout called childViewHost
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/childViewHost" />
</FrameLayout >

 
  3. a MvxFragment derived class. Note the MvvmCross BindingInflate method which makes binding work in the fragment
public class ChildView : MvxFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
return this.BindingInflate(Resource.Layout.ChildView, null);
}
}
4. a corresponding Android layout  for it: ChildView.axml. Let’s have a textbox bound to the ViewModel’s property
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
local:MvxBind="Text Hello"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2" />
</LinearLayout>



Friday, May 24, 2013

ActionBarSherlock in Xamarin Android targeting Android 2.1

ActionBarSherlock is a library which is an extension of the ActionBar in Android. ActionBar appeared in Android 4.

Besides being an extension, this library works for version previous to Android 4, starting from Android 2.1

 

First, we need to build the ActionBarSherlock from scratch using Eclipse. (I had also to install ‘Android SDK Tools’ using the Android SDK Manger).

Second, we need to create a Xamarin Java Binding Library, which will create a bridge library for Xamarin based on the ActionBarSherlock Android library.

For these two steps, follow instructions from http://www.craigsprogramming.com/2012/07/actionbarsherlock-with-mono-for-android.html

To test the app, in the app’s Activit1, just use the sample  code also posted there (use the code from TabActivity class).

 

In order to target Android 2.1:

1. Change properties of the ActionBarSherlockBindings project to have Android minimum version 2.1

2. For the app, also change properties to have Android minimum version 2.1 (in Visual Studio, right click on project, Properties and from the dialog, it’s in the Application tab, ‘Minimum Android to target’)

3. On the app, we need to change it to target Android 4. This is specified in the AndroidManifest.xml file of the app

If it does not exist, in Visual Studio, go to the app properties, and click on ‘Android Manifest’ Tab and click to generate the file.

Once done, UI appears with options for the manifest,  set ‘Target API level’ to 14.

 

Also,  once I targeted Android 2.1, I had to make few changes in the sample code for it to work.

Some classes need to be replaced with classes from the Android.Support.V4.App (like Fragment) and a constant (ActionBar.NavigationModeTabs instead of ActionBar_Sherlock.ActionBarSherlock.ActionBarNavigationMode.Tabs)

Now the app can be tested on an Android 2.1 device or emulator.

Wednesday, May 22, 2013

First app with Xamarin Android and MVVMCross – gotchas

1. After installing Xamarin, create a new ‘Visual C# / Android / Android Application’ using Visual Studio, say ‘DemoApp.Android’ but have the solution called ‘DemoApp’.

2. Add an ‘Visual C# / Windows / Portable Class Library’ called DemoApp.Core.
   First select ‘Windows Phone 7.5 and later’ and then ‘Mono Android’ and ‘MonoTouch’. Note that Xamarin frameworks become available only if you select ‘Windows Phone 7.5 and later’

3. Make sure you have the latest NuGet installed. For this, in Visual Studio, go to Help \ About Microsoft Visual Studio.
image

4. Using NuGet, search for ‘mvvmcross’ and add ‘MVVMCross Hot Tuna Starter Pack’ to BOTH the DemoApp.Android and DemoApp.Core
In the DemoApp.Android, it creates a SplashScreen activity and layout, and a layout and a view in FirstView.axml and FirstView.cs respectively.
In the DemoApp.Core, it creates a FirstViewModel view model.

6. In DemoApp.Android, delete the Activity1.cs and Resources/Layout/Main.axml.

7. Run. It should run OK at this point.