Can you use Chrome Custom Tabs in Xamarin? - android

In this documentation https://developer.chrome.com/docs/android/custom-tabs/integration-guide/ it says you have to add the AndroidX Browser Library in your project.
Open the app/build.gradle file and add the browser library to the dependencies section"
But I think that's some Android Studio thing.Then I tried to find maybe a NuGet Package but the only thing that showed was some Chrome Custom Tabs version 1.0.0 that couldn't even install:
Severity Code Description Project File Line Suppression State
Error NU1202 Package Xamarin.Android.ChromeCustomTabs 1.0.0 is not
compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package
Xamarin.Android.ChromeCustomTabs 1.0.0 supports: monoandroid50
(MonoAndroid,Version=v5.0)
Is there any way I can use Chrome's Custom Tabs in my Xamarin Project?

Open the app/build.gradle file and add the browser library to the
dependencies section"
For this problem,you can try to install nuget Xamarin.AndroidX.Browser which is developed by Microsoft. Meanwhile, you also need to install nuget Xamarin.AndroidX.Core .
For more details , you can check: https://github.com/xamarin/AndroidX.
Is there any way I can use Chrome's Custom Tabs in my Xamarin Project?
For this , you can try to install nuget Xamarin.Android.Support.CustomTabs.

Related

How to effectively add dependency .aar file in Xamarin project?

I am trying to create a Xamarin project using PayTM android library. Since PayTM doesn't have a direct Xamarin binding I have added the appinvokesdk-1.2.aar in the Xamarin Android Biding library project. The build action for appinvoke is "LibraryProjectZip". Now the appinvoke library also have a runtime dependency on easypay-8.7.3-appinvoke.aar (I found this after checking the pom file for appinvoke.aar file). I have set the build action for the easypay aar file as "EmbdedJar". I have also tried setting it to "LibraryProjectZip","ReferenceJar" and "EmbeddedReferenceJar". During runtime I am getting the error as
Java.Lang.ClassNotFoundException: Didn't find class "easypay.listeners.WebClientListener" on path: DexPathList[[zip file "/data/app/com.edmatix.poc.paytmdemo1-WQf3uMctjbNHoAG_ZfsH3A==/base.apk"],nativeLibraryDirectories=[/data/app/com.edmatix.poc.paytmdemo1-WQ…}
Here is my environment details
Visual Studio for Mac 8.5.4 (Build 12)
AndroidX assemblies
Xamarin.Form 4.6.0.726
Android Minimum API version 22
Android Target API 28 (Android 9)
the class easypay.listeners.WebClientListener is only required during run time and not during compile time.
Can you please help about how to properly embed the dependency library?
Thanks
so this is what I did to solve the issue of missing .aar file during runtime. I added the second .aar file (easypay-8.7.3-appinvoke.aar) into another Xamarin binding project (as shown in here) and set the compile type as LibraryProjectZip. And that solved my issue with not finding the class in runtime.
Thanks
Please try to install Xamarin.Kotlin.StdLib in your Xamarin Android project. Installing the Kotlin package worked for me because I was using the .aar file which contains Kotlin code.
Install-Package Xamarin.Kotlin.StdLib -Version 1.3.50.1

GoogleMaps.LocationServices NuGet package says namespace could not be found

I am creating an android application using Xamarin on Visual Studio 2017. I am trying to use the NuGet package GoogleMaps.LocationServices using this guide (http://www.c-sharpcorner.com/blogs/find-latitude-and-longitude-using-c-sharp1). I have installed the package fine
But when I try to use the package on my code like the guide I following does I just get an error saying it can't find the namespace:
This means that I cannot create a GoogleLocationService() object which is what I need to do to create a Google Maps pin point using a list of location addresses.
Anyone got any idea why I'd be getting this error? Unsure if I just need to use a different namespace now as this guide was from 2013.
The GoogleMaps.LocationServices 1.2.1 NuGet package contains an assembly for .NET 4.0 and no other target frameworks. So it does not support Android projects. NuGet will not add a reference to the GoogleMaps.Gelocation assembly since it is in the lib/net40 directory so it not considered compatible.
Instead I would take a look at the Xamarin.GooglePlayServices.Location NuGet package.
Looking at the content of the NuGet package it has a content file GoogleMaps.LocationServices.readme.txt which seems to be why you can install it into a Android project. This GoogleMaps.LocationServices.readme.txt file is added to your project.
Ideally the NuGet package should have a readme.txt file in the root of the NuGet package and not add a file to the project. Such a readme.txt file would be automatically opened on installation by Visual Studio without the need to add anything to the project. Removing the content file would also prevent the NuGet package from being installed into an Android project, or any other unsupported project type.
The older GoogleMaps.LocationsServices 0.9.0 can be installed into an Android project but that seems to be because the NuGet package is not packaged correctly. The GoogleMaps.Gelocation assembly in this version of the NuGet package is in the lib directory and does not indicate any target framework so it is allowed in all project types, which does not seem to be correct.
It's hard to trace what a new signature of the methods are in 2017, but from my brief look if you change the version on a package to
0.9.0 and use namespace
using GoogleMaps.Geolocation;
The example should work.

How to Configure AspectJ in Android Studio

I am trying to configure AspectJ in Android Studio. But after all trial and error its not working ! Surprisingly I am able to make it work with Eclipse Kepler version The steps I followed for Android Studio
Created sample Android Project
File > Settings > searched for AspectJ in Plugin section
Assuming nothing more to be done in Studio , except configuration of build.gradle files
Added compile 'org.aspectj:aspectjrt:1.8.1' to the to the build.gradle (Module:app)
Created Analytics_onBackPressed.aj for back button press detection
Created Analytics_OnClick.aj for click events detection
Created Analytics_onCreate.aj for components oncreate event detection
Created necessary dependency classes which the above mentioned *.aj classes will internally call
Added required permissions in Manifest
Running the project is not detecting any of the events (button click, oncreate or back button click)
Followed these links ReferenceLinkOne , ReferenceLinkTwo and ReferenceLinkThree
My Question is what is more required to make AspectJ working with Android Studio
Steps followed in Eclipse and got AspectJ working
Downloaded Eclipse Kepler version
Through Install New Software option searched for http://download.eclipse.org/tools/ajdt/43/update
Installed AspectJ Development Tools (Required) .
Created sample android project
Created Analytics_onBackPressed.aj for back button press detection
Created Analytics_OnClick.aj for click events detection
Created Analytics_onCreate.aj for components oncreate event detection
Added required permissions in Manifest File
Right clicked in project and converted project to AspectJ by the following
Configured Java build path with AspectJ runtime library
Now while running the project, I am able to detect components oncreate, back button press
Environment Used
Android Studio : 2.1.2
JRE : 1.8.0
Windows 7 Enterprise
Any help is highly appreciated!
EDIT : 1 , From the output , still AspectJ is not properly configured
As per this link , I created jar file from eclipse including *.aj files and corresponding dependency. Excluded AndroidManifest.xml while creating jar file and created jar
Created Project in Android Studio. Placed this *.jar file in libs file. (apps> libs). I have enabled AspectJ waving as shown below
Now searched the properties for AspectJ and enabled
Now running the project, should be creating logs I had put in *.aj files which is in plugin . Unfortunately these logs are not printed in Android Studio logs.
Form which I am concluding still AspectJ is not enabled in this project OR there is a configuration error
Disclosure: I am the author of the inofficial AspectJ weaver plugin.
As noted in the AspectJ weaver plugin documentation, the plugin does not support compiling .aj files.
To use this plugin, you have two options:
Switch from .aj to annotation style aspects.
Compile the .aj files outside the IDE (IntelliJ Community / Android Studio), for example using Maven/Gradle/Ant, and package them into a .jar. Include this .jar as a dependency in your project and click the Search for aspects... button, as per the documentation.
I have had various success trying to get AspectJ working in Android Studio. This link helped me get part of the way there (assumes Gradle build setup for your project). http://fernandocejas.com/2014/08/03/aspect-oriented-programming-in-android/
Using the custom block of code in the build.gradle file, I was able to get aspects defined using annotations in .java files compiling and weaving properly in my project. However, this same method did not work for me when defining native aspects using .aj files. I hope it helps.
IntelliJ has no tooling support for AspectJ, and Annotation Style AspectJ can work on Android studio. Just treat the aspect code as Java code.
For detail read this issue
aspectj for Android studio - where is AJDT plugin
Also, you can use gradle plugin aspectjx which can weave kotlin code and demo is here

Installing GooglePlayServices with NuGet gives me a Install-Package error

So I'm trying to install this package into my solution and I'm having a weird error I can't seem to fix or find a solution for.
Install failed. Rolling back...
Install-Package : Could not install package 'Xamarin.Android.Support.v7.AppCompat 21.0.3.0'.
You are trying to install this package into a project that targets 'MonoAndroid,Version=v2.2', but the pack
age does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:16
+ Install-Package <<<< Xamarin.GooglePlayServices
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
I've tried changing my target MonoAndroid version to either the latest or the earliest and it didn't seem to change anything, so I've put it back to where it was originally.
This is the error I'm getting. The problem is I either need to get this to work (because Xamarin didn't update their website so I can't download it from there and just take their .dll) OR do the bindings for Google Play Services myself which would probably be a pain in the ass.
Unless there is another way?
Thanks in advance!
The following settings work for me:
Looking at the Xamarin.Android.Support.v7.AppCompat 21.0.3.0 NuGet package it only contains an assembly for MonoAndroid 4.0.3 so your project will need to target that version or above before you can install it.
It looks like you are using Visual Studio so you can either go into the project options and change the targeted Android version in the project properties and change the Compile using Android version or edit the project file (.csproj) and change the TargetFrameworkVersion directly in the file.
<TargetFrameworkVersion>v4.3</TargetFrameworkVersion>
If you need to target Android 2.2 then you could use the Xamarin.GooglePlayServicesFroyo NuGet package since that can be installed into a project that targets MonoAndroid 2.2
Following this answer, all you have to do is change this:
to this:

Unresolved dependency error when creating a new project

This error appears when creating a new Android Application module in Android Studio using Fixed Tabs + Swipes for navigation.
It says:
The following dependencies were not resolvable. See your build.gradle
file for details. - com.android.support:appcompat-v7:18.0.0
I'm targeting Android 4.0+ devices. Why is the compatibility library involved? One workaround is to install this library using the Android SDK manager, but I'm concerned my app will actually use this compatibility library when there is no reason to. The ActionBar and fixed tab navigation should be built-in to the Android 4.0+ framework right?
This happened to me with IntelliJ Idea 13 Ultimate when creating new Gradle Module. I was working on the app that supports Froyo. I had to manually add support libraries to the SDK. After that I was able to build just fine. Here is the screenshot of Project Structure settings for SDK that I have:
As you can see, support for v4, v7 and v13 which were added manually. Those will be associated with Android API 19 Platform (in my case). When you create next new Gradle Module, you will still need to go to Project Structure to select the SDK under Project, but you will not need to add support libs again. Hope this helps.
I installed the compatibility library anyways. Something I didn't realize is that you can't create your first module by using File -> New Module. You have to use File -> Project Structure -> New Module for your first module. It's really unintuitive. After I did this, then everything worked.

Categories

Resources