Xamarin droid challenges when extending HTTPContent - android

My question is a follow up on: How can I calculate progress with HttpClient PostAsync?
This solution works perfectly. Just remember, if you are using Xamarin, to include the Microsoft.Net.Http nuget package in the .iOS project otherwise you'll get a TypeLoadException when initialising this class – Davide Vosti Oct 27 '15 at 6:47
I'm working with a Xamarin PCL project. This works perfectly on iOS.
I run into problems on droid. I'm targeting 4.4, however, the MSFT HTTP.Net droid package targets 7.1 and I get the expected TypeLoadException. Any workarounds (that keep me at 4.4)?
Thanks, D

Not an answer to the question, but I've hit the same problem here today trying to add upload progress support by extending HttpContent, using Xamarin with a core PCL project and Xamarin Android (there's also an iOS project using the core). I'm adding some extra detail in this post rather than creating a duplicate SO post.
When I'd tried any of the proposed solutions on StackOverflow (including the one the original poster had linked to) that extend from HttpContent, I'm getting an exception of:
System.TypeLoadException: Type Test.Project.FileService+CustomStream has invalid vtable method slot 6 with method none
Which I'm guessing is the same problem they're seeing. I'm not including Microsoft.Net.Http in the PCL/Android project, but we are using System.Net etc.
When I'd tried deriving from StreamContent instead, while that didn't crash, breakpoints were only hit for the contructor and TryComputeLength, but not SerializeToStreamAsync, though the data was successfully uploaded to the server without that being hit.
This is a legacy app I'm working on targetting Android 4.4 too. While I've managed to have this kind of thing working on platform specific (Xamarin.Android) in the past, that would be a much bigger change to this app so ideally would like to be able to get this working in the PCL

Related

Import Unity Classes into Existing Android Project

As the title says, I have an existing Android project and I want to import Unity classes.jar so I can access the UnityPlayer.UnitySendMessage.
I found this other question with similar goal, but the answers were unintelligible or unhelpful.
I also found this on the Unity forums, but it is apparently very outdated (2011).
Essentially, all I'm trying to do is:
Open up an Android application.
Select which scene (or, preferably, more than one scene) I want to view from the Unity app.
Launch the Unity GearVR application.
Play the selected scene(s).
I've already got steps 1 and 3 working, and steps 2 and 4 I'm making work by loading each scene up as a different APK and launching a specific APK depending on which scene I want to view, but, ideally, I could host all the scenes in a single application so I could then watch several off the scenes in a row (and also so I could cut down significantly on memory usage).
I've found some tutorials on using UnityPlayer.UnitySendMessage, so I think I can get it working if I can only get Android Studio to recognize and use UnityPlayer.UnitySendMessage, but if you have any other ideas, I appreciate those as well!
I've found some tutorials on using UnityPlayer.UnitySendMessage, so I
think I can get it working if I can only get Android Studio to
recognize and use UnityPlayer.UnitySendMessage
Get classes.jar from one of the sub-folders from
<UnityInstallationDirectory>\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono
or
<UnityInstallationDirectory>\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\il2cpp
depending on if you are using mono or IL2CPP as Scripting Backend to build your Android Project.
Import it into Android Studio. Right-click on it and click Add As library and Android Studio should add it as library. See this if you are still confused. You can now use UnityPlayer.UnitySendMessage.
As for the rest of your question, I think that you should look into this answer. It explains how you can show Unity scene in a sub-view. That is another way to get what you want.

INSTALL_FAILED_DEXOPT when using GreenDao

Background
I wanted to simplify the usage of DB in an Android app.
For this, I've compared some third party libraries that create a DAO layer.
I've come up with a nice library called "GreenDao" (presentation about it here) . The website shows that it's faster than other competitors (like ORMLite) and is optimized for Android.
The problem
For some reason, on some device (usually old devices, with GB) , I get the next console error when trying to install the app:
Installation error: INSTALL_FAILED_DEXOPT
Please check logcat output for more details.
Launch canceled!
I've searched for the reason of this error, but couldn't find out how to solve it. Many complain about this error, but I can't find out why it occurs, and what can be done.
The error is quite common and known, but it's never mentioned as the result of using this library, yet when I remove the usage of this library, everything works fine...
Also note that on newer devices (like nexus 4) it installs and works just fine, and that the sample itself also works fine no matter which device I test it on.
The question
Why does it occur?
Is it possible that the structure of the classes is just too much for old devices to load, since we use other libraries ?
Could it be that I've reached the limit of code that is supported by android apps?
The jar file itself takes just 87KB ...
How can I solve this?
Ok, I've found the problem and the solution:
It has nothing to do with GreenDao.
It's because the app uses too many jars, so maybe Android has a limitation of code.
The solution is to either delete un-needed jar files or delete a lot of code.

SimpleJSON C++ Class cannot parse strings on Android (NDK) yet same class works on every other platform

I've successfully ported my game to Cocos2d-x and it runs great on Linux, QNX, iOS and Mac. I've also setup the Android NDK and am able to successfully build and run the App on Android (all from the exact same sources, which is really neat !)
On Android there is however one strange thing happening: the SimpleJSON.cpp class I'm using is unable to parse correctly formated JSON strings. Im using this framework: https://github.com/MJPA/SimpleJSON
I've looked into the code, but I'm not much of a CPP expert to see what's (if any) wrong with it (it works on all platforms except Android and it compiles just fine).
I did notice the Class makes use of wchar_t quite extensively and I also understand that that might be a problem on Android.
Anyway I've been figuring out how to get this thing to work for the last 48 hours, but I failed miserably. Is there anyone out there that can point me in the right direction ?
Is there a compiler option that I forget to set ?
Is this class just not going to work on Android ?
How can I change the class to get it to function properly on Android also ?
All hints are welcome.
Rgds.
Make sure to use the latest framework. Also look for #if defined(ANDROID) in the code, maybe there's a bug when compiling for Android.

Incorporating both Contacts and ContactsContract into an Android application

Greetings all,
I realize this issue has been posed before in other forms, and believe me, I have been searching the net for days trying to find the answer. However, I'm fairly new to Android and Java, and I need a little guidance please.
I presently have two version of my app, one for Android 1.5 and 1.6, and another for 2.0 and beyond. As you probably guessed, it's because the Contacts API is different.
I recently became aware that it was possible to combine both methods into a single app, by using dynamically loadable classes. Very cool! After days of attempts, I still haven't been able to do it successfully... or at least, it won't run.
I have come across 3 examples of how to do this - one by Google, called "Business Card", another that had something to do with Spinners, and a 3rd was something someone here created. My problem is that each one seems to me to have a showstopper.
I'm using Eclipse on Windows 7. My app was first created for A1.5, so that's the one I'm upgrading. What's happening is that my ContactsAccessorNewApi class needs to import the ContactContracts, and according to Eclipse, that won't work because my project was originally built without support for it. Hence, it won't run. I've tried adding the android.jar for SDK level 5 into the project, but that creates a whole mess of other problems.
My code for this pat of my app is exactly like the Google example "Business Card" - so if someone could help me cross this hurdle, I'd be very grateful. I'll be happy to post any code that you need to answer my question.
Thank you!
another that had something to do with Spinners
If you mean this sample project, that's mine.
I'm using Eclipse on Windows 7. My app was first created for A1.5, so that's the one I'm upgrading. What's happening is that my ContactsAccessorNewApi class needs to import the ContactContracts, and according to Eclipse, that won't work because my project was originally built without support for it.
You need to set your build target (Project Properties > Android) to be high enough that ContactsContract exists (android-5 or higher).
So long as your android:minSdkVersion in your manifest is set to support earlier versions of Android (e.g., 3 for Android 1.5), your app will still install on older emulator AVDs and devices.
I've tried adding the android.jar for SDK level 5 into the project, but that creates a whole mess of other problems.
Yeah, don't do that.

Force close before onCreate, activity class not found exception

I just started testing my app on android 1.5, and it doesn't want to run at all. I have a breakpoint in onCreate on my main activity, but I get a ClassNotFound exception even before reaching that. The class not found appears to be the class of my main activity. The exception happens in:
ActivityThread.performLaunchActivity
It runs fine on 1.6 and later, so I assume I'm using something that isn't supported on 1.5. But how can I find out what it is? Any tips on how to debug this would be greatly appreciated.
Thanks.
If you have imported jars, verify that they are in the /libs directory and not in the /lib directory and they are imported as jars and not as external jars
I had the same problem today. It's difficult to identify which class is not supported. The stack trace doesn't really shed any light on it, it just gives the somewhat misleading message that your activity class cannot be found. A couple API's that I have used that I know are not in Android 1.5 are:
- Bluetooth (2.0 and up)
- Text to Speech (1.6 and up)
I ran into this issue because I added support for text to speech to my app and didn't think to check the docs first to make sure text to speech is supported on Android 1.5. I was dismayed to learn it was only added in Android 1.6. To work around the problem I had to do a couple things:
Remove the "import android.speech.tts.*" from my activity
Create wrapper classes that mirror the text to speech API and call the real text to speech classes from there.
Put if statements around the calls to my wrapper class to make sure I only call out to it if the Android SDK level is 1.6 or above. You can check the Android SDK level by inspecting android.os.Build.VERSION.SDK
In your Android Market listing, indicate that the text to speech functionality is only available if you have Android 1.6 or higher installed.
The nice thing about this approach is that in the future, when I decide to abandon support for Android 1.5 I can easily change my calls to my wrapper class to just call the text to speech API directly and rip out the wrapper classes.
I did something similar for my Bluetooth code.

Categories

Resources