I'm developing an API for Android and it works great but I'm not sure how to package/distribute it. I've gotten the "meat" of the API into a jarfile - that's all the classes and an XML file in res/values/attrs.xml (I'm not sure if there's a way users can reference to that without having to copy my attrs.xml into their /values folder, but that's another question).
While trying my API in a test case, I've added my .jar to the build path and I can import a class successfully if I want to, but I don't want to :P My API allows users to implement a custom View into their own XML files, so nothing is instantiated in code.
The question: How can users reference to a custom View in my API? For example, if my View is called FooView and is in package com.myfoo, the following XML fails to load:
<com.myfoo.FooView
android:layout_width="fill_parent"
android:layout_height="100dp"
/>
Does this have to packaged into a jar , As i see facebook android sdk they give out the source code . I set it up as a new android project and from my android project reference this as library.In that case i am able to access all the apis exposed
You might want to look into Android Library Projects. These are basically normal android projects, which can be referenced as a library. This means you can define classes, layouts and resources as you would normally, and just use them in your main app (in this case in your clients app) as if they were defined in the same project. This allows you to reference views in XML like you tried above via <packagename.classname ... />.
There is one huge downside though (which is especially important when you create custom views):
styleable-resources simply don't work. This is a bug.
According to this question it's going to be fixed in the next devtool release though.
With that in mind I recommend setting up a small test project with a test library project and see if everything that you need works correctly.
Related
Since VS2019, I have noticed that every new project has regular XML as its resources like native Android Studio applications, but previously (2015 or 2017) it created AXML files.
Internally, the files looked exactly the same, but recently I'm getting new bugs in Xamarin.Android in each new release in VS2019 (Windows or Mac), for example:
Link assemblies is crashing
Build with Linking is Crashing in Xamarin.Android 9.5
Perhaps, I should use AXML files as an uncommon comment came yesterday:
The linker removes classes that are needed and apparently doesn't
parse the axml to see that they are in fact needed
This situation makes me wonder if there is any specific difference between them because when I run my app it works perfectly fine while it's not for Release or certain configurations like linking all assemblies.
Important note:
As my title of the question says: I'd like to know the difference between both extensions since for any reason the extension changed without any notice. The previous situations only raised my curiosity about this situation, they are not necessary linked.
.axml is nothing more than an extension hack that was used to render Android Layout Files i.e. Android flavored .xml files inside Visual Studio. It literally meant .axml (Android XML).
We previously lacked infrastructure to interpret flavored versions of .xml files coming from all different types of workloads. However in 16.2 and 8.2 respectfully (Visual Studio and Visual Studio for mac), you can use .xml seamlessly in your application and be provided a layout editor, rich intellisense, and more.
If you don't require a layout editor, you have been able to use .xml since the first release of MonoDroid as .axml is processed the same way as .xml at the end of the day.
First, the linker does not do anything with your layout files. So .axml or .xml, it just won't touch it or parse it. The linker only work with the classes represented by the layout files, not the layout files themselves.
Now, regarding the ".axml" versus ".xml" I believe the ".axml" extension is just a legacy thing from MonoDroid. The only goal of that specific extension was probably to identify android layout files, from regular xml files, without any advanced logic (it's only a supposition).
Long story short, if you're facing issues in your project regarding the linker, it's probably not related to your extension choice for layout files. You should keep whatever Visual Studio defines as the default.
First of all, Link all assemblies is prone to crashing and while those crashes can be fixed with some level of effort and knowledge, exactly because it causes more trouble than what it helps it isn't recommended option by Xamarin. So those are not 'bugs', those crashes are expected behavior.
Second, that comment on github that you linked doesn't tell there is any problem with axml files. It says that your axml file requires some library to be present and that it cannot be determined by the compiler which removes it and causes crashes.
Basically it has nothing to do with the question in your title.
I have task to modify android gingerbread launcher (2.3). I want to download launcher's sources and add some functionality. I have found sources here:
android Gingerbread launcher sources
I download this and import into workspace as is. As a result I get numerous compile errors (some classes are missing, instance variables are missing, etc). Why? I mean why wouldn't it compile? What should I do to make it compile?
P.S. By the way, when project is imported, used platform as per project settings is not 2.3, so I have to manually set it to 2.3. However, numerous errors still remain.
To convert an AOSP application into a standalone SDK application, you will need to find all the "classes and variable not present in the SDK" and remove/replace the references to them. The simplest is to remove the references to them, if the app will still run with reduced functionality. For references to internal resources, you can simply copy those to your project and modify the R values to point to your local copy. You are welcome to examine the "classes and variable not present in the SDK" and determine that you can copy those as well (refactoring them into a new package), in which case you would update your project to refer to the copied and refactored classes.
The easier solution would be to use someone's source where they already did that..Here found one at
Launcher2 full compilable Ginngerbread lancher code
Have a look at here.
It is the Launcher2 from ICS, not GB, but they are very similar.
From Wiki: Note that it is not completely bug free, and adding widgets will crash the app (as it uses a system level permission. Maybe if you installed via root it'll work).
Here's a list of what all I had to do, that I can recall doing:
There are lots of methods like setFastXXX (for example, setFastAlpha()) that aren't available to us. Changing these to setXXX (for example, 'setAlpha()`) worked for me.
Some thing which are available to us via getSystemService() are initialized directly in the code, like the usage of the Vibrator class. These need to be changed to use getSystemService().
Android has several system icons available, such as these.
I can't use them in my application (for system notifications as an example) since they are not made public within the API. So I would like to add them to my project in eclipse using ADT.
Is there a way to do this automatically? For example, when I start a new android project, it allows me to create an icon for my project, and creates it in all sizes and places them in the correct resource folders. I'd like to import other icons from the android library the same way.
Thanks.
From what it says here:
NOTE: Some of the images in the Android jar are not public and
therefore cannot be directly used (you can copy them to you own
application, but can't reference them via the "android" package
namespace). This project does not distinguish between what is public
and what is not. If you try to use an image that is not public, you
will get an error indicating that fact.
So it seems that the way to go is to copy the icons to your project, as Android won't allow direct access to them.
I am implementing menus using TWL (http://twl.l33tlabs.org/) in an app written using Libgdx. The app runs fine if I don't start any menus, but as soon as I go to a menu screen it immediately force-closes. Menu screens work fine on the desktop version.
In which build path should TWL-android.jar be included (right now it behaves the same in main, android, and both)? And how will the program know to use the libraries from this .jar instead of the default gdx-twl.jar? Will I have to manually implement something in code to use one or the other depending on platform?
There does not seem to be any documentation or sample code of anyone using TWL on android, only mentioning that it can be done.
Running debugger attached to phone gives the following logcat error:
Could not find class 'com.badlogic.gdt.twl.Layout' referenced from method com.Nanners.OptionsScreen.<init>
I think that TWL-android.jar should be added to android project's build path too. Location of .jar is not relevant.
When you add TWL-android.jar. As that is Android specific you can't use it on the core project, so the classes you are importing are the ones from gdx-twl. To make it simpler to explain I will divide it in different escenarios.
You add TWL-android to your Android buildpath. But you use Gdx-twl in your core project. Which isn't added. Thus getting a:
Could not find class 'com.badlogic.gdx.twl.Layout'
You add both TWL-android AND Gdx-twl to your build path. Thus getting duplicated classes and:
Conversion to Dalvik format failed with error 1
Solution
If you use TWL-android classes, you can only do it inside the Android project:
Merge Core, Desktop and Android project. Or
Use Interfacing with Platform Specific
If you use Gdx-twl:
Don't do it.
Actually the best solution is to get rid of all twl stuff and use Scene2d.Ui instead. Its crossplatform and much easier to use.
When I first started a project in Android under eclipse, I am able to access the Graphical Layout designer, so I fast can design my application. But when I create a new XML file in order to add components to another class I can use this feature, how can I fix this?
Sometimes when you have a project with, fore example, 2.1 with google apis the editor dont work property. Delete the google api and try other time