JNI parsing error using Eclipse - android

Maybe it's my configuration problem but... My Eclipse shows error when i'm trying to do sth like this:
// let say that i have a vector like this:
std::vector<Point2f> someVec(/*init vector or sth...*/);
and i want to read a field or whatever like this:
someVec[0].x = 10;
but then Eclipse cry that it's error - x is not a property. Moreover sth like this is "invalid" too:
// both are 'invalid'
someVec.operator[](0);
// or
someVec.at(0);
On the other hand I can do sth like this and now Eclipse doesn't see any problem:
Point2f& p = someVec[0];
p.x = 10;
This 'hack' works well:
someVec.data()[0].x;
Have ever had similar problem maybe?

I found an answer. I included stddef.h which define size_t and some other stuff. Now problem is solved.

Related

Lottie animation strange error on Android, works on iOS. The Path cannot loop back on itself

Someone made this Lottie animation for me: https://lottiefiles.com/share/DO3Kpo
It seems to work perfectly on iOS, but on Android it throws the following Exception. We tried a lot but we can't figure out what the problem could be. Anyone any thoughts about it?
Java.Lang.IllegalStateException: Unable to parse composition ---> Java.Lang.IllegalArgumentException: The Path cannot loop back on itself.
at java.lang.IllegalArgumentException: The Path cannot loop back on itself.
at at android.view.animation.PathInterpolator.initPath(PathInterpolator.java:185)
at at android.view.animation.PathInterpolator.initCubic(PathInterpolator.java:158)
at at android.view.animation.PathInterpolator.<init>(PathInterpolator.java:89)
at at android.support.v4.view.animation.PathInterpolatorCompat.create(PathInterpolatorCompat.java:82)
at at com.airbnb.lottie.parser.KeyframeParser.parseKeyframe(KeyframeParser.java:130)
at at com.airbnb.lottie.parser.KeyframeParser.parse(KeyframeParser.java:58)
at at com.airbnb.lottie.parser.PathKeyframeParser.parse(PathKeyframeParser.java:21)
at at com.airbnb.lottie.parser.AnimatablePathValueParser.parse(AnimatablePathValueParser.java:29)
at at com.airbnb.lottie.parser.AnimatablePathValueParser.parseSplitPath(AnimatablePathValueParser.java:55)
at at com.airbnb.lottie.parser.AnimatableTransformParser.parse(AnimatableTransformParser.java:54)
at at com.airbnb.lottie.parser.LayerParser.parse(LayerParser.java:99)
at at com.airbnb.lottie.parser.LottieCompositionParser.parseAssets(LottieCompositionParser.java:147)
at at com.airbnb.lottie.parser.LottieCompositionParser.parse(LottieCompositionParser.java:77)
at at com.airbnb.lottie.LottieCompositionFactory.fromJsonReaderSyncInternal(LottieCompositionFactory.java:248)
at at com.airbnb.lottie.LottieCompositionFactory.fromJsonReaderSync(LottieCompositionFactory.java:242)
at at com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(LottieCompositionFactory.java:177)
at at com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(LottieCompositionFactory.java:171)
at at com.airbnb.lottie.LottieCompositionFactory.fromAssetSync(LottieCompositionFactory.java:114)
at at com.airbnb.lottie.LottieCompositionFactory$2.call(LottieCompositionFactory.java:95)
at at com.airbnb.lottie.LottieCompositionFactory$2.call(LottieCompositionFactory.java:93)
at at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at at java.lang.Thread.run(Thread.java:764)
I think you can open an issue at https://github.com/airbnb/lottie-android/issues
Share the link to the json and they may investigate the issue.
I could reproduce it here. It is happening on Android only because the Exception is happening in a Android class:
// Note the class path: android.view.animation.PathInterpolator
at at android.view.animation.PathInterpolator.initPath(PathInterpolator.java:185)
at at android.view.animation.PathInterpolator.initCubic(PathInterpolator.java:158)
at at android.view.animation.PathInterpolator.<init>(PathInterpolator.java:89)
at at android.support.v4.view.animation.PathInterpolatorCompat.create(PathInterpolatorCompat.java:82)
at at com.airbnb.lottie.parser.KeyframeParser.parseKeyframe(KeyframeParser.java:130)
Checking the source code of PathInterpolator:
float fraction = pointComponents[componentIndex++];
float x = pointComponents[componentIndex++];
float y = pointComponents[componentIndex++];
if (fraction == prevFraction && x != prevX) {
throw new IllegalArgumentException(
"The Path cannot have discontinuity in the X axis.");
}
if (x < prevX) {
// Exception is being triggered here due to x < prevX
throw new IllegalArgumentException("The Path cannot loop back on itself.");
}
PathInterpolator is being invoked by the Lottie library. So, they may provide a better feedback on this issue.
Try there: https://github.com/airbnb/lottie-android/issues
Note that they need the AEP file. So, talk to your friend in order to get that file:
Zip your After Effects AEP file and attach it. Your issue will be auto-closed if it doesn't have an AEP or no explicit reason otherwise is given.
After debugging i figured out the problem. There where two layers with the same name, they caused a conflict. Not sure if this is a bug in Lottie for Android, the initial version is working perfectly in iOS. So make sure every layer has a different name ;-)

Error in saving and using model of TensorForestEstimator for Android

I use the randomforest estimator, implemented in tensorflow, to predict if a text is english or not. I saved my model (A dataset with 2k samples and 2 class labels 0/1 (Not English/English)) using the following code (train_input_fn function return features and class labels):
model_path='test/'
TensorForestEstimator(params, model_dir='model/')
estimator.fit(input_fn=train_input_fn, max_steps=1)
After running the above code, the graph.pbtxt and checkpoints are saved in the model folder. Now I want to use it on Android. I have 2 problems:
As the first step, I need to freeze the graph and checkpoints to a .pb file to use it on Android. I tried freeze_graph (I used the code here: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py). When I call the freeze_graph in my mode, I get the following error and the code cannot create the final .pb graph:
File "/Users/XXXXXXX/freeze_graph.py", line 105, in freeze_graph
_ = tf.import_graph_def(input_graph_def, name="")
File "/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/importer.py", line 258, in import_graph_def
op_def = op_dict[node.op]
KeyError: u'CountExtremelyRandomStats'
this is how I call freeze_graph:
def save_model_android():
checkpoint_state_name = "model.ckpt-1"
input_graph_name = "graph.pbtxt"
output_graph_name = "output_graph.pb"
checkpoint_path = os.path.join(model_path, checkpoint_state_name)
input_graph_path = os.path.join(model_path, input_graph_name)
input_saver_def_path = None
input_binary = False
output_node_names = "output"
restore_op_name = "save/restore_all"
filename_tensor_name = "save/Const:0"
output_graph_path = os.path.join(model_path, output_graph_name)
clear_devices = True
freeze_graph.freeze_graph(input_graph_path, input_saver_def_path,
input_binary, checkpoint_path,
output_node_names, restore_op_name,
filename_tensor_name, output_graph_path,
clear_devices, "")
I also tried the freezing on the iris dataset in "tf.contrib.learn.datasets.load_iris". I get the same error. So I believe it is not related to the dataset.
As a second step, I need to use the .pb file on the phone to predict a text. I found the camera demo example by google and it contains a lot of code. I wonder if there is a step by step tutorial how to use a Tensorflow model on Android by passing a feature vector and get the class label.
Thanks, in advance!
UPDATE
By using the recent version of tensorflow (0.12), the problem is solved. However, now, the problem is that what I should pass to output_node_names ??? How can I get what are the output nodes in the graph ?
Re (1) it looks like you are running freeze_graph on a build of tensorflow which does not have access to contrib ops. Maybe try explicitly importing tensorforest before calling freeze_graph?
Re (2) I don't know of a simpler example.
CountExtremelyRandomStats is one of TensorForest's custom ops, and exists in tensorflow/contrib. As was pointed out, TF switched to including contrib ops by default at some point. I don't think there's an easy way to include the contrib custom ops in the global registry in the previous releases, because TensorForest uses the method of building a .so file that is included as a data file which is loaded at runtime (a method that was the standard when TensorForest was created, but may not be any longer). So there are no easily-included python build rules that will properly link in the C++ custom ops. You can try including tensorflow/contrib/tensor_forest:ops_lib as a dep in your build rule, but I don't think it will work.
In any case, you can try installing the nightly build of tensorflow. The alternative includes modifying how tensorforest custom ops are built, which is pretty nasty.

Android - Libgdx - Couldnt Load File

I have used google, read all Questions here on StackExchange but still couldnt solve my Problem.
So Im following a tutorial from kilobolt(Zombie Bird).
The desktop-version of the game is running without problems, but if I want to run it on an android emulator I get this error message:
"Couldn't load file: data/logo.png"
The line where I get the error looks like this:
logoTexture = new Texture(Gdx.files.internal("data/logo.png"));
My Android Path looks like this:
-Android
-Assets
-Data
-logo.png
I assume this is the correct path.
I have tried cleaning the project, I used Gradle > Refresh All, I restarted Eclipse.
Nothing worked.
Im a little bit confused cause if I move the file outside of Data but in the Assets Folder and change the path to this:
logoTexture = new Texture(Gdx.files.internal("logo.png"));
It works.
Can someone explain me why I cant use the Data Folder inside of Assets?
What emulator are you using to run it? For me, the same code works properly on an actual Android device, so I'd assume it is an Emulator error. Possibly has to do with the / as the seperator character. This is just a wild guess, but does
logoTexture = new Texture(Gdx.files.internal("data" + File.separator + "logo.png"));
fix it, or break it?
maybe it's caused by the difference of OpenGl ES 1 and OpenGl ES 2...
Using OpenGl ES 1 the picture size has the power of two. Bear with me - I'm new to libgdx.. :)

How to find a WebView element in Android using Calabash using TextContent

I have a webview in an ios app that basically has no id or class. (I know, right?)
But it does have a textContent field that I would like to use to select elements.
This is the element I want to find:
{"rect"=>
{"center_x"=>307.5,
"left"=>295,
"bottom"=>136,
"right"=>320,
"top"=>93,
"width"=>25,
"height"=>43,
"center_y"=>178.5},
"nodeName"=>"LI",
"id"=>"",
"textContent"=>"!!! I WANT TO FIND IT BY THIS !!!",
"center"=>{"X"=>307.5, "Y"=>178.5},
"nodeType"=>"ELEMENT_NODE",
"webView"=>
"<UIWebView: 0xe2e1400; frame = (0 0; 320 504); clipsToBounds = YES; autoresize = W+H
"class"=>"arrow",
"html"=>"<div class=\"arrow\"></div>"}
So I was able to find this using css pseudo-selectors alá
query("webView css:'el:first-child'")
I can find it by using the hashes in the results array alá
query("webView css:'li'").select {|element| element["textContent"] == "!!! I WANT TO FIND IT BY THIS !!!}
And I can refactor it a bit to use a regex alá
query("webView css:'li'").select {|element| element["textContent"] =~ /I WANT/}
But all this feels really dirty. Very un-Calabashy. Is there a better way to write this?
I have not tried your exact setup. But I do often use queries with the LIKE comparison on label.
Would that solve your problem?
ex.
element_exists("label {text LIKE 'I WANT TO FIND'}")
I wound up going with this:
query("webView css:'TITLE'{textContent CONTAINS ’I WANT’}")
It tends to work more consistently with these particular webviews (given a lack of accessibility labels in the code).

Fixed typo in C code, still won't build

I am converting someones Palm Pilot code into an Android application for them. This involves me using the NDK to read from one of their already built libraries. For this, I need to create several new functions.
void __stdcall FreeRelay(void){
RelayAPI_DataValid=0;
RelayAPI_SetBaud=0;
RelayAPI_get=0;
RelayAPI_put=0;
RelayAPI_flush=0;
RelayAPI_delay=0;
RelayAPI_initilized=0;
}
void Java_my_MainMenu_FreeRelayJava( JNIEnv * env, jobject this ) {
RelayAPI_DataValid = 0;
RelayAPI_SetBaud = 0;
RelayAPI_get = 0;
RelayAPI_put = 0;
RelayAPI_flush = 0;
RelayAPI_delay = 0;
RelayAPI_initilized = 0;
}
Now, my error is in the last line of the second method. I had originall had it spelled RelayAPI_initialized, I know that thats correct, but I'm not going through the trouble of changing all of this C code for the typo. I'll make my function fit with the old code. Anyway, I tried ndk-build and got this.
Now in between those separate ndk-build calls, I fixed the error. But it still is telling me in line 615 there is an error dealing with RelayAPI_initialized but its NOT THERE. I don't know whats going on, and I really know very little about C. I saved my files with the updated information then called ndk-build. WHAT AM I MISSING?
maybe you can grep to find if other var like RelayAPI_* are defined GLOBALLY in some c code or header file.
if not, define it, or don't set it.
it will resolve compilation error... but probably it wont work
do a clean of your build. so the party built stuff is deleted and you get a full rebuild.

Categories

Resources