I need to use http://viewpagerindicator.com/ to add static tabs below the actionbar on a Xamarin.Android project.
I downloaded the project and migrated it from maven to gradle to build it into an AAR file suitable for Xamarin consumption. I created a java binding project, added the AAR file as a LibraryProjectZip and added the v13 support jar as a ReferenceJar but it seems it is being lost somewhere in the way as evidenced by these xbuild logs:
BINDINGSGENERATOR: warning BG8C00: For type Com.Viewpagerindicator.IPageIndicator, base interface android.support.v4.view.ViewPager.OnPageChangeListener does not exist.
BINDINGSGENERATOR: warning BG8800: Unknown parameter type android.support.v4.view.ViewPager.OnPageChangeListener in method SetOnPageChangeListener in managed type Com.Viewpagerindicator.IPageIndicator
BINDINGSGENERATOR: warning BG8800: Unknown parameter type android.support.v4.view.ViewPager in method SetViewPager in managed type Com.Viewpagerindicator.IPageIndicator
The warnings chain continues for a long time, ending the process with a severely limited port
as the missing types make the methods depending on them to vanish away.
If i remove the support jar, the build fails because of missing classes from a utility named jar2xml, leading me to believe it is only used for part of the compilation/mapping process.
The support jar was taken from an unmodified android sdk at extras/android/support/v13/android-support-v13.jar.
Any help is most welcome.
There is a workaround to make these things work.
In my example, I had 2 reference jars (android-support-v4.jar and google-play-services.jar).
So if you just add these 2 jars with Build Action = ReferenceJar, you will see same errors as you posted.
BINDINGSGENERATOR: warning BG8800: Unknown parameter type com.google.android.gms.maps.model.Marker in managed type Com.Google.Maps.Android.MarkerManager.
Though the Marker and MarkerManager classes are defined in the jars, they're not getting resolved correctly on the C# side. To fix that you need to do is to just add already compiled C# bindings for these jars as references.
In my case I used Xamarin.GooglePlayServices package which had a dependency Xamarin.Android.Support.v4 (exactly as my jars).
In your case, you just need to add Xamarin.Android.Support.v4 package to your binding project.
In the end you will have something like this in your project structure:
Hope that helps!
Related
I'm trying to create bindings for the android sdk provided here https://www.nmi.com/sdks-and-apis#CDNA. The binding project builds, and I can add it into my xamarin android project but as soon as I include it I get the following error/s.
error: package com.creditcall.chipdnamobile does not exist
com.creditcall.chipdnamobile.IApplicationSelectionListener ChipDnaSample.Android
C:\Users\mikee\Documents\GitHub\ChipDna\ChipDnaSample\ChipDnaSample.Android\obj\Debug\90\android\src\mono\com\creditcall\chipdnamobile\IApplicationSelectionListenerImplementor.java 8
error: package com.creditcall.chipdnamobile does not exist private
native void n_onAvailablePinPads
(com.creditcall.chipdnamobile.Parameters
p0); ChipDnaSample.Android C:\Users\mikee\Documents\GitHub\ChipDna\ChipDnaSample\ChipDnaSample.Android\obj\Debug\90\android\src\mono\com\creditcall\chipdnamobile\IAvailablePinPadsListenerImplementor.java 33
There are 64 errors of the same nature just referencing different classes. I've put all the code on GitHub here
If I go into Obj/Release/generated/src I can find IApplicationSelectionListener so it is created some binding but it doesn't actually work. Could someone point me in the right direction about what I need to do to correct errors such as these?
Thanks
You have to change the build type of the jars. The java compile can't find it, because it's not present at compile time.
Change
InputJar to EmbeddedInputJar for ChipDnaMobile.jar
ReferenceJar to EmbeddedReferenceJar for CardEaseXMLClient.jar
For more info see: https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-a-jar
The important sentences:
Typically, you use the EmbeddedJar build action so that the .JAR is automatically packaged into the bindings library. This is the simplest option – Java bytecode in the .JAR is converted into Dex bytecode and is embedded (along with the Managed Callable Wrappers) into your APK. If you want to keep the .JAR separate from the bindings library, you can use the InputJar option; however, you must ensure that the .JAR file is available on the device that runs your app.
In java can add:
import com.runjva.sourceforge.jsocks.protocol.ProxyServer;
import com.runjva.sourceforge.jsocks.server.ServerAuthenticatorNone;
but how I can do it in my xamarin android app?
You can use a Java Bindings Library to use any AAR or JAR file in Xamarin for Android. Note that, due to some differences between C# and Java, it's possible that you'll have to do a little bit of manual mapping (there's an XML format provided for that). Using this, the compiler will take care of all the JNI bindings and other "plumbing" for you; it'll even convert naming conventions (e.g. prefix interface names with "I").
Are you using xamarin in visual studio ? if yes then you can simply go to tools and then nuget package manager and install packages.More over you can also search packages on nuget.org its the best site
First thing, check nuget if what you look is already there.
If it is not there, use this VS extension:
https://github.com/EgorBo/Xamarin.GradleBindings
Download the extension from here:
https://marketplace.visualstudio.com/items?itemName=EgorBogatov.XamarinGradleBindings
Then after adding the extension to Visual Studio, right click on your reference and then you will see
Add Dependency via gradle
Put the dependency id.
Choose the dependencies you need and download them.
DONT FORGET to put the dependency into your Jar folder (because you might the produced member in your reference dll).
You might need to fix the problems by adding some lines in the metadata.xml*.
If you still don't get any members, you can extract the classes.jar file from the .aar file then rename it to the package file and follow the .jar binding instructions:
https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/binding-a-jar/
*Refer to binding troubleshooting to fix any issue you face (most of the binding needs that step of fixing the metadata.xml): https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/troubleshooting-bindings/ )
I use log4j in Android project, dependency defined in project gradle like:
compile 'log4j:log4j:1.2.16'
When Lint check happens, the analyser reports "InvalidPackage" errors:
../../../../../../../.gradle/caches/modules-2/files-2.1/log4j/log4j/1.2.17/5af35056b4d257e4b64b9e8069c0746e8b08629f/log4j-1.2.17.jar: Invalid package reference in library; not included in Android: java.awt. Referenced from org.apache.log4j.chainsaw.ControlPanel.
../../../../../../../.gradle/caches/modules-2/files-2.1/log4j/log4j/1.2.17/5af35056b4d257e4b64b9e8069c0746e8b08629f/log4j-1.2.17.jar: Invalid package reference in library; not included in Android: java.awt.event. Referenced from org.apache.log4j.chainsaw.Main.1.
....
How can I fix that the better way?
Lint suggest to supress this warning by id, but this means supressing all warning by the type, am I right? This looks like not the best solution...
Maybe some way to specify lint not to check the log4j package?
awt itself is not supported in Android.
Instead use the native Android graphics as detailed in How to add java.awt.image package in Android and other questions like 25488832: using-awt-classes-in-android
Of course this doesn't help much if you rely on a library which relies on awt . Possibly there is an Android version of such library.
(You may be OK using parts of a library which provokes this error. You can only use parts of the library which do not use awt, else, RTE. For this, your build process would have to tolerate the reaction from Lint. There are likely safer ways around this. )
I have a Library project set up and a project which depends on this library project - Everything compiles fine and I've had the Dependent project running fine however;
I'm have an intermittent problem however while using an Activity from the Library project.
My Library project can be "unchecked" as a library project and the "picker" Activity can be run in isolation. Running the Library project in it's own right works fine with no problems.
When I use the Library project (and the "picker" Activity) from the dependent project it gives me either NullPointerExceptions (or historically DexOp) errors saying that the "picker" Activity can't find it's resources.
Can anybody tell me if they have experienced this before?
EDIT
Manually copying the layout.xml used by the Library project activity to the dependent project makes the project open the "picker" Activity correctly. Is this required?! Surely not? This further makes me wonder if there is a problem with merging/referencing the integer id's from R.java in the Library project.
EDIT
I'm not sure if this is of any consequence, but one of my Library projects is a wrapper around a set of custom views used in different front end projects.
These custom views each have an Activity so that they can be tested in isolation.
One of these view's has custom attributes, which while running in isolation work very well. However, it doesn't seem like the dependent project correctly pull's in the attributes and keep's them in their original namespace, causing the imported layout's to throw compilation errors:
[2012-05-16 12:07:28 - Project] D:\opt\workspace\CustomGlowList\res\layout\main.xml:14: error: No resource identifier found for attribute 'listId' in package 'com.company.library.glowlist'
[2012-05-16 12:07:28 - Project] D:\opt\workspace\CustomGlowList\res\layout\main.xml:14: error: No resource identifier found for attribute 'type' in package 'com.company.library.glowlist
EDIT
DexOp errors were solved by removing a duplicate file name which was present in the Dependent project. Not sure if the file name was the problem or the contents of the file.
EDIT
I've been unable to find a solution to this problem as of yet (although #yorkw's answer certainly helps with the xml attributes! Thanks).
I have managed to make this problem intermittent however:
I have gone through each of the library projects and ensured they all had their own namespace (ie, com.company.library.component1, com.company.library.component2 etc). After a couple of clean's (each project ordered with the correct precedence) this problem resolves itself, however does eventually come back when switching around library/not a library to test components.
Cause:
Issue 9656: Library projects don't support custom XML attributes for custom classes
Solution:
Upgrade to latest SDK & ADT version (fixed was released since r17) and use http://schemas.android.com/apk/res-auto as custom attributes' namespace URI, see Revisions for ADT 17.0.0:
Added support for custom views with custom attributes in libraries. Layouts using custom attributes must use the namespace URI http://schemas.android.com/apk/res-auto instead of the URI that includes the app package name. This URI is replaced with the app specific one at build time.
Related Topic:
Help with a custom View attributes inside a Android Library Project
not sure how you use the android library , but i've done this thing a lot of times without any problems , so please have a reading of the next things regarding using android libraries:
in order for an android project to use an android library project , you can either edit the "project.properties" and add the path to the library project there , or , much easier, right click the project (that uses the library project) , choose "android" category , and choose there "add" and choose the library project.
in order to make the android project to always open the android library project , also choose "java build path"->"projects" and choose the library project.
on the "project.properties" , try to set the target to the same target for both projects , and to the newest one that you have (latest now is 15) ,even if you can't test the app on this android version .
source files and all resources files (in the res folder) are ok to be used on the library projects.
assets folders cannot be used inside the library project . only on the android project that actually runs , the assets folder can be used . same thing goes to the proguard file .
the manifest of the library projects almost doesn't need to have almost anything . see this post for more information: https://stackoverflow.com/a/10445630/878126 . if there are activities on the library project that you wish to be able to access via the project that use it , don't forget to include them in the manifest of the android project (no need to write them in the manifest of the android library) .
remember to run lint before you export the app . it gives you plenty of warnings , but the most important warning is when you use too-new functions that cannot run on the range of APIs that you target . this is important for libraries since it's easy to get lost if there are multiple sources .
if you wish to extend activities on the android library , you need some kind of a method to go between them . the only way i know of is to extend the application and let it be the manager of how to create an intent for each of the activities . i think you can do other tricks , but they are all probably similar to this one.
if you have the same resource (any resource on the "res" folder) on both the android library and the android project, the one on the android project will replace the other one . this has advantages and disadvantages . remember that you can't have different file extensions for the same resource .
The problem was being caused by the R files from each of the Library projects not correctly being built and referenced. The resource files are built and referenced directly from the calling project.
Each of the Libraries need to have unique package as defined in the AndroidManifest.xml. This leads to each of it's resources being compiled in that unique namespace within the calling project alongside the Library jar which contains the class files.
The problem becomes intermittent when switching between a library and a runnable project because a clean and build needs to take place to regenerate these files as it isn't done automagically when unclicking the Use as library checkbox, where as the jar (and java classes) don't require as much coaxing for them to be correctly referenced as the library projects references them when acting as a Library.
This can lead to intermittent and also varying errors including missing references, DexOp and NullPointerExceptions depending on to what degree the R.java files have been mangled or partially built and what conflicts are taking places between packages.
I have same issue like, I have one library project and it has some activity.
When I was calling library project's Activity from my Main project, layout files resources were not getting loaded properly for the libray project's activity and giving "nullpointer exception" or "class could not be loaded", etc.
Solution: I have noticed that same layout file name is getting used in my Library project and Main project. I have just renamed those activity and it is solved.
May be this will help you.
I had similar issue when referencing Library project inside the Android App project. I deleted the R.java file from Library project so it generated again and App picked up the generated file. You should see the generated R.java file under your app project->gen->library_namespace_R.java.
I have a basic Android project created in Eclipse Indigo. I have a third-party library on my build path, and it is called is used when I instantiate a class from that library in my initial activity.
Although the app build just fine, I encounter the following error:
10-02 19:51:17.311: ERROR/AndroidRuntime(314): java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>
Earlier in logcat, I do observe the following error message:
10-02 19:50:48.670: DEBUG/dalvikvm(295): DexOpt: not verifying 'Lorg/apache/http/conn/scheme/Scheme;': multiple definitions
This class is included in the third-party JAR; is it used by Android somehow/somewhere to suggest a conflict or other source of "multiple definitions?"
Thanks!
How does one reconcile the conflict - do I have crack open the third-party JAR and exclude the conflicting files?
My guess is that this would not help, though you can certainly try it. Somebody would appear to be trying to call a method on Scheme that perhaps exists in the JAR's own private copy of that class but is not in the Android SDK.
If the third-party JAR in question is Apache HttpClient, simply don't put that JAR in your build path, as HttpClient is already part of Android, and stick to methods that are in the SDK. If the third-party JAR is not Apache HttpClient, I suspect that once you remove their duplicate org.apache.http classes, that something else will break that depended on their own private version of those classes. If that is the case, you should probably take it up with the third-party developer directly, to work with them on Android support for their JAR. You might be able to use tools like jarjar to get past this, but I would not count on it.
You can try something like jarjar, it can break open the jars and rename the packages to a different path at build time. This avoids conflicts like the ones you're having. I'm just not sure it will work with Android.