Transitioning from Using Jar to Dependency for Ion - android

I originally had ion-1.3.8.jar in my libs directory in Android Studio, with compile files('libs/ion-1.3.8.jar') in my build.gradle file. I also had (and still have) androidasync-1.3.8.jar in my libs folder and an entry for it in build.gradle.
I want to get rid of the ion jar and instead use a dependency, but when I delete the jar and put compile 'com.koushikdutta.ion:ion:2.+ in my build.gradle file, I get an error ("cannot resolve method get(String...))" on the following line of code in one of my classes: result.getHeaders().get("USER-TOKEN");.
I'm guessing that line of code probably wasn't what it should have been all along, but it did work with Ion 1.3.8. I can't figure out what I should change it to, and though I can probably figure it out with some trial and error, I would like to hear from the community or Koush about this.
Also, Android Studio is warning me that "Avoid using + in version numbers; can lead to unpredictable and unrepeatable builds". Any thoughts about this?
Here's my code:
Ion.with(activity)
.load(url)
.setJsonObjectBody(loginObject)
.asJsonObject()
.withResponse()
.setCallback(new FutureCallback<Response<JsonObject>>() {
#Override
public void onCompleted(Exception e, com.koushikdutta.ion.Response<JsonObject> result) {
String errorText = activity.getString(R.string.unable_to_login);
if (e != null) {
String errorMessage = e.getLocalizedMessage();
Log.e(TAG, errorMessage);
if (errorMessage.contains(activity.getString(R.string.unable_resolve_host))) {
errorText = activity.getString(R.string.no_internet);
}
}
else if (result != null) {
JsonElement reply = result.getResult().get(activity.getString(R.string.user));
if (reply != null) {
errorText = NO_ERROR;
SessionManager.setProfile(result.getResult());
String userToken = result.getHeaders().get(activity.getString(R.string.user_token));
SessionManager.createLoginSession(userToken);
if (SessionManager.isProfileComplete()) {
activity.startActivity(new Intent(activity, NavigationDrawerActivity.class));
}
else {
activity.startActivity(new Intent(activity, ProfileActivity.class));
}
}
else if (result.getResult().getAsJsonArray(activity.getString(R.string.errors)) != null) {
errorText = activity.getString(R.string.login_error);
}
}
else { // There was some other problem logging in
Log.e(TAG, "Unknown login problem");
}
requestCompleted.onRequestCompleted(errorText);
}
});

On version 2.+ of ION the API probably changed.
If you want to use the old API that works with your code, change your dependency to:
compile 'com.koushikdutta.ion:ion:1.3.8'
It will also automatically add the Android Async 1.3.8 dependency for you.
The warning saying that you should avoid the '+' is because that way, gradle will always get the newest version it finds, where some APIs can change and then break your code.

The API changed slightly in 2. One of those was changing the names of a few methods around the ResponseFuture and RawHeaders classes. In your case, getHeaders() was simply renamed to headers().
The transition from 1.x to 2.x is fairly painless, but there are some breaking changes nonetheless.
If you don't want to deal with the breaking changes, and use the latest version of 1.x in gradle, do the following:
compile 'com.koushikdutta.ion:ion:1.+
There are no breaking changes between 1.x versions. Current 1.x version is 1.4.1 I believe.

Related

Unity Admob plugin; The application crashes when you try to change "TextMesh.text"

1) I used the sample project on https://github.com/googleads/googleads-mobile-unity
2) I added a "TextMesh" object to the scene (Game object name: "Screen Text").
3) I have added the following lines;
public class GoogleMobileAdsDemoScript : MonoBehaviour
{
TextMesh screenText;
...
...
public void Start()
{
screenText = GameObject.Find("Screen Text").GetComponent<TextMesh>();
...
...
public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
{
screenText.text = "Test 1";
...
...
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
screenText.text = "Test 2";
...
...
4) When the video is finished or canceled, I'm trying to change the text and the app is always crashes.
5) Unity Version: Unity 2017.3.1f1 (64-bit). Android SDK: Platform 27. Phone Note 5
Is this an issue? or do I have to fix something?
(Here is Log file when video rewarded: https://justpaste.it/7b1hn)
For future reference, yes, it happens regularly. It's not a simple missing reference issue.
I have also tried creating a Canvas with just an Image: no crash.
Then I have tried creating a Canvas with just a TextMeshPro text: CRASH!
The simplest fix I have found (after many many hours of tests) was to "change the text" one frame later, through a very simple coroutine starting with "yield return new WaitForEndOfFrame()".
I'm still reading and investigating, and will update here if I find anything.
Have you tried adding check for screenText? Try this.
if (screenText != null)
screenText.text = "Test 2";
else
Debug.Log ("NULL screenText");

TweetViewFetchAdapter.setTweetIds does not work in android

I want to display some tweets with the twitter API in my app. To do so I have fetched some tweet ids (which is working without any hassle) and use the TweetViewFetchAdapter adapter provided by the Twitter API to display my tweets.
The weird thing is: this has worked at some point! But then suddenly it stopped working (company app, multiple people working on the code but I haven't seen any changes to the twitter stuff in the time between working and not working)
The code is super straight forward taken from the official twitter site:
// fill the tweet adapter with the loaded tweet ids
#Override
protected void onPostExecute(List<Long> params){
if (params != null && params.size() > 0) {
adapter.setTweetIds(params,
new LoadCallback<List<Tweet>>() {
#Override
public void success(List<Tweet> tweets) {
Log.i("twitter", "Success!");
}
#Override
public void failure(TwitterException exception) {
Log.e("twitter", "Exception: " + exception.getMessage());
}
});
}
Log.i("twitter", "params.size = " + params.size() + "adapter.tweetCount = " + adapter.getCount());
}
(inside an AsyncTask). The adapter seems to fail to set the tweet ids as the debug output is I/twitter﹕ params.size = 10 adapter.tweet Count = 0
I tried to debug/have a log output in the success/failure callbacks, but I never got anything as if the methods would never be called (quite weird actually..)
Regarding log cat output I haven't seen any, but I'm afraid there is a little chance I might have messed it up as we just recently moved to Android Studio and I just can't get my head around some stuff there yet.
Issue was caused by an wrong version of okhttp / okhttp-urlconnection.
The weird part is that no debug messages was shown. This code resolved the debug message issue and helped resolve the issue overall:
final Fabric fabric = new Fabric.Builder(this)
.kits(new Twitter(authConfig))
.logger(new DefaultLogger(Log.DEBUG))
.debuggable(true)
.build();
Fabric.with(fabric);
Overall fix: change build.gradle:
dependencies {
// ...
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
}
Original conversation: https://twittercommunity.com/t/adapter-settweetid-seems-to-be-unable-to-load-the-tweets-but-doesnt-fire-a-success-failure-callback/36506/13

Phonegap plugin for android is not working. Why?

I cannot make an Android phonegap plugin work. Not even a single one of the examples I found nor my pathetic failures trying to create one by myself. I first tried with Tutorials like this one. They don't work for me. I always end up with a Cannot call method of undefined error.
So I tried something ready. Got this project from github. It's just a simple plugin to show a toast. I checked everything that i learned on the tutorials:
//the package name in the java
package com.phonegap.toast;
//my class extends Plugin and has a simple show toast method.
public class Tutorial extends Plugin {
#Override
public PluginResult execute(String cmd, JSONArray args, String callback) {
if(cmd.equals("toast"))
{
return showToast(args);
}
return null;
}
private PluginResult showToast(JSONArray args) {
final String message;
try {
message = args.getString(0);
ctx.runOnUiThread(new Runnable()
{
public void run() {
Toast myToast = Toast.makeText(ctx, message, Toast.LENGTH_SHORT);
myToast.show();
}
});
return new PluginResult(PluginResult.Status.OK);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
}
the plugin is defined in res/xml/plugins.xml
plugin name="Tutorial" value="com.phonegap.toast.Tutorial"
and no, if i put it on rex/xml/config.xml it also doesn't work
Last, the method that calls the plugin:
function createToast() {
// i also tried window.Tutorial.showToast('Hello AndroidOpen'); with no success
window.plugins.Tutorial.showToast('Hello AndroidOpen');
}
And here I get the same error again.
10-22 15:39:07.770: E/Web Console(2885): Uncaught TypeError: Cannot call method 'showToast' of undefined at file:///android_asset/www/main.js:123
Any enlightened soul can explain to me what I'm doing wrong? I've been trying this for days, with many different plugins, both my own and even this ones and I can't find out what is it.
Okay, here are a few things that are probably tripping you up. First if the config.xml file exists in res/xml then it will take precedence over plugins.xml. So you will need to add your plugin line to config.xml instead.
Make sure you are including the .js file for your Toast plugin.
Third, window.plugins has been deprecated away so you may need to modify the .js if you are using PhoneGap 2.0.0 or better. Check out my blog post on the topic. The root change is that you now need to new PluginName in your JS as it is no longer put in window.plugins by default.

Error integrating Aurasma: Resource Integrity check failed

I am trying to Integrating Aurasma in my application. All application work well but on Aurasma part when I launch it on Button Click IT throws a message on splash screen as "An error is occurred" and on Log Cat It shows "Resource integrity check failed" I am wondering why this is happening, I integrate aurasma on a separate application without any click event, it launches directly then it works but in side of my application its not working, why. I am sure about these points:
Make sure the SDK tools are version 14 or above.
Check the Eclipse project to make sure that AurasmaKernel is set as required on the build path
Check that the AurasmaKernel package has built properly in Eclipse (also try building it manually)
Make sure that the kernel is correctly extracted, and that your resources don't clash with any of the packaged library
But yet it not working same error message.
Code for launching Aurasma is below:
aurasmaIntent = AurasmaIntentFactory.getAurasmaLaunchIntent(HomeActivity.this,
getString(R.string.app_name), getString(R.string.app_version));
} catch (AurasmaLaunchException e) {
Log.e("AKTest", "Error getting intent", e);
showDialog(DIALOG_ERROR);
return;
}
if (DELAY_START) {
AurasmaSetupCallback callback = new AurasmaSetupCallback() {
#Override
public void onLoaded() {
dismissDialog(DIALOG_PROGRESS);
startActivity(aurasmaIntent);
}
#Override
public void onLoadWarning(final int code) {
Log.w("AKTest", "Preload warning: " + code);
}
#Override
public void onLoadFail(final int code) {
Log.e("AKTest", "Preload error: " + code);
dismissDialog(DIALOG_PROGRESS);
showDialog(DIALOG_ERROR);
}
};
showDialog(DIALOG_PROGRESS);
AurasmaIntentFactory.startAurasmaPreload(getApplicationContext(), aurasmaIntent,
callback);
} else {
startActivity(aurasmaIntent);
}
}
If you change some resource from Aurasma library(layout or string) you will get this error - "An error is occurred". Library checks resources on Aurasma start. Don't change or delete any files.
Another thing that can cause error is:
aurasmaIntent = AurasmaIntentFactory.getAurasmaLaunchIntent(HomeActivity.this,
getString(R.string.app_name), getString(R.string.app_version));
Here second parameter is userAgentName. This is the name of your app that you have from studio.aurasma.com. In "Make your own app" you can see the application name - this name is connected with your application but can be different.
check your minSdkVersion in the manifest
android:minSdkVersion="8"

<-- operator in android graphics

v1.addView(new TransfomedViewWidget(<-- (9)
this,
new Transformation() {<-- (10)
#Override public String describe() { return "rotate(-30)"; }
#Override public void transform(Canvas canvas) {
canvas.rotate(-30.0F);
} }));
I am new to Java and android programming , can anyone tell me what this <-- operator means? I am getting error while trying to compile this in eclipse.
It isn't part of the syntax, it loks like something else has put it there.
Certainly it was a note or comment ... add // in front of them and try to compile again.

Categories

Resources